-
Notifications
You must be signed in to change notification settings - Fork 403
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
fix(store): prevent writing to state once action handler is unsubscribed #2231
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit b2b3a97. 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 +1.56KB +1.21% Groups updated (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)Files updated (3)
Total files change +135B +0.06% Final result: ✅ View report in BundleMon website ➡️ |
9cf8695
to
5999dc0
Compare
@Action(MyActionAwait, { cancelUncompleted: true }) | ||
async handleActionAwait() { | ||
recorder.push('before promise await ready'); | ||
await promiseAwaitReady; | ||
recorder.push('after promise await ready'); | ||
} | ||
|
||
@Action(MyActionThen, { cancelUncompleted: true }) | ||
handleActionThen() { | ||
recorder.push('before promise then ready'); | ||
return promiseThenReady.then(() => { | ||
recorder.push('after promise then ready'); | ||
}); |
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.
What are we testing here?
There isn't anything that checks that operations on the state are nooped after cancellation.
@arturovt I wasn't meaning to remove that test file, but rather to add tests that showcase the cancellation behavior by writing to the state. Potentially the action could write the log entries to the state as well as the recorder. PS. I view the "don't write to state after unsubscribe" as a different set of tests to the cancellation tests (even though they use the same mechanism). |
c14cad5
to
f4de279
Compare
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.
Looking good.
Please add a description to the PR, and a line to the changelog 🙏
In this commit, we update the implementation of action invocation. The key addition is that we now prevent writing to the state whenever an action handler is unsubscribed (completed or cancelled). Since we have a "unique" state context object for each action being invoked, we can set its `setState` and `patchState` functions to no-ops, essentially making them do nothing when invoked.
f4de279
to
b2b3a97
Compare
Code Climate has analyzed commit b2b3a97 and detected 0 issues on this pull request. The test coverage on the diff in this pull request is 91.6% (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. |
In this commit, we update the implementation of action invocation. The key addition is that
we now prevent writing to the state whenever an action handler is unsubscribed (completed or
cancelled). Since we have a "unique" state context object for each action being invoked, we
can set its
setState
andpatchState
functions to no-ops, essentially making them donothing when invoked.