From 268dd9342992b376362fa752f8413db6e2bf435f Mon Sep 17 00:00:00 2001 From: Andrew Courtice Date: Fri, 20 Aug 2021 09:31:02 +1000 Subject: [PATCH] fix(action): suppress initial write ops to prevent thrashing triggers --- extensions/action/src/index.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/extensions/action/src/index.ts b/extensions/action/src/index.ts index 95424b9c..1c0020c9 100644 --- a/extensions/action/src/index.ts +++ b/extensions/action/src/index.ts @@ -36,9 +36,7 @@ export default function actionsExtension() { return (store: InternalStore) => { const _store = store as unknown as InternalStore; - _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); @@ -47,7 +45,7 @@ export default function actionsExtension() { runCount: 0, instances: new Map(), }; - }); + }, true); } function clearActionRunCount(name: string) { @@ -78,7 +76,7 @@ export default function actionsExtension() { ...options, }; - const mutate = (mutator: Mutator) => _store.write(name, '$actions-extension', mutator); + const mutate = (mutator: Mutator) => _store.write(name, SENDER, mutator); return ((payload: TPayload, controller?: AbortController) => { if (!parallel && tasks.size > 0) { @@ -105,9 +103,10 @@ export default function actionsExtension() { 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();