jssm 5.60.3 → 5.61.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.
@@ -42,6 +42,8 @@ declare class Machine<mDT> {
42
42
  _has_named_hooks: boolean;
43
43
  _has_entry_hooks: boolean;
44
44
  _has_exit_hooks: boolean;
45
+ _has_global_action_hooks: boolean;
46
+ _has_transition_hooks: boolean;
45
47
  _hooks: Map<string, Function>;
46
48
  _named_hooks: Map<string, Function>;
47
49
  _entry_hooks: Map<string, Function>;
@@ -106,6 +108,9 @@ declare class Machine<mDT> {
106
108
  hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
107
109
  hook_global_action(action: string, handler: HookHandler): Machine<mDT>;
108
110
  hook_any_action(handler: HookHandler): Machine<mDT>;
111
+ hook_standard_transition(handler: HookHandler): Machine<mDT>;
112
+ hook_main_transition(handler: HookHandler): Machine<mDT>;
113
+ hook_forced_transition(handler: HookHandler): Machine<mDT>;
109
114
  hook_any_transition(handler: HookHandler): Machine<mDT>;
110
115
  hook_entry(to: string, handler: HookHandler): Machine<mDT>;
111
116
  hook_exit(from: string, handler: HookHandler): Machine<mDT>;
package/dist/es6/jssm.js CHANGED
@@ -350,6 +350,8 @@ class Machine {
350
350
  this._has_named_hooks = false;
351
351
  this._has_entry_hooks = false;
352
352
  this._has_exit_hooks = false;
353
+ this._has_global_action_hooks = false;
354
+ this._has_transition_hooks = true;
353
355
  // no need for a boolean has any transition hook, as it's one or nothing, so just test that for undefinedness
354
356
  this._hooks = new Map();
355
357
  this._named_hooks = new Map();
@@ -719,14 +721,17 @@ class Machine {
719
721
  case 'hook':
720
722
  this._hooks.set(hook_name(HookDesc.from, HookDesc.to), HookDesc.handler);
721
723
  this._has_hooks = true;
724
+ this._has_basic_hooks = true;
722
725
  break;
723
726
  case 'named':
724
727
  this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
725
728
  this._has_hooks = true;
729
+ this._has_named_hooks = true;
726
730
  break;
727
731
  case 'global action':
728
732
  this._global_action_hooks.set(HookDesc.action, HookDesc.handler);
729
733
  this._has_hooks = true;
734
+ this._has_global_action_hooks = true;
730
735
  break;
731
736
  case 'any action':
732
737
  this._any_action_hook = HookDesc.handler;
@@ -734,14 +739,17 @@ class Machine {
734
739
  break;
735
740
  case 'standard transition':
736
741
  this._standard_transition_hook = HookDesc.handler;
742
+ this._has_transition_hooks = true;
737
743
  this._has_hooks = true;
738
744
  break;
739
745
  case 'main transition':
740
746
  this._main_transition_hook = HookDesc.handler;
747
+ this._has_transition_hooks = true;
741
748
  this._has_hooks = true;
742
749
  break;
743
750
  case 'forced transition':
744
751
  this._forced_transition_hook = HookDesc.handler;
752
+ this._has_transition_hooks = true;
745
753
  this._has_hooks = true;
746
754
  break;
747
755
  case 'any transition':
@@ -751,10 +759,12 @@ class Machine {
751
759
  case 'entry':
752
760
  this._entry_hooks.set(HookDesc.to, HookDesc.handler);
753
761
  this._has_hooks = true;
762
+ this._has_entry_hooks = true;
754
763
  break;
755
764
  case 'exit':
756
765
  this._exit_hooks.set(HookDesc.from, HookDesc.handler);
757
766
  this._has_hooks = true;
767
+ this._has_exit_hooks = true;
758
768
  break;
759
769
  default:
760
770
  console.log(`Unknown hook type ${HookDesc.kind}, should be impossible`);
@@ -781,6 +791,21 @@ class Machine {
781
791
  this.set_hook({ kind: 'any action', handler });
782
792
  return this;
783
793
  }
794
+ hook_standard_transition(handler) {
795
+ // TODO: should this throw if setting the hook fails, or ignore it and continue?
796
+ this.set_hook({ kind: 'standard transition', handler });
797
+ return this;
798
+ }
799
+ hook_main_transition(handler) {
800
+ // TODO: should this throw if setting the hook fails, or ignore it and continue?
801
+ this.set_hook({ kind: 'main transition', handler });
802
+ return this;
803
+ }
804
+ hook_forced_transition(handler) {
805
+ // TODO: should this throw if setting the hook fails, or ignore it and continue?
806
+ this.set_hook({ kind: 'forced transition', handler });
807
+ return this;
808
+ }
784
809
  hook_any_transition(handler) {
785
810
  // TODO: should this throw if setting the hook fails, or ignore it and continue?
786
811
  this.set_hook({ kind: 'any transition', handler });
@@ -823,8 +848,10 @@ class Machine {
823
848
  }
824
849
  else {
825
850
  if (this.valid_transition(newStateOrAction, newData)) {
851
+ if (this._has_transition_hooks) {
852
+ trans_type = this.edges_between(this._state, newStateOrAction)[0].kind; // TODO this won't do the right thing if various edges have different types
853
+ }
826
854
  valid = true;
827
- trans_type = this.edges_between(this._state, newStateOrAction)[0].kind; // TODO this won't do the right thing if various edges have different types
828
855
  newState = newStateOrAction;
829
856
  }
830
857
  }
@@ -854,26 +881,32 @@ class Machine {
854
881
  }
855
882
  }
856
883
  // 4. exit hook
857
- const maybe_ex_hook = this._exit_hooks.get(this._state);
858
- if (maybe_ex_hook !== undefined) {
859
- if (maybe_ex_hook({ from: this._state, forced: wasForced }) === false) {
860
- return false;
884
+ if (this._has_exit_hooks) {
885
+ const maybe_ex_hook = this._exit_hooks.get(this._state);
886
+ if (maybe_ex_hook !== undefined) {
887
+ if (maybe_ex_hook({ from: this._state, forced: wasForced }) === false) {
888
+ return false;
889
+ }
861
890
  }
862
891
  }
863
892
  // 5. named transition / action hook
864
- if (wasAction) {
865
- const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
866
- if (n_maybe_hook !== undefined) {
867
- if (n_maybe_hook({ from: this._state, to: newState, action: newStateOrAction }) === false) {
868
- return false;
893
+ if (this._has_named_hooks) {
894
+ if (wasAction) {
895
+ const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
896
+ if (n_maybe_hook !== undefined) {
897
+ if (n_maybe_hook({ from: this._state, to: newState, action: newStateOrAction }) === false) {
898
+ return false;
899
+ }
869
900
  }
870
901
  }
871
902
  }
872
903
  // 6. regular hook
873
- const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
874
- if (maybe_hook !== undefined) {
875
- if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined }) === false) {
876
- return false;
904
+ if (this._has_basic_hooks) {
905
+ const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
906
+ if (maybe_hook !== undefined) {
907
+ if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined }) === false) {
908
+ return false;
909
+ }
877
910
  }
878
911
  }
879
912
  // 7. edge type hook
@@ -908,10 +941,12 @@ class Machine {
908
941
  }
909
942
  }
910
943
  // 8. entry hook
911
- const maybe_en_hook = this._entry_hooks.get(newState);
912
- if (maybe_en_hook !== undefined) {
913
- if (maybe_en_hook({ to: newState, forced: wasForced }) === false) {
914
- return false;
944
+ if (this._has_entry_hooks) {
945
+ const maybe_en_hook = this._entry_hooks.get(newState);
946
+ if (maybe_en_hook !== undefined) {
947
+ if (maybe_en_hook({ to: newState, forced: wasForced }) === false) {
948
+ return false;
949
+ }
915
950
  }
916
951
  }
917
952
  this._state = newState;
@@ -164,20 +164,14 @@ declare type HookDescriptionWithAction = {
164
164
  };
165
165
  declare type StandardTransitionHook = {
166
166
  kind: 'standard transition';
167
- from: string;
168
- to: string;
169
167
  handler: HookHandler;
170
168
  };
171
169
  declare type MainTransitionHook = {
172
170
  kind: 'main transition';
173
- from: string;
174
- to: string;
175
171
  handler: HookHandler;
176
172
  };
177
173
  declare type ForcedTransitionHook = {
178
174
  kind: 'forced transition';
179
- from: string;
180
- to: string;
181
175
  handler: HookHandler;
182
176
  };
183
177
  declare type AnyTransitionHook = {
@@ -1,2 +1,2 @@
1
- const version = "5.60.3";
1
+ const version = "5.61.2";
2
2
  export { version };