jssm 5.54.0 → 5.56.2
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-dot.js +1 -1
- package/dist/es6/jssm.d.ts +3 -0
- package/dist/es6/jssm.js +39 -23
- 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 +3 -0
- package/package.json +8 -8
package/dist/es6/jssm.d.ts
CHANGED
|
@@ -40,8 +40,10 @@ declare class Machine<mDT> {
|
|
|
40
40
|
_has_hooks: boolean;
|
|
41
41
|
_has_basic_hooks: boolean;
|
|
42
42
|
_has_named_hooks: boolean;
|
|
43
|
+
_has_entry_hooks: boolean;
|
|
43
44
|
_hooks: Map<string, Function>;
|
|
44
45
|
_named_hooks: Map<string, Function>;
|
|
46
|
+
_entry_hooks: Map<string, Function>;
|
|
45
47
|
_any_transition_hook: HookHandler | undefined;
|
|
46
48
|
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>);
|
|
47
49
|
_new_state(state_config: JssmGenericState): StateType;
|
|
@@ -96,6 +98,7 @@ declare class Machine<mDT> {
|
|
|
96
98
|
hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
|
|
97
99
|
hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
|
|
98
100
|
hook_any_transition(handler: HookHandler): Machine<mDT>;
|
|
101
|
+
hook_entry(to: string, handler: HookHandler): Machine<mDT>;
|
|
99
102
|
transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
|
|
100
103
|
action(actionName: StateType, newData?: mDT): boolean;
|
|
101
104
|
transition(newState: StateType, newData?: mDT): boolean;
|
package/dist/es6/jssm.js
CHANGED
|
@@ -348,8 +348,11 @@ class Machine {
|
|
|
348
348
|
this._has_hooks = false;
|
|
349
349
|
this._has_basic_hooks = false;
|
|
350
350
|
this._has_named_hooks = false;
|
|
351
|
+
this._has_entry_hooks = false;
|
|
352
|
+
// no need for a boolean has any transition hook, as it's one or nothing, so just test that for undefinedness
|
|
351
353
|
this._hooks = new Map();
|
|
352
354
|
this._named_hooks = new Map();
|
|
355
|
+
this._entry_hooks = new Map();
|
|
353
356
|
this._any_transition_hook = undefined;
|
|
354
357
|
if (state_declaration) {
|
|
355
358
|
state_declaration.map((state_decl) => {
|
|
@@ -717,9 +720,10 @@ class Machine {
|
|
|
717
720
|
this._any_transition_hook = HookDesc.handler;
|
|
718
721
|
this._has_hooks = true;
|
|
719
722
|
break;
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
+
case 'entry':
|
|
724
|
+
this._entry_hooks.set(HookDesc.to, HookDesc.handler);
|
|
725
|
+
this._has_hooks = true;
|
|
726
|
+
break;
|
|
723
727
|
// case 'exit':
|
|
724
728
|
// console.log('TODO: Should add exit hook here');
|
|
725
729
|
// throw 'TODO: Should add exit hook here';
|
|
@@ -743,6 +747,11 @@ class Machine {
|
|
|
743
747
|
this.set_hook({ kind: 'any transition', handler });
|
|
744
748
|
return this;
|
|
745
749
|
}
|
|
750
|
+
hook_entry(to, handler) {
|
|
751
|
+
// TODO: should this throw if setting the hook fails, or ignore it and continue?
|
|
752
|
+
this.set_hook({ kind: 'entry', to, handler });
|
|
753
|
+
return this;
|
|
754
|
+
}
|
|
746
755
|
// remove_hook(HookDesc: HookDescription) {
|
|
747
756
|
// throw 'TODO: Should remove hook here';
|
|
748
757
|
// }
|
|
@@ -771,43 +780,50 @@ class Machine {
|
|
|
771
780
|
// todo major incomplete whargarbl comeback
|
|
772
781
|
if (valid) {
|
|
773
782
|
if (this._has_hooks) {
|
|
774
|
-
|
|
783
|
+
// 1. any action hook
|
|
784
|
+
// not yet implemented
|
|
785
|
+
// 2. any transition hook
|
|
775
786
|
if (this._any_transition_hook !== undefined) {
|
|
776
787
|
if (this._any_transition_hook() === false) {
|
|
777
788
|
return false;
|
|
778
789
|
}
|
|
779
790
|
}
|
|
791
|
+
// 3. exit hook
|
|
792
|
+
// not yet implemented
|
|
793
|
+
// 4. named transition / action hook
|
|
780
794
|
if (wasAction) {
|
|
781
795
|
const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
|
|
782
|
-
if (n_maybe_hook
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
hook_permits = n_maybe_hook({ from: this._state, to: newState, action: newStateOrAction });
|
|
787
|
-
}
|
|
788
|
-
if (!(hook_permits)) {
|
|
789
|
-
return false;
|
|
796
|
+
if (n_maybe_hook !== undefined) {
|
|
797
|
+
if (n_maybe_hook({ from: this._state, to: newState, action: newStateOrAction }) === false) {
|
|
798
|
+
return false;
|
|
799
|
+
}
|
|
790
800
|
}
|
|
791
801
|
}
|
|
802
|
+
// 5. regular hook
|
|
792
803
|
const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
|
|
793
|
-
if (maybe_hook
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
hook_permits = maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined });
|
|
798
|
-
}
|
|
799
|
-
if (hook_permits !== false) {
|
|
800
|
-
this._state = newState;
|
|
801
|
-
return true;
|
|
804
|
+
if (maybe_hook !== undefined) {
|
|
805
|
+
if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined }) === false) {
|
|
806
|
+
return false;
|
|
807
|
+
}
|
|
802
808
|
}
|
|
803
|
-
|
|
804
|
-
|
|
809
|
+
// 6. edge type hook
|
|
810
|
+
// not yet implemented
|
|
811
|
+
// 7. entry hook
|
|
812
|
+
const maybe_en_hook = this._entry_hooks.get(newState);
|
|
813
|
+
if (maybe_en_hook !== undefined) {
|
|
814
|
+
if (maybe_en_hook({ to: newState, forced: wasForced }) === false) {
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
805
817
|
}
|
|
818
|
+
this._state = newState;
|
|
819
|
+
return true;
|
|
820
|
+
// or without hooks
|
|
806
821
|
}
|
|
807
822
|
else {
|
|
808
823
|
this._state = newState;
|
|
809
824
|
return true;
|
|
810
825
|
}
|
|
826
|
+
// not valid
|
|
811
827
|
}
|
|
812
828
|
else {
|
|
813
829
|
return false;
|
package/dist/es6/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "5.
|
|
1
|
+
const version = "5.56.2";
|
|
2
2
|
export { version };
|