jssm 5.57.1 → 5.59.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.
@@ -46,6 +46,8 @@ declare class Machine<mDT> {
46
46
  _named_hooks: Map<string, Function>;
47
47
  _entry_hooks: Map<string, Function>;
48
48
  _exit_hooks: Map<string, Function>;
49
+ _global_action_hooks: Map<string, Function>;
50
+ _any_action_hook: HookHandler | undefined;
49
51
  _any_transition_hook: HookHandler | undefined;
50
52
  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>);
51
53
  _new_state(state_config: JssmGenericState): StateType;
@@ -99,6 +101,7 @@ declare class Machine<mDT> {
99
101
  set_hook(HookDesc: HookDescription): void;
100
102
  hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
101
103
  hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
104
+ hook_any_action(handler: HookHandler): Machine<mDT>;
102
105
  hook_any_transition(handler: HookHandler): Machine<mDT>;
103
106
  hook_entry(to: string, handler: HookHandler): Machine<mDT>;
104
107
  hook_exit(from: string, handler: HookHandler): Machine<mDT>;
package/dist/es6/jssm.js CHANGED
@@ -355,6 +355,8 @@ class Machine {
355
355
  this._named_hooks = new Map();
356
356
  this._entry_hooks = new Map();
357
357
  this._exit_hooks = new Map();
358
+ this._global_action_hooks = new Map();
359
+ this._any_action_hook = undefined;
358
360
  this._any_transition_hook = undefined;
359
361
  if (state_declaration) {
360
362
  state_declaration.map((state_decl) => {
@@ -718,6 +720,14 @@ class Machine {
718
720
  this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
719
721
  this._has_hooks = true;
720
722
  break;
723
+ case 'global action':
724
+ this._global_action_hooks.set(HookDesc.action, HookDesc.handler);
725
+ this._has_hooks = true;
726
+ break;
727
+ case 'any action':
728
+ this._any_action_hook = HookDesc.handler;
729
+ this._has_hooks = true;
730
+ break;
721
731
  case 'any transition':
722
732
  this._any_transition_hook = HookDesc.handler;
723
733
  this._has_hooks = true;
@@ -745,6 +755,11 @@ class Machine {
745
755
  this.set_hook({ kind: 'named', from, to, action, handler });
746
756
  return this;
747
757
  }
758
+ hook_any_action(handler) {
759
+ // TODO: should this throw if setting the hook fails, or ignore it and continue?
760
+ this.set_hook({ kind: 'any action', handler });
761
+ return this;
762
+ }
748
763
  hook_any_transition(handler) {
749
764
  // TODO: should this throw if setting the hook fails, or ignore it and continue?
750
765
  this.set_hook({ kind: 'any transition', handler });
@@ -788,22 +803,35 @@ class Machine {
788
803
  // todo major incomplete whargarbl comeback
789
804
  if (valid) {
790
805
  if (this._has_hooks) {
791
- // 1. any action hook
792
- // not yet implemented
793
- // 2. any transition hook
806
+ if (wasAction) {
807
+ // 1. any action hook
808
+ if (this._any_action_hook !== undefined) {
809
+ if (this._any_action_hook() === false) {
810
+ return false;
811
+ }
812
+ }
813
+ // 2. global specific action hook
814
+ const maybe_ga_hook = this._global_action_hooks.get(newStateOrAction);
815
+ if (maybe_ga_hook !== undefined) {
816
+ if (maybe_ga_hook({ action: newStateOrAction, forced: wasForced }) === false) {
817
+ return false;
818
+ }
819
+ }
820
+ }
821
+ // 3. any transition hook
794
822
  if (this._any_transition_hook !== undefined) {
795
823
  if (this._any_transition_hook() === false) {
796
824
  return false;
797
825
  }
798
826
  }
799
- // 3. exit hook
827
+ // 4. exit hook
800
828
  const maybe_ex_hook = this._exit_hooks.get(this._state);
801
829
  if (maybe_ex_hook !== undefined) {
802
830
  if (maybe_ex_hook({ from: this._state, forced: wasForced }) === false) {
803
831
  return false;
804
832
  }
805
833
  }
806
- // 4. named transition / action hook
834
+ // 5. named transition / action hook
807
835
  if (wasAction) {
808
836
  const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
809
837
  if (n_maybe_hook !== undefined) {
@@ -812,16 +840,16 @@ class Machine {
812
840
  }
813
841
  }
814
842
  }
815
- // 5. regular hook
843
+ // 6. regular hook
816
844
  const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
817
845
  if (maybe_hook !== undefined) {
818
846
  if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined }) === false) {
819
847
  return false;
820
848
  }
821
849
  }
822
- // 6. edge type hook
850
+ // 7. edge type hook
823
851
  // not yet implemented
824
- // 7. entry hook
852
+ // 8. entry hook
825
853
  const maybe_en_hook = this._entry_hooks.get(newState);
826
854
  if (maybe_en_hook !== undefined) {
827
855
  if (maybe_en_hook({ to: newState, forced: wasForced }) === false) {
@@ -166,6 +166,15 @@ declare type AnyTransitionHook = {
166
166
  kind: 'any transition';
167
167
  handler: HookHandler;
168
168
  };
169
+ declare type GlobalActionHook = {
170
+ kind: 'global action';
171
+ action: string;
172
+ handler: HookHandler;
173
+ };
174
+ declare type AnyActionHook = {
175
+ kind: 'any action';
176
+ handler: HookHandler;
177
+ };
169
178
  declare type EntryHook = {
170
179
  kind: 'entry';
171
180
  to: string;
@@ -176,5 +185,5 @@ declare type ExitHook = {
176
185
  from: string;
177
186
  handler: HookHandler;
178
187
  };
179
- declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | AnyTransitionHook | EntryHook | ExitHook;
188
+ declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | GlobalActionHook | AnyActionHook | AnyTransitionHook | EntryHook | ExitHook;
180
189
  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 };
@@ -1,2 +1,2 @@
1
- const version = "5.57.1";
1
+ const version = "5.59.0";
2
2
  export { version };