jssm 5.56.2 → 5.58.0
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/dist/es6/jssm.d.ts +4 -0
- package/dist/es6/jssm.js +36 -10
- package/dist/es6/jssm_types.d.ts +5 -1
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs.js +1 -1
- package/dist/jssm.es5.iife.js +1 -1
- package/jssm.d.ts +4 -0
- package/jssm_types.d.ts +5 -1
- package/package.json +1 -1
package/dist/es6/jssm.d.ts
CHANGED
|
@@ -41,9 +41,12 @@ declare class Machine<mDT> {
|
|
|
41
41
|
_has_basic_hooks: boolean;
|
|
42
42
|
_has_named_hooks: boolean;
|
|
43
43
|
_has_entry_hooks: boolean;
|
|
44
|
+
_has_exit_hooks: boolean;
|
|
44
45
|
_hooks: Map<string, Function>;
|
|
45
46
|
_named_hooks: Map<string, Function>;
|
|
46
47
|
_entry_hooks: Map<string, Function>;
|
|
48
|
+
_exit_hooks: Map<string, Function>;
|
|
49
|
+
_any_action_hook: HookHandler | undefined;
|
|
47
50
|
_any_transition_hook: HookHandler | undefined;
|
|
48
51
|
constructor({ start_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout }: JssmGenericConfig<mDT>);
|
|
49
52
|
_new_state(state_config: JssmGenericState): StateType;
|
|
@@ -99,6 +102,7 @@ declare class Machine<mDT> {
|
|
|
99
102
|
hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
|
|
100
103
|
hook_any_transition(handler: HookHandler): Machine<mDT>;
|
|
101
104
|
hook_entry(to: string, handler: HookHandler): Machine<mDT>;
|
|
105
|
+
hook_exit(from: string, handler: HookHandler): Machine<mDT>;
|
|
102
106
|
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
103
107
|
action(actionName: StateType, newData?: mDT): boolean;
|
|
104
108
|
transition(newState: StateType, newData?: mDT): boolean;
|
package/dist/es6/jssm.js
CHANGED
|
@@ -349,10 +349,13 @@ class Machine {
|
|
|
349
349
|
this._has_basic_hooks = false;
|
|
350
350
|
this._has_named_hooks = false;
|
|
351
351
|
this._has_entry_hooks = false;
|
|
352
|
+
this._has_exit_hooks = false;
|
|
352
353
|
// no need for a boolean has any transition hook, as it's one or nothing, so just test that for undefinedness
|
|
353
354
|
this._hooks = new Map();
|
|
354
355
|
this._named_hooks = new Map();
|
|
355
356
|
this._entry_hooks = new Map();
|
|
357
|
+
this._exit_hooks = new Map();
|
|
358
|
+
this._any_action_hook = undefined;
|
|
356
359
|
this._any_transition_hook = undefined;
|
|
357
360
|
if (state_declaration) {
|
|
358
361
|
state_declaration.map((state_decl) => {
|
|
@@ -716,6 +719,10 @@ class Machine {
|
|
|
716
719
|
this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
|
|
717
720
|
this._has_hooks = true;
|
|
718
721
|
break;
|
|
722
|
+
case 'any action':
|
|
723
|
+
this._any_action_hook = HookDesc.handler;
|
|
724
|
+
this._has_hooks = true;
|
|
725
|
+
break;
|
|
719
726
|
case 'any transition':
|
|
720
727
|
this._any_transition_hook = HookDesc.handler;
|
|
721
728
|
this._has_hooks = true;
|
|
@@ -724,9 +731,10 @@ class Machine {
|
|
|
724
731
|
this._entry_hooks.set(HookDesc.to, HookDesc.handler);
|
|
725
732
|
this._has_hooks = true;
|
|
726
733
|
break;
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
734
|
+
case 'exit':
|
|
735
|
+
this._exit_hooks.set(HookDesc.from, HookDesc.handler);
|
|
736
|
+
this._has_hooks = true;
|
|
737
|
+
break;
|
|
730
738
|
default:
|
|
731
739
|
console.log(`Unknown hook type ${HookDesc.kind}, should be impossible`);
|
|
732
740
|
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
|
|
@@ -752,6 +760,11 @@ class Machine {
|
|
|
752
760
|
this.set_hook({ kind: 'entry', to, handler });
|
|
753
761
|
return this;
|
|
754
762
|
}
|
|
763
|
+
hook_exit(from, handler) {
|
|
764
|
+
// TODO: should this throw if setting the hook fails, or ignore it and continue?
|
|
765
|
+
this.set_hook({ kind: 'exit', from, handler });
|
|
766
|
+
return this;
|
|
767
|
+
}
|
|
755
768
|
// remove_hook(HookDesc: HookDescription) {
|
|
756
769
|
// throw 'TODO: Should remove hook here';
|
|
757
770
|
// }
|
|
@@ -781,16 +794,29 @@ class Machine {
|
|
|
781
794
|
if (valid) {
|
|
782
795
|
if (this._has_hooks) {
|
|
783
796
|
// 1. any action hook
|
|
797
|
+
if (wasAction) {
|
|
798
|
+
if (this._any_action_hook !== undefined) {
|
|
799
|
+
if (this._any_action_hook() === false) {
|
|
800
|
+
return false;
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
// 2. global specific action hook
|
|
784
805
|
// not yet implemented
|
|
785
|
-
//
|
|
806
|
+
// 3. any transition hook
|
|
786
807
|
if (this._any_transition_hook !== undefined) {
|
|
787
808
|
if (this._any_transition_hook() === false) {
|
|
788
809
|
return false;
|
|
789
810
|
}
|
|
790
811
|
}
|
|
791
|
-
//
|
|
792
|
-
|
|
793
|
-
|
|
812
|
+
// 4. exit hook
|
|
813
|
+
const maybe_ex_hook = this._exit_hooks.get(this._state);
|
|
814
|
+
if (maybe_ex_hook !== undefined) {
|
|
815
|
+
if (maybe_ex_hook({ from: this._state, forced: wasForced }) === false) {
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
// 5. named transition / action hook
|
|
794
820
|
if (wasAction) {
|
|
795
821
|
const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
|
|
796
822
|
if (n_maybe_hook !== undefined) {
|
|
@@ -799,16 +825,16 @@ class Machine {
|
|
|
799
825
|
}
|
|
800
826
|
}
|
|
801
827
|
}
|
|
802
|
-
//
|
|
828
|
+
// 6. regular hook
|
|
803
829
|
const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
|
|
804
830
|
if (maybe_hook !== undefined) {
|
|
805
831
|
if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined }) === false) {
|
|
806
832
|
return false;
|
|
807
833
|
}
|
|
808
834
|
}
|
|
809
|
-
//
|
|
835
|
+
// 7. edge type hook
|
|
810
836
|
// not yet implemented
|
|
811
|
-
//
|
|
837
|
+
// 8. entry hook
|
|
812
838
|
const maybe_en_hook = this._entry_hooks.get(newState);
|
|
813
839
|
if (maybe_en_hook !== undefined) {
|
|
814
840
|
if (maybe_en_hook({ to: newState, forced: wasForced }) === false) {
|
package/dist/es6/jssm_types.d.ts
CHANGED
|
@@ -166,6 +166,10 @@ declare type AnyTransitionHook = {
|
|
|
166
166
|
kind: 'any transition';
|
|
167
167
|
handler: HookHandler;
|
|
168
168
|
};
|
|
169
|
+
declare type AnyActionHook = {
|
|
170
|
+
kind: 'any action';
|
|
171
|
+
handler: HookHandler;
|
|
172
|
+
};
|
|
169
173
|
declare type EntryHook = {
|
|
170
174
|
kind: 'entry';
|
|
171
175
|
to: string;
|
|
@@ -176,5 +180,5 @@ declare type ExitHook = {
|
|
|
176
180
|
from: string;
|
|
177
181
|
handler: HookHandler;
|
|
178
182
|
};
|
|
179
|
-
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | AnyTransitionHook | EntryHook | ExitHook;
|
|
183
|
+
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | AnyActionHook | AnyTransitionHook | EntryHook | ExitHook;
|
|
180
184
|
export { JssmColor, JssmTransition, JssmTransitions, JssmTransitionList, JssmTransitionRule, JssmArrow, JssmArrowKind, JssmArrowDirection, JssmGenericConfig, JssmGenericState, JssmGenericMachine, JssmParseTree, JssmCompileSe, JssmCompileSeStart, JssmCompileRule, JssmPermitted, JssmPermittedOpt, JssmResult, JssmStateDeclaration, JssmStateDeclarationRule, JssmLayout, JssmParseFunctionType, JssmMachineInternalState, FslDirection, FslTheme, HookDescription, HookHandler };
|
package/dist/es6/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "5.
|
|
1
|
+
const version = "5.58.0";
|
|
2
2
|
export { version };
|