Skip to content

Commit

Permalink
fix(action): suppress initial write ops to prevent thrashing triggers
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewcourtice committed Aug 19, 2021
1 parent 7dd5622 commit 268dd93
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions extensions/action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ export default function actionsExtension<TState extends BaseState>() {
return (store: InternalStore<TState>) => {
const _store = store as unknown as InternalStore<TState & ActionStoreState>;

_store.write('$action-init', SENDER, state => {
state.$actions = {};
});
_store.write('$action-init', SENDER, state => state.$actions = {}, true);

function registerAction(name: string) {
_store.register('actions', name, () => undefined);
Expand All @@ -47,7 +45,7 @@ export default function actionsExtension<TState extends BaseState>() {
runCount: 0,
instances: new Map<symbol, unknown>(),
};
});
}, true);
}

function clearActionRunCount(name: string) {
Expand Down Expand Up @@ -78,7 +76,7 @@ export default function actionsExtension<TState extends BaseState>() {
...options,
};

const mutate = (mutator: Mutator<TState, undefined, void>) => _store.write(name, '$actions-extension', mutator);
const mutate = (mutator: Mutator<TState, undefined, void>) => _store.write(name, SENDER, mutator);

return ((payload: TPayload, controller?: AbortController) => {
if (!parallel && tasks.size > 0) {
Expand All @@ -105,9 +103,10 @@ export default function actionsExtension<TState extends BaseState>() {
incrementRunCount(name);
} catch (error) {
if (error instanceof DOMException) {
fail(); // Fetch has been cancelled
return fail(); // Fetch has been cancelled
}

incrementRunCount(name);
reject(error);
} finally {
complete();
Expand Down

0 comments on commit 268dd93

Please sign in to comment.