-
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
feat(store): expose abort controller on state context #2244
base: master
Are you sure you want to change the base?
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 8ae35ba. 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 (2)
Unchanged files (4)
Total files change +616B +0.46% Groups updated (2)
Final result: ❌ View report in BundleMon website ➡️ |
BundleMon (NGXS Plugins)Files updated (1)
Unchanged files (8)
Total files change +25B +0.12% Groups updated (1)
Final result: ❌ View report in BundleMon website ➡️ |
BundleMon (Integration Projects)Files updated (3)
Total files change +231B +0.11% Final result: ✅ View report in BundleMon website ➡️ |
packages/store/src/symbols.ts
Outdated
@@ -99,6 +99,8 @@ export { StateOperator }; | |||
* State context provided to the actions in the state. | |||
*/ | |||
export interface StateContext<T> { | |||
abortController: AbortController; |
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.
abortController: AbortController; | |
abortSignal: AbortSignal; |
const stateContext = this._stateContextFactory.createStateContext( | ||
path, | ||
abortController | ||
); |
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.
const stateContext = this._stateContextFactory.createStateContext( | |
path, | |
abortController | |
); | |
const stateContext = this._stateContextFactory.createStateContext( | |
path, | |
abortSignal | |
); |
const abortController = new AbortController(); | ||
const cancellable = !!actionMeta.options.cancelUncompleted; |
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.
const abortController = new AbortController(); | |
const cancellable = !!actionMeta.options.cancelUncompleted; | |
const abortController = new AbortController(); | |
const abortSignal = abortController.signal; | |
const cancellable = !!actionMeta.options.cancelUncompleted; |
} | ||
|
||
const aborted = fromEvent(abortController.signal, 'abort'); |
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.
const aborted = fromEvent(abortController.signal, 'abort'); | |
const aborted = fromEvent(abortSignal, 'abort'); |
const root = this._internalStateOperations.getRootStateOperations(); | ||
|
||
return { | ||
abortController: abortController!, |
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.
abortController: abortController!, | |
abortSignal: abortSignal!, |
|
||
/** | ||
* Create the state context | ||
*/ | ||
createStateContext<T>(path: string): StateContext<T> { | ||
createStateContext<T>(path: string, abortController?: AbortController): StateContext<T> { |
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.
createStateContext<T>(path: string, abortController?: AbortController): StateContext<T> { | |
createStateContext<T>(path: string, abortSignal?: AbortSignal): StateContext<T> { |
@@ -99,6 +99,7 @@ export class LifecycleStateManager implements OnDestroy { | |||
} | |||
|
|||
private _getStateContext(mappedStore: MappedStore): StateContext<any> { | |||
// Question: abort controller is not gonna be available for lifecycle hooks. |
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 think that the abortSignal
could be available for lifecycle hooks.
For example, when we have a local state, the abort signal for the lifecycle hooks would be triggered when the state should be unloaded.
@@ -345,10 +346,14 @@ export class StateFactory implements OnDestroy { | |||
const { dispatched$ } = this._actions; | |||
for (const actionType of Object.keys(actions)) { | |||
const actionHandlers = actions[actionType].map(actionMeta => { | |||
const cancelable = !!actionMeta.options.cancelUncompleted; | |||
const abortController = new AbortController(); |
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.
If cancellation is enabled we would retain a reference to the previous abortController
for the handler and when the next action hits this handler we would call abortController.abort()
on the previous abortController
to trigger the cancellation of the previous handler and of any related work that has used the abort signal from the context.
When the abortSignal fires for some work in progress in the handler (like fetch
), the handler would throw an error, we should catch this error and not let it propagate to the action error handlers.
Code Climate has analyzed commit 8ae35ba 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. |
No description provided.