@alwatr/fsm
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -6,6 +6,53 @@ # Change Log | ||
## [1.0.1](https://github.com/AliMD/alwatr/compare/v1.0.0...v1.0.1) (2023-06-21) | ||
# 1.1.0 (2023-09-12) | ||
**Note:** Version bump only for package @alwatr/fsm | ||
# 1.0.0 (2023-06-14) | ||
# 0.32.0 (2023-05-27) | ||
# 0.31.0 (2023-05-08) | ||
### Bug Fixes | ||
* **fms:** import path ([f6770a0](https://github.com/AliMD/alwatr/commit/f6770a07fdf6855ccd63a85822d44d5ef9c72dee)) | ||
* **fsm:** action maybe async ([50efffa](https://github.com/AliMD/alwatr/commit/50efffa34a2ea5a3515561d7425da0c109631f36)) | ||
* **fsm:** autoSignalUnsubscribe type ([f7db30b](https://github.com/AliMD/alwatr/commit/f7db30bf5a90ff3d163f036b313a412a5149ff2b)) | ||
* **fsm:** call render states function in there own this ([a950478](https://github.com/AliMD/alwatr/commit/a95047811366e375785b2cd8fb176b1176638cab)) | ||
* **fsm:** fix order of `initFsmInstance` args ([3b60138](https://github.com/AliMD/alwatr/commit/3b60138ecebcbcb4d732e4d1a3e79f5b8661ae47)) | ||
* **fsm:** initial exec actions ([e7dd5c8](https://github.com/AliMD/alwatr/commit/e7dd5c8aaf9760c9856e4392cc899020f7e796d9)) | ||
* **fsm:** last reported bugs in set state ([e7435c8](https://github.com/AliMD/alwatr/commit/e7435c870a054b0ec3e4004f13c6db7610610be0)) | ||
* **fsm:** review reset process ([af6e81c](https://github.com/AliMD/alwatr/commit/af6e81c068b467d8b3aa96f2431e13ac479f018c)) | ||
* **fsm:** run init entry actions ([777ae45](https://github.com/AliMD/alwatr/commit/777ae459f2b77f79696daf3a0ca355d6d78e57d3)) | ||
* new logger api ([9d83a7d](https://github.com/AliMD/alwatr/commit/9d83a7dc5c103bc3bb4282dacfd85fa998915300)) | ||
### Features | ||
* **fsm:** add `signalRecord` to config ([1a35291](https://github.com/AliMD/alwatr/commit/1a352915fba978da141513517655d1e07350c3ec)) | ||
* **fsm:** add unsubscribe ([85ed3c3](https://github.com/AliMD/alwatr/commit/85ed3c3439e1f40c2760f6011df112242f10be06)) | ||
* **fsm:** callback in provider signals ([772818b](https://github.com/AliMD/alwatr/commit/772818baa7953b6fbb4d4128fcee76733f42cc2d)) | ||
* **fsm:** custom signal callback ([47c22e9](https://github.com/AliMD/alwatr/commit/47c22e92a8a8085148b44b316d649b695ff8071a)) | ||
* **fsm:** destroy and expire api ([e1a1c15](https://github.com/AliMD/alwatr/commit/e1a1c150d81f4428718bd18f039235c7fce9caf2)) | ||
* **fsm:** new types ([2866e3b](https://github.com/AliMD/alwatr/commit/2866e3bd5ff56fd2b5bddcaed3673a5868bae4bb)) | ||
* **fsm:** rewrite state machine ([7f24695](https://github.com/AliMD/alwatr/commit/7f246959e5a80b21c1c4b21e895e75f8fbe56798)) | ||
* **fsm:** subscribe ([2af4f44](https://github.com/AliMD/alwatr/commit/2af4f44f0e8a2dee39cde10dcaa3281075632e6a)) | ||
# 0.30.0 (2023-03-06) | ||
### Bug Fixes | ||
* **fsm:** every signal mather ([0dc504d](https://github.com/AliMD/alwatr/commit/0dc504dacbb1ec68f154244619d644ff8e43cc04)) | ||
* **fsm:** remove additional import ([231337b](https://github.com/AliMD/alwatr/commit/231337b95ee7b046fe35429f50931ddf85be291f)) | ||
* **fsm:** update context in transition bug ([28a21d0](https://github.com/AliMD/alwatr/commit/28a21d00d903b6189d814303c72ba6e784852f33)) | ||
### Features | ||
* Alwatr Finite State Machines ([d5900b4](https://github.com/AliMD/alwatr/commit/d5900b4ee8685b120188888871405853f5a69417)) | ||
* **fsm:** $all and $self state ([69adf41](https://github.com/AliMD/alwatr/commit/69adf41064ca0f55497484c50e298ebc26c42dcc)) | ||
* **fsm:** enhance types ([3b13046](https://github.com/AliMD/alwatr/commit/3b130463a102f59c38603b0de470be5c87ee88c9)) | ||
* **fsm:** make simple state machine ([ff9ae1c](https://github.com/AliMD/alwatr/commit/ff9ae1ca04156e8b811899ff0f62480e1c37af72)) | ||
* **fsm:** new state context type with {to, from, by} ([11423e6](https://github.com/AliMD/alwatr/commit/11423e6a89159b92e82cfd1e774ad37983581090)) | ||
* **fsm:** rewrite with signal power ([01a1651](https://github.com/AliMD/alwatr/commit/01a1651e231a817d5eebb54cf84d51d620bfd6e8)) | ||
* **fsm:** share state events ([de42522](https://github.com/AliMD/alwatr/commit/de42522a97fdf6be8bee73d91a35820e2a5e6efb)) | ||
* **fsm:** transition with partial context set ([823377e](https://github.com/AliMD/alwatr/commit/823377e65028ea3e713f060ae678776c609c1661)) | ||
# [1.0.0](https://github.com/AliMD/alwatr/compare/v0.32.0...v1.0.0) (2023-06-14) | ||
@@ -12,0 +59,0 @@ |
@@ -54,3 +54,3 @@ import { ListenerSpec } from '@alwatr/signal'; | ||
*/ | ||
export declare const subscribeSignals: (instanceId: string, signalList: Array<SignalConfig>, subscribeConstructorSignals?: boolean) => Array<ListenerSpec>; | ||
export declare const subscribeSignals: (instanceId: string, signalList: SignalConfig[], subscribeConstructorSignals?: boolean) => ListenerSpec[]; | ||
/** | ||
@@ -73,3 +73,3 @@ * Define signals for finite state machine constructor. | ||
TContext: StringifyableRecord; | ||
}>>(instanceId: string, signalList: SignalConfig<T>[], subscribeConstructorSignals?: boolean) => Array<ListenerSpec>; | ||
}>>(instanceId: string, signalList: SignalConfig<T>[], subscribeConstructorSignals?: boolean) => ListenerSpec[]; | ||
/** | ||
@@ -76,0 +76,0 @@ * Render helper for use finite state machine instance in UI. |
88
core.js
@@ -14,4 +14,3 @@ import { createLogger, globalAlwatr } from '@alwatr/logger'; | ||
export const defineConstructor = (id, config) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'defineConstructor', { id, config }); | ||
logger.logMethodArgs?.('defineConstructor', { id, config }); | ||
if (fsmConstructorStorage[id] != null) | ||
@@ -31,4 +30,3 @@ throw new Error('fsm_exist', { cause: { id } }); | ||
export const getFsmInstance = (instanceId) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, '_getFsmInstance', instanceId); | ||
logger.logMethodArgs?.('_getFsmInstance', instanceId); | ||
const fsmInstance = contextConsumer.getValue(instanceId); | ||
@@ -43,4 +41,3 @@ if (fsmInstance == null) | ||
export const getFsmConstructor = (constructorId) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, '_getFsmConstructor', constructorId); | ||
logger.logMethodArgs?.('_getFsmConstructor', constructorId); | ||
const fsmConstructor = fsmConstructorStorage[constructorId]; | ||
@@ -55,4 +52,3 @@ if (fsmConstructor == null) | ||
export const getState = (instanceId) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'getState', instanceId); | ||
logger.logMethodArgs?.('getState', instanceId); | ||
return getFsmInstance(instanceId).state; | ||
@@ -64,4 +60,3 @@ }; | ||
export const getContext = (instanceId) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'getContext', instanceId); | ||
logger.logMethodArgs?.('getContext', instanceId); | ||
return getFsmInstance(instanceId).context; | ||
@@ -73,4 +68,3 @@ }; | ||
export const setContext = (instanceId, context, notify) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'setContext', { instanceId, context }); | ||
logger.logMethodArgs?.('setContext', { instanceId, context }); | ||
const fsmInstance = getFsmInstance(instanceId); | ||
@@ -89,3 +83,2 @@ fsmInstance.context = { | ||
export const transition = (instanceId, event, context) => { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
const fsmInstance = getFsmInstance(instanceId); | ||
@@ -95,4 +88,4 @@ const fsmConstructor = getFsmConstructor(fsmInstance.constructorId); | ||
const stateRecord = fsmConstructor.config.stateRecord; | ||
const transitionConfig = (_b = (_a = stateRecord[fromState]) === null || _a === void 0 ? void 0 : _a.on[event]) !== null && _b !== void 0 ? _b : stateRecord.$all.on[event]; | ||
(_c = logger.logMethodArgs) === null || _c === void 0 ? void 0 : _c.call(logger, 'transition', { instanceId, fromState, event, context, target: transitionConfig === null || transitionConfig === void 0 ? void 0 : transitionConfig.target }); | ||
const transitionConfig = stateRecord[fromState]?.on[event] ?? stateRecord.$all.on[event]; | ||
logger.logMethodArgs?.('transition', { instanceId, fromState, event, context, target: transitionConfig?.target }); | ||
if (context !== undefined) { | ||
@@ -105,8 +98,8 @@ fsmInstance.context = { | ||
if (transitionConfig == null) { | ||
(_d = logger.incident) === null || _d === void 0 ? void 0 : _d.call(logger, 'transition', 'invalid_target_state', 'Defined target state for this event not found in state config', { | ||
logger.incident?.('transition', 'invalid_target_state', 'Defined target state for this event not found in state config', { | ||
fromState, | ||
event, | ||
events: { | ||
...(_e = stateRecord.$all) === null || _e === void 0 ? void 0 : _e.on, | ||
...(_f = stateRecord[fromState]) === null || _f === void 0 ? void 0 : _f.on, | ||
...stateRecord.$all?.on, | ||
...stateRecord[fromState]?.on, | ||
}, | ||
@@ -122,3 +115,3 @@ }); | ||
fsmInstance.state = { | ||
target: (_g = transitionConfig.target) !== null && _g !== void 0 ? _g : fromState, | ||
target: transitionConfig.target ?? fromState, | ||
from: fromState, | ||
@@ -134,4 +127,3 @@ by: event, | ||
export const defineActions = (constructorId, actionRecord) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'defineActions', { constructorId, actionRecord }); | ||
logger.logMethodArgs?.('defineActions', { constructorId, actionRecord }); | ||
const fmsConstructor = getFsmConstructor(constructorId); | ||
@@ -147,8 +139,7 @@ fmsConstructor.actionRecord = { | ||
export const _execAllActions = (constructor, state, consumerInterface) => { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, '_execAllActions', consumerInterface.id); | ||
logger.logMethodArgs?.('_execAllActions', consumerInterface.id); | ||
const stateRecord = constructor.config.stateRecord; | ||
if (state.by === 'INIT') { | ||
_execAction(constructor, stateRecord.$all.entry, consumerInterface); | ||
_execAction(constructor, (_b = stateRecord[state.target]) === null || _b === void 0 ? void 0 : _b.entry, consumerInterface); | ||
_execAction(constructor, stateRecord[state.target]?.entry, consumerInterface); | ||
return; | ||
@@ -159,9 +150,9 @@ } | ||
_execAction(constructor, stateRecord.$all.exit, consumerInterface); | ||
_execAction(constructor, (_c = stateRecord[state.from]) === null || _c === void 0 ? void 0 : _c.exit, consumerInterface); | ||
_execAction(constructor, stateRecord[state.from]?.exit, consumerInterface); | ||
_execAction(constructor, stateRecord.$all.entry, consumerInterface); | ||
_execAction(constructor, (_d = stateRecord[state.target]) === null || _d === void 0 ? void 0 : _d.entry, consumerInterface); | ||
_execAction(constructor, stateRecord[state.target]?.entry, consumerInterface); | ||
} | ||
_execAction(constructor, ((_e = stateRecord[state.from]) === null || _e === void 0 ? void 0 : _e.on[state.by]) != null | ||
? (_f = stateRecord[state.from].on[state.by]) === null || _f === void 0 ? void 0 : _f.actions | ||
: (_g = stateRecord.$all.on[state.by]) === null || _g === void 0 ? void 0 : _g.actions, consumerInterface); | ||
_execAction(constructor, stateRecord[state.from]?.on[state.by] != null | ||
? stateRecord[state.from].on[state.by]?.actions | ||
: stateRecord.$all.on[state.by]?.actions, consumerInterface); | ||
}; | ||
@@ -172,6 +163,5 @@ /** | ||
export const _execAction = (constructor, actionNames, finiteStateMachine) => { | ||
var _a; | ||
if (actionNames == null) | ||
return; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'execAction', { constructorId: constructor.id, actionNames }); | ||
logger.logMethodArgs?.('execAction', { constructorId: constructor.id, actionNames }); | ||
if (Array.isArray(actionNames)) { | ||
@@ -205,4 +195,3 @@ return actionNames | ||
export const initFsmInstance = (instanceId, constructorId) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'initializeMachine', { constructorId, instanceId }); | ||
logger.logMethodArgs?.('initializeMachine', { constructorId, instanceId }); | ||
const constructor = getFsmConstructor(constructorId); | ||
@@ -226,4 +215,3 @@ const { initial, context } = constructor.config; | ||
export const subscribeSignals = (instanceId, signalList, subscribeConstructorSignals = true) => { | ||
var _a, _b, _c; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'subscribeSignals', { instanceId, signalList }); | ||
logger.logMethodArgs?.('subscribeSignals', { instanceId, signalList }); | ||
const listenerList = []; | ||
@@ -234,6 +222,5 @@ if (subscribeConstructorSignals) { | ||
for (const signalConfig of signalList) { | ||
(_b = signalConfig.signalId) !== null && _b !== void 0 ? _b : (signalConfig.signalId = instanceId); | ||
signalConfig.signalId ?? (signalConfig.signalId = instanceId); | ||
listenerList.push(contextConsumer.subscribe(signalConfig.signalId, (signalDetail) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'execSignalCallback', { instanceId, signalId: signalConfig.signalId, signalDetail }); | ||
logger.logMethodArgs?.('execSignalCallback', { instanceId, signalId: signalConfig.signalId, signalDetail }); | ||
if (signalConfig.callback) { | ||
@@ -248,3 +235,3 @@ signalConfig.callback(signalDetail, finiteStateMachineConsumer(instanceId)); | ||
} | ||
}, { receivePrevious: (_c = signalConfig.receivePrevious) !== null && _c !== void 0 ? _c : 'No' })); | ||
}, { receivePrevious: signalConfig.receivePrevious ?? 'No' })); | ||
} | ||
@@ -257,4 +244,3 @@ return listenerList; | ||
export const defineConstructorSignals = (constructorId, signalList) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'defineSignals', { constructorId, signalList: signalList }); | ||
logger.logMethodArgs?.('defineSignals', { constructorId, signalList: signalList }); | ||
const fsmConstructor = getFsmConstructor(constructorId); | ||
@@ -267,4 +253,3 @@ fsmConstructor.signalList = fsmConstructor.signalList.concat(signalList); | ||
export const defineInstanceSignals = (instanceId, signalList, subscribeConstructorSignals = true) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'defineSignals', { instanceId, signals: signalList }); | ||
logger.logMethodArgs?.('defineSignals', { instanceId, signals: signalList }); | ||
return subscribeSignals(instanceId, signalList, subscribeConstructorSignals); | ||
@@ -286,5 +271,4 @@ }; | ||
export const render = (instanceId, states, thisArg = null) => { | ||
var _a; | ||
const state = getFsmInstance(instanceId).state; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'render', { instanceId, state: state.target }); | ||
logger.logMethodArgs?.('render', { instanceId, state: state.target }); | ||
let renderFn = states[state.target]; | ||
@@ -303,4 +287,3 @@ if (typeof renderFn === 'string') { | ||
export const subscribe = (instanceId, callback, options) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'subscribe', instanceId); | ||
logger.logMethodArgs?.('subscribe', instanceId); | ||
return contextConsumer.subscribe(instanceId, callback, options); | ||
@@ -312,4 +295,3 @@ }; | ||
export const destroy = (instanceId) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'destroy', instanceId); | ||
logger.logMethodArgs?.('destroy', instanceId); | ||
destroySignal(instanceId); | ||
@@ -321,4 +303,3 @@ }; | ||
export const reset = (instanceId) => { | ||
var _a; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'reset', instanceId); | ||
logger.logMethodArgs?.('reset', instanceId); | ||
const constructorId = getFsmInstance(instanceId).constructorId; | ||
@@ -334,4 +315,3 @@ // contextProvider.expire(instanceId); | ||
export const finiteStateMachineConsumer = (instanceId, makeFromConstructor) => { | ||
var _a, _b; | ||
(_a = logger.logMethodArgs) === null || _a === void 0 ? void 0 : _a.call(logger, 'stateMachineLookup', instanceId); | ||
logger.logMethodArgs?.('stateMachineLookup', instanceId); | ||
const machineInstance = contextConsumer.getValue(instanceId); | ||
@@ -353,3 +333,3 @@ if (machineInstance == null) { | ||
*/ | ||
constructorId: (_b = machineInstance === null || machineInstance === void 0 ? void 0 : machineInstance.constructorId) !== null && _b !== void 0 ? _b : makeFromConstructor, | ||
constructorId: machineInstance?.constructorId ?? makeFromConstructor, | ||
/** | ||
@@ -356,0 +336,0 @@ * Render helper for use finite state machine instance in UI. |
{ | ||
"name": "@alwatr/fsm", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Managing invocations finite-state machines for lit-element written in tiny TypeScript module.", | ||
@@ -37,8 +37,8 @@ "keywords": [ | ||
"dependencies": { | ||
"@alwatr/logger": "^1.0.1", | ||
"@alwatr/signal": "^1.0.1", | ||
"@alwatr/type": "^1.0.1", | ||
"tslib": "^2.5.3" | ||
"@alwatr/logger": "^1.1.0", | ||
"@alwatr/signal": "^1.1.0", | ||
"@alwatr/type": "^1.1.0", | ||
"tslib": "^2.6.2" | ||
}, | ||
"gitHead": "10b9734389e27538ba4fa4ac7871ec0354ca9285" | ||
"gitHead": "e5c3bcb9d4f391a5a94d1469c5d31cbcd102c90b" | ||
} |
@@ -11,3 +11,3 @@ import type { finiteStateMachineConsumer } from './core.js'; | ||
actionRecord: ActionRecord; | ||
signalList: Array<SignalConfig>; | ||
signalList: SignalConfig[]; | ||
} | ||
@@ -14,0 +14,0 @@ export interface FsmConstructorConfig<TState extends string = string, TEventId extends string = string, TActionName extends string = string, TContext extends StringifyableRecord = StringifyableRecord> extends StringifyableRecord { |
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
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
72300
648
Updated@alwatr/logger@^1.1.0
Updated@alwatr/signal@^1.1.0
Updated@alwatr/type@^1.1.0
Updatedtslib@^2.6.2