jssm 5.162.4 → 5.162.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/dist/cdn/instance.js +1 -1
- package/dist/cdn/viz.js +1 -1
- package/dist/cli/fsl-export-system-prompt.cjs +1 -1
- package/dist/cli/fsl-render.cjs +1 -1
- package/dist/cli/fsl.cjs +1 -1
- package/dist/cli/lib.cjs +1 -1
- package/dist/cli/lib.mjs +1 -1
- package/dist/deno/README.md +7 -7
- package/dist/deno/jssm.d.ts +87 -2
- package/dist/deno/jssm.js +1 -1
- package/dist/deno/jssm_types.d.ts +11 -5
- package/dist/fence/fence.js +141 -15
- package/dist/jssm.es5.cjs +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/dist/jssm.es6.mjs +1 -1
- package/dist/jssm_viz.cjs +1 -1
- package/dist/jssm_viz.iife.cjs +1 -1
- package/dist/jssm_viz.mjs +1 -1
- package/jssm.es5.d.cts +98 -7
- package/jssm.es6.d.ts +98 -7
- package/jssm.fence.d.ts +98 -7
- package/jssm_viz.es5.d.cts +98 -7
- package/jssm_viz.es6.d.ts +98 -7
- package/package.json +1 -1
package/jssm.es5.d.cts
CHANGED
|
@@ -759,6 +759,10 @@ type AfterHook<mDT> = {
|
|
|
759
759
|
from: string;
|
|
760
760
|
handler: HookHandler<mDT>;
|
|
761
761
|
};
|
|
762
|
+
type AfterAnyHook<mDT> = {
|
|
763
|
+
kind: 'after any';
|
|
764
|
+
handler: HookHandler<mDT>;
|
|
765
|
+
};
|
|
762
766
|
type PostBasicHookDescription<mDT> = {
|
|
763
767
|
kind: 'post hook';
|
|
764
768
|
from: string;
|
|
@@ -832,12 +836,12 @@ type PostEverythingHook<mDT> = {
|
|
|
832
836
|
*
|
|
833
837
|
* Pre-transition variants (`'hook'`, `'named'`, `'standard transition'`,
|
|
834
838
|
* `'main transition'`, `'forced transition'`, `'any transition'`,
|
|
835
|
-
* `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'
|
|
836
|
-
* may return a falsy value to veto a transition. Post-transition
|
|
839
|
+
* `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`,
|
|
840
|
+
* `'after any'`) may return a falsy value to veto a transition. Post-transition
|
|
837
841
|
* variants (`'post *'`) cannot veto and are invoked only after a
|
|
838
842
|
* successful transition.
|
|
839
843
|
*/
|
|
840
|
-
type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
|
|
844
|
+
type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | AfterAnyHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
|
|
841
845
|
/**
|
|
842
846
|
* Whether an observational hook runs in the pre-transition phase (where it
|
|
843
847
|
* may veto/mutate the transition) or the post-transition phase (a pure
|
|
@@ -1092,7 +1096,9 @@ type JssmErrorEventDetail = {
|
|
|
1092
1096
|
/**
|
|
1093
1097
|
* Detail payload fired with a `data-change` event. Fires whenever the
|
|
1094
1098
|
* machine's data payload is replaced. `old_data` is the value before the
|
|
1095
|
-
* change; `new_data` is the value after.
|
|
1099
|
+
* change; `new_data` is the value after. `cause` names the API family that
|
|
1100
|
+
* performed the replacement: a data-bearing `transition`, an `override`, or
|
|
1101
|
+
* a direct `set_data` call.
|
|
1096
1102
|
*/
|
|
1097
1103
|
type JssmDataChangeEventDetail<mDT> = {
|
|
1098
1104
|
from?: StateType$1;
|
|
@@ -1100,7 +1106,7 @@ type JssmDataChangeEventDetail<mDT> = {
|
|
|
1100
1106
|
action?: StateType$1;
|
|
1101
1107
|
old_data: mDT;
|
|
1102
1108
|
new_data: mDT;
|
|
1103
|
-
cause: 'transition' | 'override';
|
|
1109
|
+
cause: 'transition' | 'override' | 'set_data';
|
|
1104
1110
|
};
|
|
1105
1111
|
/**
|
|
1106
1112
|
* Detail payload fired with an `override` event. Distinguishes a forced
|
|
@@ -2157,6 +2163,7 @@ declare class Machine<mDT> {
|
|
|
2157
2163
|
_entry_hooks: Map<number, HookHandler<mDT>>;
|
|
2158
2164
|
_exit_hooks: Map<number, HookHandler<mDT>>;
|
|
2159
2165
|
_after_hooks: Map<string, HookHandler<mDT>>;
|
|
2166
|
+
_after_any_hook: HookHandler<mDT> | undefined;
|
|
2160
2167
|
_global_action_hooks: Map<number, HookHandler<mDT>>;
|
|
2161
2168
|
_any_action_hook: HookHandler<mDT> | undefined;
|
|
2162
2169
|
_standard_transition_hook: HookHandler<mDT> | undefined;
|
|
@@ -2318,6 +2325,40 @@ declare class Machine<mDT> {
|
|
|
2318
2325
|
*
|
|
2319
2326
|
*/
|
|
2320
2327
|
data(): mDT;
|
|
2328
|
+
/*********
|
|
2329
|
+
*
|
|
2330
|
+
* Replace the machine's data in place, without a transition. This is the
|
|
2331
|
+
* practical way to assign any value — including `undefined`, `null`, or
|
|
2332
|
+
* `false` — outside a hook's complex return, closing the gap where an
|
|
2333
|
+
* `undefined` assignment had no direct API (StoneCypher/fsl#1264). Fires
|
|
2334
|
+
* a `data-change` event with cause `'set_data'` when the value actually
|
|
2335
|
+
* changes; unlike {@link override} it requires no `allows_override`
|
|
2336
|
+
* config, because it never moves the state.
|
|
2337
|
+
*
|
|
2338
|
+
* ```typescript
|
|
2339
|
+
* import * as jssm from 'jssm';
|
|
2340
|
+
*
|
|
2341
|
+
* const lswitch = jssm.from('on <=> off;', {data: 1});
|
|
2342
|
+
* console.log( lswitch.data() ); // 1
|
|
2343
|
+
*
|
|
2344
|
+
* lswitch.set_data(2);
|
|
2345
|
+
* console.log( lswitch.data() ); // 2
|
|
2346
|
+
*
|
|
2347
|
+
* lswitch.set_data(undefined);
|
|
2348
|
+
* console.log( lswitch.data() ); // undefined
|
|
2349
|
+
* ```
|
|
2350
|
+
*
|
|
2351
|
+
* @typeParam mDT The type of the machine data member; usually omitted
|
|
2352
|
+
*
|
|
2353
|
+
* @param newData The value to install as the machine's data.
|
|
2354
|
+
*
|
|
2355
|
+
* @returns The machine, for chaining.
|
|
2356
|
+
*
|
|
2357
|
+
* @see Machine.data
|
|
2358
|
+
* @see override
|
|
2359
|
+
*
|
|
2360
|
+
*/
|
|
2361
|
+
set_data(newData: mDT): Machine<mDT>;
|
|
2321
2362
|
/**
|
|
2322
2363
|
* The machine's current data by REFERENCE — no clone. The public
|
|
2323
2364
|
* {@link Machine.data} contract is a deep clone per call (a mutation
|
|
@@ -3633,6 +3674,33 @@ declare class Machine<mDT> {
|
|
|
3633
3674
|
* @see set_state_timeout
|
|
3634
3675
|
*/
|
|
3635
3676
|
hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3677
|
+
/** Register a hook that fires when ANY state's `after` timer elapses — the
|
|
3678
|
+
* whole-machine companion to {@link hook_after}, mirroring how
|
|
3679
|
+
* {@link hook_any_transition} companions {@link hook}. When the elapsing
|
|
3680
|
+
* state also has a specific {@link hook_after}, the specific hook fires
|
|
3681
|
+
* first and this one fires second; a specific after hook firing always
|
|
3682
|
+
* implies the any-after hook fires too (StoneCypher/fsl#1299). Like
|
|
3683
|
+
* `hook_after` it is informational — its outcome cannot reject the timed
|
|
3684
|
+
* transition — and it does NOT fire on ordinary dispatch.
|
|
3685
|
+
* @param handler - Callback invoked whenever any `after` timer fires, just
|
|
3686
|
+
* before the timed transition is taken.
|
|
3687
|
+
* @returns `this` for chaining.
|
|
3688
|
+
*
|
|
3689
|
+
* @example
|
|
3690
|
+
* const m = sm`a after 1000 -> b; a -> c; c -> a;`;
|
|
3691
|
+
* let calls = 0;
|
|
3692
|
+
* m.hook_after_any(() => { calls += 1; });
|
|
3693
|
+
* m.go('c');
|
|
3694
|
+
* m.go('a');
|
|
3695
|
+
* // ordinary dispatch never fires it; only a timer elapsing does:
|
|
3696
|
+
* calls; // => 0
|
|
3697
|
+
* m.clear_state_timeout();
|
|
3698
|
+
*
|
|
3699
|
+
* @see hook_after
|
|
3700
|
+
* @see hook_any_transition
|
|
3701
|
+
* @see set_state_timeout
|
|
3702
|
+
*/
|
|
3703
|
+
hook_after_any(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3636
3704
|
/** Post-transition hook on a specific edge. Fires after the transition
|
|
3637
3705
|
* from `from` to `to` has completed. Cannot block the transition.
|
|
3638
3706
|
* @param from - Source state name.
|
|
@@ -3777,7 +3845,13 @@ declare class Machine<mDT> {
|
|
|
3777
3845
|
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
|
|
3778
3846
|
/*********
|
|
3779
3847
|
*
|
|
3780
|
-
* Replace the current state and data
|
|
3848
|
+
* Replace the current state — and, when a data argument is provided, the
|
|
3849
|
+
* data — with no regard to the graph.
|
|
3850
|
+
*
|
|
3851
|
+
* The data argument is arity-detected: omitting it preserves the current
|
|
3852
|
+
* data, while explicitly passing `undefined` really sets the data to
|
|
3853
|
+
* `undefined` (StoneCypher/fsl#1264). Before 5.163 an omitted data
|
|
3854
|
+
* argument silently cleared the data.
|
|
3781
3855
|
*
|
|
3782
3856
|
* ```typescript
|
|
3783
3857
|
* import { sm } from 'jssm';
|
|
@@ -3793,6 +3867,16 @@ declare class Machine<mDT> {
|
|
|
3793
3867
|
* console.log( machine.state() ); // 'a'
|
|
3794
3868
|
* ```
|
|
3795
3869
|
*
|
|
3870
|
+
* @param newState The state to teleport to; must exist in the graph.
|
|
3871
|
+
*
|
|
3872
|
+
* @param newData Replacement data. Omit to keep the current data; pass
|
|
3873
|
+
* `undefined` explicitly to clear it.
|
|
3874
|
+
*
|
|
3875
|
+
* @throws {JssmError} If the machine's config does not set
|
|
3876
|
+
* `allows_override: true`, or if `newState` does not exist.
|
|
3877
|
+
*
|
|
3878
|
+
* @see set_data
|
|
3879
|
+
*
|
|
3796
3880
|
*/
|
|
3797
3881
|
override(newState: StateType, newData?: mDT | undefined): void;
|
|
3798
3882
|
/*********
|
|
@@ -3907,13 +3991,20 @@ declare class Machine<mDT> {
|
|
|
3907
3991
|
* `newStateOrAction` is an action name and the target state is looked up
|
|
3908
3992
|
* via the current action edge.
|
|
3909
3993
|
*
|
|
3994
|
+
* @param dataProvided `true` when the caller explicitly supplied a data
|
|
3995
|
+
* argument — even an explicitly-`undefined` one, which commits `undefined`
|
|
3996
|
+
* as the new data (StoneCypher/fsl#1264). When `false` the current data
|
|
3997
|
+
* is preserved. The public wrappers derive this from call arity; the
|
|
3998
|
+
* default reproduces the old `!== undefined` inference for any direct
|
|
3999
|
+
* callers.
|
|
4000
|
+
*
|
|
3910
4001
|
* @returns `true` if the transition was valid and every hook passed;
|
|
3911
4002
|
* `false` if the transition was invalid or any hook rejected.
|
|
3912
4003
|
*
|
|
3913
4004
|
* @internal
|
|
3914
4005
|
*
|
|
3915
4006
|
*/
|
|
3916
|
-
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
4007
|
+
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean, dataProvided?: boolean): boolean;
|
|
3917
4008
|
/** If the current state has an `after` timeout configured, schedule it.
|
|
3918
4009
|
* Called internally after each transition.
|
|
3919
4010
|
*/
|
package/jssm.es6.d.ts
CHANGED
|
@@ -759,6 +759,10 @@ type AfterHook<mDT> = {
|
|
|
759
759
|
from: string;
|
|
760
760
|
handler: HookHandler<mDT>;
|
|
761
761
|
};
|
|
762
|
+
type AfterAnyHook<mDT> = {
|
|
763
|
+
kind: 'after any';
|
|
764
|
+
handler: HookHandler<mDT>;
|
|
765
|
+
};
|
|
762
766
|
type PostBasicHookDescription<mDT> = {
|
|
763
767
|
kind: 'post hook';
|
|
764
768
|
from: string;
|
|
@@ -832,12 +836,12 @@ type PostEverythingHook<mDT> = {
|
|
|
832
836
|
*
|
|
833
837
|
* Pre-transition variants (`'hook'`, `'named'`, `'standard transition'`,
|
|
834
838
|
* `'main transition'`, `'forced transition'`, `'any transition'`,
|
|
835
|
-
* `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'
|
|
836
|
-
* may return a falsy value to veto a transition. Post-transition
|
|
839
|
+
* `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`,
|
|
840
|
+
* `'after any'`) may return a falsy value to veto a transition. Post-transition
|
|
837
841
|
* variants (`'post *'`) cannot veto and are invoked only after a
|
|
838
842
|
* successful transition.
|
|
839
843
|
*/
|
|
840
|
-
type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
|
|
844
|
+
type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | AfterAnyHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
|
|
841
845
|
/**
|
|
842
846
|
* Whether an observational hook runs in the pre-transition phase (where it
|
|
843
847
|
* may veto/mutate the transition) or the post-transition phase (a pure
|
|
@@ -1092,7 +1096,9 @@ type JssmErrorEventDetail = {
|
|
|
1092
1096
|
/**
|
|
1093
1097
|
* Detail payload fired with a `data-change` event. Fires whenever the
|
|
1094
1098
|
* machine's data payload is replaced. `old_data` is the value before the
|
|
1095
|
-
* change; `new_data` is the value after.
|
|
1099
|
+
* change; `new_data` is the value after. `cause` names the API family that
|
|
1100
|
+
* performed the replacement: a data-bearing `transition`, an `override`, or
|
|
1101
|
+
* a direct `set_data` call.
|
|
1096
1102
|
*/
|
|
1097
1103
|
type JssmDataChangeEventDetail<mDT> = {
|
|
1098
1104
|
from?: StateType$1;
|
|
@@ -1100,7 +1106,7 @@ type JssmDataChangeEventDetail<mDT> = {
|
|
|
1100
1106
|
action?: StateType$1;
|
|
1101
1107
|
old_data: mDT;
|
|
1102
1108
|
new_data: mDT;
|
|
1103
|
-
cause: 'transition' | 'override';
|
|
1109
|
+
cause: 'transition' | 'override' | 'set_data';
|
|
1104
1110
|
};
|
|
1105
1111
|
/**
|
|
1106
1112
|
* Detail payload fired with an `override` event. Distinguishes a forced
|
|
@@ -2157,6 +2163,7 @@ declare class Machine<mDT> {
|
|
|
2157
2163
|
_entry_hooks: Map<number, HookHandler<mDT>>;
|
|
2158
2164
|
_exit_hooks: Map<number, HookHandler<mDT>>;
|
|
2159
2165
|
_after_hooks: Map<string, HookHandler<mDT>>;
|
|
2166
|
+
_after_any_hook: HookHandler<mDT> | undefined;
|
|
2160
2167
|
_global_action_hooks: Map<number, HookHandler<mDT>>;
|
|
2161
2168
|
_any_action_hook: HookHandler<mDT> | undefined;
|
|
2162
2169
|
_standard_transition_hook: HookHandler<mDT> | undefined;
|
|
@@ -2318,6 +2325,40 @@ declare class Machine<mDT> {
|
|
|
2318
2325
|
*
|
|
2319
2326
|
*/
|
|
2320
2327
|
data(): mDT;
|
|
2328
|
+
/*********
|
|
2329
|
+
*
|
|
2330
|
+
* Replace the machine's data in place, without a transition. This is the
|
|
2331
|
+
* practical way to assign any value — including `undefined`, `null`, or
|
|
2332
|
+
* `false` — outside a hook's complex return, closing the gap where an
|
|
2333
|
+
* `undefined` assignment had no direct API (StoneCypher/fsl#1264). Fires
|
|
2334
|
+
* a `data-change` event with cause `'set_data'` when the value actually
|
|
2335
|
+
* changes; unlike {@link override} it requires no `allows_override`
|
|
2336
|
+
* config, because it never moves the state.
|
|
2337
|
+
*
|
|
2338
|
+
* ```typescript
|
|
2339
|
+
* import * as jssm from 'jssm';
|
|
2340
|
+
*
|
|
2341
|
+
* const lswitch = jssm.from('on <=> off;', {data: 1});
|
|
2342
|
+
* console.log( lswitch.data() ); // 1
|
|
2343
|
+
*
|
|
2344
|
+
* lswitch.set_data(2);
|
|
2345
|
+
* console.log( lswitch.data() ); // 2
|
|
2346
|
+
*
|
|
2347
|
+
* lswitch.set_data(undefined);
|
|
2348
|
+
* console.log( lswitch.data() ); // undefined
|
|
2349
|
+
* ```
|
|
2350
|
+
*
|
|
2351
|
+
* @typeParam mDT The type of the machine data member; usually omitted
|
|
2352
|
+
*
|
|
2353
|
+
* @param newData The value to install as the machine's data.
|
|
2354
|
+
*
|
|
2355
|
+
* @returns The machine, for chaining.
|
|
2356
|
+
*
|
|
2357
|
+
* @see Machine.data
|
|
2358
|
+
* @see override
|
|
2359
|
+
*
|
|
2360
|
+
*/
|
|
2361
|
+
set_data(newData: mDT): Machine<mDT>;
|
|
2321
2362
|
/**
|
|
2322
2363
|
* The machine's current data by REFERENCE — no clone. The public
|
|
2323
2364
|
* {@link Machine.data} contract is a deep clone per call (a mutation
|
|
@@ -3633,6 +3674,33 @@ declare class Machine<mDT> {
|
|
|
3633
3674
|
* @see set_state_timeout
|
|
3634
3675
|
*/
|
|
3635
3676
|
hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
3677
|
+
/** Register a hook that fires when ANY state's `after` timer elapses — the
|
|
3678
|
+
* whole-machine companion to {@link hook_after}, mirroring how
|
|
3679
|
+
* {@link hook_any_transition} companions {@link hook}. When the elapsing
|
|
3680
|
+
* state also has a specific {@link hook_after}, the specific hook fires
|
|
3681
|
+
* first and this one fires second; a specific after hook firing always
|
|
3682
|
+
* implies the any-after hook fires too (StoneCypher/fsl#1299). Like
|
|
3683
|
+
* `hook_after` it is informational — its outcome cannot reject the timed
|
|
3684
|
+
* transition — and it does NOT fire on ordinary dispatch.
|
|
3685
|
+
* @param handler - Callback invoked whenever any `after` timer fires, just
|
|
3686
|
+
* before the timed transition is taken.
|
|
3687
|
+
* @returns `this` for chaining.
|
|
3688
|
+
*
|
|
3689
|
+
* @example
|
|
3690
|
+
* const m = sm`a after 1000 -> b; a -> c; c -> a;`;
|
|
3691
|
+
* let calls = 0;
|
|
3692
|
+
* m.hook_after_any(() => { calls += 1; });
|
|
3693
|
+
* m.go('c');
|
|
3694
|
+
* m.go('a');
|
|
3695
|
+
* // ordinary dispatch never fires it; only a timer elapsing does:
|
|
3696
|
+
* calls; // => 0
|
|
3697
|
+
* m.clear_state_timeout();
|
|
3698
|
+
*
|
|
3699
|
+
* @see hook_after
|
|
3700
|
+
* @see hook_any_transition
|
|
3701
|
+
* @see set_state_timeout
|
|
3702
|
+
*/
|
|
3703
|
+
hook_after_any(handler: HookHandler<mDT>): Machine<mDT>;
|
|
3636
3704
|
/** Post-transition hook on a specific edge. Fires after the transition
|
|
3637
3705
|
* from `from` to `to` has completed. Cannot block the transition.
|
|
3638
3706
|
* @param from - Source state name.
|
|
@@ -3777,7 +3845,13 @@ declare class Machine<mDT> {
|
|
|
3777
3845
|
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
|
|
3778
3846
|
/*********
|
|
3779
3847
|
*
|
|
3780
|
-
* Replace the current state and data
|
|
3848
|
+
* Replace the current state — and, when a data argument is provided, the
|
|
3849
|
+
* data — with no regard to the graph.
|
|
3850
|
+
*
|
|
3851
|
+
* The data argument is arity-detected: omitting it preserves the current
|
|
3852
|
+
* data, while explicitly passing `undefined` really sets the data to
|
|
3853
|
+
* `undefined` (StoneCypher/fsl#1264). Before 5.163 an omitted data
|
|
3854
|
+
* argument silently cleared the data.
|
|
3781
3855
|
*
|
|
3782
3856
|
* ```typescript
|
|
3783
3857
|
* import { sm } from 'jssm';
|
|
@@ -3793,6 +3867,16 @@ declare class Machine<mDT> {
|
|
|
3793
3867
|
* console.log( machine.state() ); // 'a'
|
|
3794
3868
|
* ```
|
|
3795
3869
|
*
|
|
3870
|
+
* @param newState The state to teleport to; must exist in the graph.
|
|
3871
|
+
*
|
|
3872
|
+
* @param newData Replacement data. Omit to keep the current data; pass
|
|
3873
|
+
* `undefined` explicitly to clear it.
|
|
3874
|
+
*
|
|
3875
|
+
* @throws {JssmError} If the machine's config does not set
|
|
3876
|
+
* `allows_override: true`, or if `newState` does not exist.
|
|
3877
|
+
*
|
|
3878
|
+
* @see set_data
|
|
3879
|
+
*
|
|
3796
3880
|
*/
|
|
3797
3881
|
override(newState: StateType, newData?: mDT | undefined): void;
|
|
3798
3882
|
/*********
|
|
@@ -3907,13 +3991,20 @@ declare class Machine<mDT> {
|
|
|
3907
3991
|
* `newStateOrAction` is an action name and the target state is looked up
|
|
3908
3992
|
* via the current action edge.
|
|
3909
3993
|
*
|
|
3994
|
+
* @param dataProvided `true` when the caller explicitly supplied a data
|
|
3995
|
+
* argument — even an explicitly-`undefined` one, which commits `undefined`
|
|
3996
|
+
* as the new data (StoneCypher/fsl#1264). When `false` the current data
|
|
3997
|
+
* is preserved. The public wrappers derive this from call arity; the
|
|
3998
|
+
* default reproduces the old `!== undefined` inference for any direct
|
|
3999
|
+
* callers.
|
|
4000
|
+
*
|
|
3910
4001
|
* @returns `true` if the transition was valid and every hook passed;
|
|
3911
4002
|
* `false` if the transition was invalid or any hook rejected.
|
|
3912
4003
|
*
|
|
3913
4004
|
* @internal
|
|
3914
4005
|
*
|
|
3915
4006
|
*/
|
|
3916
|
-
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
4007
|
+
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean, dataProvided?: boolean): boolean;
|
|
3917
4008
|
/** If the current state has an `after` timeout configured, schedule it.
|
|
3918
4009
|
* Called internally after each transition.
|
|
3919
4010
|
*/
|
package/jssm.fence.d.ts
CHANGED
|
@@ -880,6 +880,10 @@ type AfterHook<mDT> = {
|
|
|
880
880
|
from: string;
|
|
881
881
|
handler: HookHandler<mDT>;
|
|
882
882
|
};
|
|
883
|
+
type AfterAnyHook<mDT> = {
|
|
884
|
+
kind: 'after any';
|
|
885
|
+
handler: HookHandler<mDT>;
|
|
886
|
+
};
|
|
883
887
|
type PostBasicHookDescription<mDT> = {
|
|
884
888
|
kind: 'post hook';
|
|
885
889
|
from: string;
|
|
@@ -953,12 +957,12 @@ type PostEverythingHook<mDT> = {
|
|
|
953
957
|
*
|
|
954
958
|
* Pre-transition variants (`'hook'`, `'named'`, `'standard transition'`,
|
|
955
959
|
* `'main transition'`, `'forced transition'`, `'any transition'`,
|
|
956
|
-
* `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'
|
|
957
|
-
* may return a falsy value to veto a transition. Post-transition
|
|
960
|
+
* `'global action'`, `'any action'`, `'entry'`, `'exit'`, `'after'`,
|
|
961
|
+
* `'after any'`) may return a falsy value to veto a transition. Post-transition
|
|
958
962
|
* variants (`'post *'`) cannot veto and are invoked only after a
|
|
959
963
|
* successful transition.
|
|
960
964
|
*/
|
|
961
|
-
type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
|
|
965
|
+
type HookDescription<mDT> = BasicHookDescription<mDT> | HookDescriptionWithAction<mDT> | GlobalActionHook<mDT> | AnyActionHook<mDT> | StandardTransitionHook<mDT> | MainTransitionHook<mDT> | ForcedTransitionHook<mDT> | AnyTransitionHook<mDT> | EntryHook<mDT> | ExitHook<mDT> | AfterHook<mDT> | AfterAnyHook<mDT> | PostBasicHookDescription<mDT> | PostHookDescriptionWithAction<mDT> | PostGlobalActionHook<mDT> | PostAnyActionHook<mDT> | PostStandardTransitionHook<mDT> | PostMainTransitionHook<mDT> | PostForcedTransitionHook<mDT> | PostAnyTransitionHook<mDT> | PostEntryHook<mDT> | PostExitHook<mDT> | PreEverythingHook<mDT> | EverythingHook<mDT> | PrePostEverythingHook<mDT> | PostEverythingHook<mDT>;
|
|
962
966
|
/**
|
|
963
967
|
* Whether an observational hook runs in the pre-transition phase (where it
|
|
964
968
|
* may veto/mutate the transition) or the post-transition phase (a pure
|
|
@@ -1213,7 +1217,9 @@ type JssmErrorEventDetail = {
|
|
|
1213
1217
|
/**
|
|
1214
1218
|
* Detail payload fired with a `data-change` event. Fires whenever the
|
|
1215
1219
|
* machine's data payload is replaced. `old_data` is the value before the
|
|
1216
|
-
* change; `new_data` is the value after.
|
|
1220
|
+
* change; `new_data` is the value after. `cause` names the API family that
|
|
1221
|
+
* performed the replacement: a data-bearing `transition`, an `override`, or
|
|
1222
|
+
* a direct `set_data` call.
|
|
1217
1223
|
*/
|
|
1218
1224
|
type JssmDataChangeEventDetail<mDT> = {
|
|
1219
1225
|
from?: StateType$1;
|
|
@@ -1221,7 +1227,7 @@ type JssmDataChangeEventDetail<mDT> = {
|
|
|
1221
1227
|
action?: StateType$1;
|
|
1222
1228
|
old_data: mDT;
|
|
1223
1229
|
new_data: mDT;
|
|
1224
|
-
cause: 'transition' | 'override';
|
|
1230
|
+
cause: 'transition' | 'override' | 'set_data';
|
|
1225
1231
|
};
|
|
1226
1232
|
/**
|
|
1227
1233
|
* Detail payload fired with an `override` event. Distinguishes a forced
|
|
@@ -1460,6 +1466,7 @@ declare class Machine<mDT> {
|
|
|
1460
1466
|
_entry_hooks: Map<number, HookHandler<mDT>>;
|
|
1461
1467
|
_exit_hooks: Map<number, HookHandler<mDT>>;
|
|
1462
1468
|
_after_hooks: Map<string, HookHandler<mDT>>;
|
|
1469
|
+
_after_any_hook: HookHandler<mDT> | undefined;
|
|
1463
1470
|
_global_action_hooks: Map<number, HookHandler<mDT>>;
|
|
1464
1471
|
_any_action_hook: HookHandler<mDT> | undefined;
|
|
1465
1472
|
_standard_transition_hook: HookHandler<mDT> | undefined;
|
|
@@ -1621,6 +1628,40 @@ declare class Machine<mDT> {
|
|
|
1621
1628
|
*
|
|
1622
1629
|
*/
|
|
1623
1630
|
data(): mDT;
|
|
1631
|
+
/*********
|
|
1632
|
+
*
|
|
1633
|
+
* Replace the machine's data in place, without a transition. This is the
|
|
1634
|
+
* practical way to assign any value — including `undefined`, `null`, or
|
|
1635
|
+
* `false` — outside a hook's complex return, closing the gap where an
|
|
1636
|
+
* `undefined` assignment had no direct API (StoneCypher/fsl#1264). Fires
|
|
1637
|
+
* a `data-change` event with cause `'set_data'` when the value actually
|
|
1638
|
+
* changes; unlike {@link override} it requires no `allows_override`
|
|
1639
|
+
* config, because it never moves the state.
|
|
1640
|
+
*
|
|
1641
|
+
* ```typescript
|
|
1642
|
+
* import * as jssm from 'jssm';
|
|
1643
|
+
*
|
|
1644
|
+
* const lswitch = jssm.from('on <=> off;', {data: 1});
|
|
1645
|
+
* console.log( lswitch.data() ); // 1
|
|
1646
|
+
*
|
|
1647
|
+
* lswitch.set_data(2);
|
|
1648
|
+
* console.log( lswitch.data() ); // 2
|
|
1649
|
+
*
|
|
1650
|
+
* lswitch.set_data(undefined);
|
|
1651
|
+
* console.log( lswitch.data() ); // undefined
|
|
1652
|
+
* ```
|
|
1653
|
+
*
|
|
1654
|
+
* @typeParam mDT The type of the machine data member; usually omitted
|
|
1655
|
+
*
|
|
1656
|
+
* @param newData The value to install as the machine's data.
|
|
1657
|
+
*
|
|
1658
|
+
* @returns The machine, for chaining.
|
|
1659
|
+
*
|
|
1660
|
+
* @see Machine.data
|
|
1661
|
+
* @see override
|
|
1662
|
+
*
|
|
1663
|
+
*/
|
|
1664
|
+
set_data(newData: mDT): Machine<mDT>;
|
|
1624
1665
|
/**
|
|
1625
1666
|
* The machine's current data by REFERENCE — no clone. The public
|
|
1626
1667
|
* {@link Machine.data} contract is a deep clone per call (a mutation
|
|
@@ -2936,6 +2977,33 @@ declare class Machine<mDT> {
|
|
|
2936
2977
|
* @see set_state_timeout
|
|
2937
2978
|
*/
|
|
2938
2979
|
hook_after(from: string, handler: HookHandler<mDT>): Machine<mDT>;
|
|
2980
|
+
/** Register a hook that fires when ANY state's `after` timer elapses — the
|
|
2981
|
+
* whole-machine companion to {@link hook_after}, mirroring how
|
|
2982
|
+
* {@link hook_any_transition} companions {@link hook}. When the elapsing
|
|
2983
|
+
* state also has a specific {@link hook_after}, the specific hook fires
|
|
2984
|
+
* first and this one fires second; a specific after hook firing always
|
|
2985
|
+
* implies the any-after hook fires too (StoneCypher/fsl#1299). Like
|
|
2986
|
+
* `hook_after` it is informational — its outcome cannot reject the timed
|
|
2987
|
+
* transition — and it does NOT fire on ordinary dispatch.
|
|
2988
|
+
* @param handler - Callback invoked whenever any `after` timer fires, just
|
|
2989
|
+
* before the timed transition is taken.
|
|
2990
|
+
* @returns `this` for chaining.
|
|
2991
|
+
*
|
|
2992
|
+
* @example
|
|
2993
|
+
* const m = sm`a after 1000 -> b; a -> c; c -> a;`;
|
|
2994
|
+
* let calls = 0;
|
|
2995
|
+
* m.hook_after_any(() => { calls += 1; });
|
|
2996
|
+
* m.go('c');
|
|
2997
|
+
* m.go('a');
|
|
2998
|
+
* // ordinary dispatch never fires it; only a timer elapsing does:
|
|
2999
|
+
* calls; // => 0
|
|
3000
|
+
* m.clear_state_timeout();
|
|
3001
|
+
*
|
|
3002
|
+
* @see hook_after
|
|
3003
|
+
* @see hook_any_transition
|
|
3004
|
+
* @see set_state_timeout
|
|
3005
|
+
*/
|
|
3006
|
+
hook_after_any(handler: HookHandler<mDT>): Machine<mDT>;
|
|
2939
3007
|
/** Post-transition hook on a specific edge. Fires after the transition
|
|
2940
3008
|
* from `from` to `to` has completed. Cannot block the transition.
|
|
2941
3009
|
* @param from - Source state name.
|
|
@@ -3080,7 +3148,13 @@ declare class Machine<mDT> {
|
|
|
3080
3148
|
edges_between(from: string, to: string): JssmTransition<StateType, mDT>[];
|
|
3081
3149
|
/*********
|
|
3082
3150
|
*
|
|
3083
|
-
* Replace the current state and data
|
|
3151
|
+
* Replace the current state — and, when a data argument is provided, the
|
|
3152
|
+
* data — with no regard to the graph.
|
|
3153
|
+
*
|
|
3154
|
+
* The data argument is arity-detected: omitting it preserves the current
|
|
3155
|
+
* data, while explicitly passing `undefined` really sets the data to
|
|
3156
|
+
* `undefined` (StoneCypher/fsl#1264). Before 5.163 an omitted data
|
|
3157
|
+
* argument silently cleared the data.
|
|
3084
3158
|
*
|
|
3085
3159
|
* ```typescript
|
|
3086
3160
|
* import { sm } from 'jssm';
|
|
@@ -3096,6 +3170,16 @@ declare class Machine<mDT> {
|
|
|
3096
3170
|
* console.log( machine.state() ); // 'a'
|
|
3097
3171
|
* ```
|
|
3098
3172
|
*
|
|
3173
|
+
* @param newState The state to teleport to; must exist in the graph.
|
|
3174
|
+
*
|
|
3175
|
+
* @param newData Replacement data. Omit to keep the current data; pass
|
|
3176
|
+
* `undefined` explicitly to clear it.
|
|
3177
|
+
*
|
|
3178
|
+
* @throws {JssmError} If the machine's config does not set
|
|
3179
|
+
* `allows_override: true`, or if `newState` does not exist.
|
|
3180
|
+
*
|
|
3181
|
+
* @see set_data
|
|
3182
|
+
*
|
|
3099
3183
|
*/
|
|
3100
3184
|
override(newState: StateType, newData?: mDT | undefined): void;
|
|
3101
3185
|
/*********
|
|
@@ -3210,13 +3294,20 @@ declare class Machine<mDT> {
|
|
|
3210
3294
|
* `newStateOrAction` is an action name and the target state is looked up
|
|
3211
3295
|
* via the current action edge.
|
|
3212
3296
|
*
|
|
3297
|
+
* @param dataProvided `true` when the caller explicitly supplied a data
|
|
3298
|
+
* argument — even an explicitly-`undefined` one, which commits `undefined`
|
|
3299
|
+
* as the new data (StoneCypher/fsl#1264). When `false` the current data
|
|
3300
|
+
* is preserved. The public wrappers derive this from call arity; the
|
|
3301
|
+
* default reproduces the old `!== undefined` inference for any direct
|
|
3302
|
+
* callers.
|
|
3303
|
+
*
|
|
3213
3304
|
* @returns `true` if the transition was valid and every hook passed;
|
|
3214
3305
|
* `false` if the transition was invalid or any hook rejected.
|
|
3215
3306
|
*
|
|
3216
3307
|
* @internal
|
|
3217
3308
|
*
|
|
3218
3309
|
*/
|
|
3219
|
-
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
3310
|
+
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean, dataProvided?: boolean): boolean;
|
|
3220
3311
|
/** If the current state has an `after` timeout configured, schedule it.
|
|
3221
3312
|
* Called internally after each transition.
|
|
3222
3313
|
*/
|