jssm 5.61.1 → 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>;
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`);
@@ -838,8 +848,10 @@ class Machine {
838
848
  }
839
849
  else {
840
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
+ }
841
854
  valid = true;
842
- trans_type = this.edges_between(this._state, newStateOrAction)[0].kind; // TODO this won't do the right thing if various edges have different types
843
855
  newState = newStateOrAction;
844
856
  }
845
857
  }
@@ -869,26 +881,32 @@ class Machine {
869
881
  }
870
882
  }
871
883
  // 4. exit hook
872
- const maybe_ex_hook = this._exit_hooks.get(this._state);
873
- if (maybe_ex_hook !== undefined) {
874
- if (maybe_ex_hook({ from: this._state, forced: wasForced }) === false) {
875
- 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
+ }
876
890
  }
877
891
  }
878
892
  // 5. named transition / action hook
879
- if (wasAction) {
880
- const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
881
- if (n_maybe_hook !== undefined) {
882
- if (n_maybe_hook({ from: this._state, to: newState, action: newStateOrAction }) === false) {
883
- 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
+ }
884
900
  }
885
901
  }
886
902
  }
887
903
  // 6. regular hook
888
- const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
889
- if (maybe_hook !== undefined) {
890
- if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined }) === false) {
891
- 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
+ }
892
910
  }
893
911
  }
894
912
  // 7. edge type hook
@@ -923,10 +941,12 @@ class Machine {
923
941
  }
924
942
  }
925
943
  // 8. entry hook
926
- const maybe_en_hook = this._entry_hooks.get(newState);
927
- if (maybe_en_hook !== undefined) {
928
- if (maybe_en_hook({ to: newState, forced: wasForced }) === false) {
929
- 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
+ }
930
950
  }
931
951
  }
932
952
  this._state = newState;
@@ -1,2 +1,2 @@
1
- const version = "5.61.1";
1
+ const version = "5.61.2";
2
2
  export { version };