Skip to content

Commit

Permalink
chore: change to abort signal
Browse files Browse the repository at this point in the history
  • Loading branch information
arturovt committed Nov 8, 2024
1 parent 835ff0c commit 8ae35ba
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class HmrStateContextFactory<T, S> {
*/
public createStateContext(): StateContext<S> {
return {
abortController: new AbortController(),
abortSignal: new AbortController().signal,
dispatch: actions => this.store!.dispatch(actions),
getState: () => <S>this.store!.snapshot(),
setState: val => {
Expand Down
4 changes: 2 additions & 2 deletions packages/store/src/internal/state-context-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export class StateContextFactory {
/**
* Create the state context
*/
createStateContext<T>(path: string, abortController?: AbortController): StateContext<T> {
createStateContext<T>(path: string, abortSignal?: AbortSignal): StateContext<T> {
const root = this._internalStateOperations.getRootStateOperations();

return {
abortController: abortController!,
abortSignal: abortSignal!,
getState(): T {
const currentAppState = root.getState();
return getState(currentAppState, path);
Expand Down
8 changes: 3 additions & 5 deletions packages/store/src/internal/state-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,11 @@ export class StateFactory implements OnDestroy {
for (const actionType of Object.keys(actions)) {
const actionHandlers = actions[actionType].map(actionMeta => {
const abortController = new AbortController();
const abortSignal = abortController.signal;
const cancellable = !!actionMeta.options.cancelUncompleted;

return (action: any) => {
const stateContext = this._stateContextFactory.createStateContext(
path,
abortController
);
const stateContext = this._stateContextFactory.createStateContext(path, abortSignal);

let result = instance[actionMeta.fn](stateContext, action);

Expand Down Expand Up @@ -394,7 +392,7 @@ export class StateFactory implements OnDestroy {
result = result.pipe(takeUntil(cancelled));
}

const aborted = fromEvent(abortController.signal, 'abort');
const aborted = fromEvent(abortSignal, 'abort');

result = result.pipe(
takeUntil(aborted),
Expand Down
2 changes: 1 addition & 1 deletion packages/store/src/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export { StateOperator };
* State context provided to the actions in the state.
*/
export interface StateContext<T> {
abortController: AbortController;
abortSignal: AbortSignal;

/**
* Get the current state.
Expand Down

0 comments on commit 8ae35ba

Please sign in to comment.