@harlem/extension-action
Advanced tools
Comparing version 2.0.0-beta.5 to 2.0.0-beta.6
@@ -35,14 +35,12 @@ var __defProp = Object.defineProperty; | ||
_store.write("$action-init", SENDER, (state) => state.$actions = {}, true); | ||
function setActionState(state, name) { | ||
state.$actions[name] = { | ||
runCount: 0, | ||
instances: new Map() | ||
}; | ||
} | ||
function registerAction(name) { | ||
_store.register("actions", name, () => void 0); | ||
_store.write("$action-register", SENDER, (state) => { | ||
state.$actions[name] = { | ||
runCount: 0, | ||
instances: new Map() | ||
}; | ||
}, true); | ||
_store.register("actions", name, () => _store.state.$actions[name]); | ||
_store.write("$action-register", SENDER, (state) => setActionState(state, name), true); | ||
} | ||
function clearActionRunCount(name) { | ||
_store.write("$action-clear-run-count", SENDER, (state) => state.$actions[name].runCount = 0); | ||
} | ||
function incrementRunCount(name) { | ||
@@ -127,2 +125,10 @@ _store.write("$action-increment-run-count", SENDER, (state) => state.$actions[name].runCount += 1); | ||
} | ||
function resetActionState(name) { | ||
const names = [].concat(name || Object.keys(_store.state.$actions)); | ||
_store.write("$action-reset-state", SENDER, (state) => names.forEach((name2) => { | ||
if (name2 in state.$actions) { | ||
setActionState(state, name2); | ||
} | ||
})); | ||
} | ||
return { | ||
@@ -133,3 +139,3 @@ action, | ||
whenActionIdle, | ||
clearActionRunCount | ||
resetActionState | ||
}; | ||
@@ -136,0 +142,0 @@ }; |
@@ -66,14 +66,12 @@ var HarlemActionExtension = (() => { | ||
_store.write("$action-init", SENDER, (state) => state.$actions = {}, true); | ||
function setActionState(state, name) { | ||
state.$actions[name] = { | ||
runCount: 0, | ||
instances: new Map() | ||
}; | ||
} | ||
function registerAction(name) { | ||
_store.register("actions", name, () => void 0); | ||
_store.write("$action-register", SENDER, (state) => { | ||
state.$actions[name] = { | ||
runCount: 0, | ||
instances: new Map() | ||
}; | ||
}, true); | ||
_store.register("actions", name, () => _store.state.$actions[name]); | ||
_store.write("$action-register", SENDER, (state) => setActionState(state, name), true); | ||
} | ||
function clearActionRunCount(name) { | ||
_store.write("$action-clear-run-count", SENDER, (state) => state.$actions[name].runCount = 0); | ||
} | ||
function incrementRunCount(name) { | ||
@@ -158,2 +156,10 @@ _store.write("$action-increment-run-count", SENDER, (state) => state.$actions[name].runCount += 1); | ||
} | ||
function resetActionState(name) { | ||
const names = [].concat(name || Object.keys(_store.state.$actions)); | ||
_store.write("$action-reset-state", SENDER, (state) => names.forEach((name2) => { | ||
if (name2 in state.$actions) { | ||
setActionState(state, name2); | ||
} | ||
})); | ||
} | ||
return { | ||
@@ -164,3 +170,3 @@ action, | ||
whenActionIdle, | ||
clearActionRunCount | ||
resetActionState | ||
}; | ||
@@ -167,0 +173,0 @@ }; |
@@ -29,5 +29,5 @@ import Task, { TaskAbortCallback } from '@harlem/task'; | ||
whenActionIdle: <TPayload_2 = unknown>(name: string, predicate?: ActionPredicate<TPayload_2> | undefined, controller?: AbortController | undefined) => Task<void>; | ||
clearActionRunCount: (name: string) => void; | ||
resetActionState: (name?: string | string[] | undefined) => void; | ||
}; | ||
export { Action, ActionAbortError, ActionBody, ActionOptions, ActionPredicate, ActionStoreState, ActionTaskState, actionsExtension as default }; |
@@ -35,14 +35,12 @@ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty; | ||
_store.write("$action-init", SENDER, (state) => state.$actions = {}, true); | ||
function setActionState(state, name) { | ||
state.$actions[name] = { | ||
runCount: 0, | ||
instances: new Map() | ||
}; | ||
} | ||
function registerAction(name) { | ||
_store.register("actions", name, () => void 0); | ||
_store.write("$action-register", SENDER, (state) => { | ||
state.$actions[name] = { | ||
runCount: 0, | ||
instances: new Map() | ||
}; | ||
}, true); | ||
_store.register("actions", name, () => _store.state.$actions[name]); | ||
_store.write("$action-register", SENDER, (state) => setActionState(state, name), true); | ||
} | ||
function clearActionRunCount(name) { | ||
_store.write("$action-clear-run-count", SENDER, (state) => state.$actions[name].runCount = 0); | ||
} | ||
function incrementRunCount(name) { | ||
@@ -127,2 +125,10 @@ _store.write("$action-increment-run-count", SENDER, (state) => state.$actions[name].runCount += 1); | ||
} | ||
function resetActionState(name) { | ||
const names = [].concat(name || Object.keys(_store.state.$actions)); | ||
_store.write("$action-reset-state", SENDER, (state) => names.forEach((name2) => { | ||
if (name2 in state.$actions) { | ||
setActionState(state, name2); | ||
} | ||
})); | ||
} | ||
return { | ||
@@ -133,3 +139,3 @@ action, | ||
whenActionIdle, | ||
clearActionRunCount | ||
resetActionState | ||
}; | ||
@@ -136,0 +142,0 @@ }; |
{ | ||
"name": "@harlem/extension-action", | ||
"amdName": "harlemAction", | ||
"version": "2.0.0-beta.5", | ||
"version": "2.0.0-beta.6", | ||
"license": "MIT", | ||
@@ -42,3 +42,3 @@ "author": "Andrew Courtice <andrewcourtice@users.noreply.github.com>", | ||
"dependencies": { | ||
"@harlem/task": "^2.0.0-beta.5" | ||
"@harlem/task": "^2.0.0-beta.6" | ||
}, | ||
@@ -50,7 +50,7 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@harlem/core": "^2.0.0-beta.5", | ||
"@harlem/testing": "^2.0.0-beta.5", | ||
"@harlem/core": "^2.0.0-beta.6", | ||
"@harlem/testing": "^2.0.0-beta.6", | ||
"vue": "^3.2.0" | ||
}, | ||
"gitHead": "b86f63cea8304451a29c6acd7463b5172eae9488" | ||
"gitHead": "6cedfe63a2b2f9f95f27ac1b1a7129f8f494de62" | ||
} |
@@ -41,14 +41,12 @@ import Task from '@harlem/task'; | ||
function registerAction(name: string) { | ||
_store.register('actions', name, () => undefined); | ||
_store.write('$action-register', SENDER, state => { | ||
state.$actions[name] = { | ||
runCount: 0, | ||
instances: new Map<symbol, unknown>(), | ||
}; | ||
}, true); | ||
function setActionState(state: TState & ActionStoreState, name: string) { | ||
state.$actions[name] = { | ||
runCount: 0, | ||
instances: new Map<symbol, unknown>(), | ||
}; | ||
} | ||
function clearActionRunCount(name: string) { | ||
_store.write('$action-clear-run-count', SENDER, state => state.$actions[name].runCount = 0); | ||
function registerAction(name: string) { | ||
_store.register('actions', name, () => _store.state.$actions[name]); | ||
_store.write('$action-register', SENDER, state => setActionState(state, name), true); | ||
} | ||
@@ -159,2 +157,12 @@ | ||
function resetActionState(name?: string | string[]) { | ||
const names = ([] as string[]).concat(name || Object.keys(_store.state.$actions)); | ||
_store.write('$action-reset-state', SENDER, state => names.forEach(name => { | ||
if (name in state.$actions) { | ||
setActionState(state, name); | ||
} | ||
})); | ||
} | ||
return { | ||
@@ -165,5 +173,5 @@ action, | ||
whenActionIdle, | ||
clearActionRunCount, | ||
resetActionState, | ||
}; | ||
}; | ||
} |
@@ -165,2 +165,22 @@ import Task from '@harlem/task'; | ||
test('Handles action resetting', async () => { | ||
const { | ||
loadUserInfo, | ||
loadUserInfoName, | ||
} = instance; | ||
const { | ||
hasActionRun, | ||
resetActionState, | ||
} = instance.store; | ||
expect(hasActionRun(loadUserInfoName)).toBe(false); | ||
await loadUserInfo(); | ||
expect(hasActionRun(loadUserInfoName)).toBe(true); | ||
resetActionState(); | ||
expect(hasActionRun(loadUserInfoName)).toBe(false); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64898
792
Updated@harlem/task@^2.0.0-beta.6