-
Notifications
You must be signed in to change notification settings - Fork 405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(store): ensure state writes are allowed with fire & forget #2241
base: master
Are you sure you want to change the base?
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit b256490. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 4 targetsSent with 💌 from NxCloud. |
commit: |
BundleMonFiles updated (1)
Unchanged files (5)
Total files change -95B -0.07% Unchanged groups (2)
Final result: ✅ View report in BundleMon website ➡️ |
BundleMon (NGXS Plugins)Unchanged files (9)
No change in files bundle size Unchanged groups (1)
Final result: ✅ View report in BundleMon website ➡️ |
BundleMon (Integration Projects)Unchanged files (3)
No change in files bundle size Final result: ✅ View report in BundleMon website ➡️ |
Code Climate has analyzed commit b256490 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 100.0% (50% is the threshold). This pull request will bring the total coverage in the repository to 95.4% (0.0% change). View more on Code Climate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the expected behaviour should be as follows...
(this is assuming that cancelUncompleted: true
is present)
- If the fire and forget action is left to run without a new action coming in, then it should be allowed to do as many writes to the context that it needs to (ie. the StateContext remains writeable)
- but as soon as a second action comes in then the previous StateContext should become noop'ed so that it is no longer writeable.
Please add test cases to demonstrate both of these expected behaviours.
I'm afraid that might be difficult to implement. With your second approach, we would need to manually subscribe to the canceled observable: const canceled = dispatched$.pipe(ofActionDispatched(action));
canceled.subscribe(() => {
stateContext.setState = noop;
stateContext.patchState = noop;
}); That is actually possible, but we need to unsubscribe from the canceled observable. However, the exact point at which we need to unsubscribe is unknown - perhaps when the action handler completes? With the fire-and-forget approach, we never know if the action is still executing any functionality or when that functionality completes. |
The alternative here is that we could keep a reference to the previous
state context and do the noop when the next one comes though. Or, we could
have an abortController linked up to do the noop'ing and then keep a
reference to the last abort controller and call it when the new event comes
through.
(abort controller doesn't necessarily need to be exposed yet, but can be
used).
…On Tue, 29 Oct 2024 at 03:21, Artur ***@***.***> wrote:
I'm afraid that might be difficult to implement. With your second
approach, we would need to manually subscribe to the canceled observable:
const canceled = dispatched$.pipe(ofActionDispatched(action));
canceled.subscribe(() => {
stateContext.setState = noop;
stateContext.patchState = noop;});
That is actually possible, but we need to unsubscribe from the canceled
observable. However, the exact point at which we need to unsubscribe is
unknown - perhaps when the action handler completes?
With the fire-and-forget approach, we never know if the action is still
executing any functionality or when that functionality completes.
—
Reply to this email directly, view it on GitHub
<#2241 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAO3U2KSQTW52GG6IPFBJXDZ53IINAVCNFSM6AAAAABQTV3YPKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBSHE3TEOBUHA>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
My thoughts that fire-and-forget actions should not be cancellable. Instead, it should be the user’s responsibility to manage their cancellation by returning an observable, rather than subscribing to an observable and 'forgetting' it. I’d prefer not to capture previous state contexts because, if the fire-and-forget action never resolves, we wouldn't know when to release a reference to the previous state context. |
No description provided.