Skip to content

Commit

Permalink
feat(action): added root strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Feb 17, 2022
1 parent cf49768 commit 407f2a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 9 additions & 1 deletion extensions/action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const ABORT_STRATEGY = {

export default function actionsExtension<TState extends BaseState>(options?: Partial<Options>) {
const {
strategies,
strategies: rootStrategies,
} = {
...options,
strategies: {
Expand Down Expand Up @@ -116,10 +116,17 @@ export default function actionsExtension<TState extends BaseState>(options?: Par
const {
parallel,
autoClearErrors,
strategies,
} = {
parallel: false,
autoClearErrors: true,

...options,

strategies: {
...rootStrategies,
...options?.strategies,
},
} as ActionOptions;

const mutate = (mutator: Mutator<TState, undefined, void>) => _store.write(name, SENDER, mutator);
Expand Down Expand Up @@ -158,6 +165,7 @@ export default function actionsExtension<TState extends BaseState>(options?: Par
result = await body(providedPayload, mutate, controller, onAbort);

emit(EVENTS.action.success);

incrementRunCount(name);
resolve(result);
} catch (error) {
Expand Down
9 changes: 6 additions & 3 deletions extensions/action/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export type ActionHookHandler<TPayload, TResult> = (data: ActionEventData<TPaylo
export type ActionAbortStrategy = (name: string, id: symbol, resolve: (value?: any) => void, reject: (reason: unknown) => void, reason?: unknown) => void;

export interface Options {
strategies: {
abort: ActionAbortStrategy
}
strategies: ActionStrategies;
}

export interface ActionStrategies {
abort: ActionAbortStrategy;
}

export interface ActionAbortStrategies {
Expand All @@ -38,6 +40,7 @@ export interface ActionOptions {
parallel: boolean;
autoClearErrors: boolean;
suppressAbortErrors: boolean;
strategies: ActionStrategies;
}

export interface ActionEventData<TPayload = any, TResult = any> {
Expand Down

0 comments on commit 407f2a0

Please sign in to comment.