jssm 5.58.0 → 5.59.1

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,7 @@ 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>;
49
50
  _any_action_hook: HookHandler | undefined;
50
51
  _any_transition_hook: HookHandler | undefined;
51
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>);
@@ -100,6 +101,8 @@ declare class Machine<mDT> {
100
101
  set_hook(HookDesc: HookDescription): void;
101
102
  hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
102
103
  hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
104
+ hook_global_action(action: string, handler: HookHandler): Machine<mDT>;
105
+ hook_any_action(handler: HookHandler): Machine<mDT>;
103
106
  hook_any_transition(handler: HookHandler): Machine<mDT>;
104
107
  hook_entry(to: string, handler: HookHandler): Machine<mDT>;
105
108
  hook_exit(from: string, handler: HookHandler): Machine<mDT>;
package/dist/es6/jssm.js CHANGED
@@ -355,6 +355,7 @@ 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();
358
359
  this._any_action_hook = undefined;
359
360
  this._any_transition_hook = undefined;
360
361
  if (state_declaration) {
@@ -719,6 +720,10 @@ class Machine {
719
720
  this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
720
721
  this._has_hooks = true;
721
722
  break;
723
+ case 'global action':
724
+ this._global_action_hooks.set(HookDesc.action, HookDesc.handler);
725
+ this._has_hooks = true;
726
+ break;
722
727
  case 'any action':
723
728
  this._any_action_hook = HookDesc.handler;
724
729
  this._has_hooks = true;
@@ -750,6 +755,16 @@ class Machine {
750
755
  this.set_hook({ kind: 'named', from, to, action, handler });
751
756
  return this;
752
757
  }
758
+ hook_global_action(action, handler) {
759
+ // TODO: should this throw if setting the hook fails, or ignore it and continue?
760
+ this.set_hook({ kind: 'global action', action, handler });
761
+ return this;
762
+ }
763
+ hook_any_action(handler) {
764
+ // TODO: should this throw if setting the hook fails, or ignore it and continue?
765
+ this.set_hook({ kind: 'any action', handler });
766
+ return this;
767
+ }
753
768
  hook_any_transition(handler) {
754
769
  // TODO: should this throw if setting the hook fails, or ignore it and continue?
755
770
  this.set_hook({ kind: 'any transition', handler });
@@ -793,16 +808,21 @@ class Machine {
793
808
  // todo major incomplete whargarbl comeback
794
809
  if (valid) {
795
810
  if (this._has_hooks) {
796
- // 1. any action hook
797
811
  if (wasAction) {
812
+ // 1. any action hook
798
813
  if (this._any_action_hook !== undefined) {
799
814
  if (this._any_action_hook() === false) {
800
815
  return false;
801
816
  }
802
817
  }
818
+ // 2. global specific action hook
819
+ const maybe_ga_hook = this._global_action_hooks.get(newStateOrAction);
820
+ if (maybe_ga_hook !== undefined) {
821
+ if (maybe_ga_hook({ action: newStateOrAction, forced: wasForced }) === false) {
822
+ return false;
823
+ }
824
+ }
803
825
  }
804
- // 2. global specific action hook
805
- // not yet implemented
806
826
  // 3. any transition hook
807
827
  if (this._any_transition_hook !== undefined) {
808
828
  if (this._any_transition_hook() === false) {
@@ -166,6 +166,11 @@ 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
+ };
169
174
  declare type AnyActionHook = {
170
175
  kind: 'any action';
171
176
  handler: HookHandler;
@@ -180,5 +185,5 @@ declare type ExitHook = {
180
185
  from: string;
181
186
  handler: HookHandler;
182
187
  };
183
- declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | AnyActionHook | AnyTransitionHook | EntryHook | ExitHook;
188
+ declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | GlobalActionHook | AnyActionHook | AnyTransitionHook | EntryHook | ExitHook;
184
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.58.0";
1
+ const version = "5.59.1";
2
2
  export { version };