jssm 5.50.0 → 5.51.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.
@@ -96,8 +96,8 @@ declare class Machine<mDT> {
96
96
  hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
97
97
  hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
98
98
  hook_any_transition(handler: HookHandler): Machine<mDT>;
99
- action(name: StateType, newData?: mDT): boolean;
100
- transition_impl(newState: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
99
+ transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
100
+ action(actionName: StateType, newData?: mDT): boolean;
101
101
  transition(newState: StateType, newData?: mDT): boolean;
102
102
  force_transition(newState: StateType, newData?: mDT): boolean;
103
103
  current_action_for(action: StateType): number;
package/dist/es6/jssm.js CHANGED
@@ -746,53 +746,25 @@ class Machine {
746
746
  // remove_hook(HookDesc: HookDescription) {
747
747
  // throw 'TODO: Should remove hook here';
748
748
  // }
749
- action(name, newData) {
750
- // todo whargarbl implement hooks
751
- // todo whargarbl implement data stuff
752
- // todo major incomplete whargarbl comeback
753
- if (this.valid_action(name, newData)) {
754
- const edge = this.current_action_edge_for(name);
755
- if (this._has_hooks) {
756
- let hook_permits = undefined;
757
- if (this._any_transition_hook !== undefined) {
758
- if (this._any_transition_hook() === false) {
759
- return false;
760
- }
761
- }
762
- const nhn = named_hook_name(this._state, edge.to, name), maybe_hook = this._named_hooks.get(nhn);
763
- if (maybe_hook === undefined) {
764
- hook_permits = true;
765
- }
766
- else {
767
- hook_permits = maybe_hook({ from: this._state, to: edge.to, action: name });
768
- }
769
- if (hook_permits !== false) {
770
- this._state = edge.to;
771
- return true;
772
- }
773
- else {
774
- return false;
775
- }
776
- }
777
- else {
778
- this._state = edge.to;
779
- return true;
749
+ transition_impl(newStateOrAction, newData, wasForced, wasAction) {
750
+ let valid = false, newState;
751
+ if (wasForced) {
752
+ if (this.valid_force_transition(newStateOrAction, newData)) {
753
+ valid = true;
754
+ newState = newStateOrAction;
780
755
  }
781
756
  }
782
- else {
783
- return false;
784
- }
785
- }
786
- transition_impl(newState, newData, wasForced, wasAction) {
787
- let valid = false;
788
- if (wasForced) {
789
- if (this.valid_force_transition(newState, newData)) {
757
+ else if (wasAction) {
758
+ if (this.valid_action(newStateOrAction, newData)) {
759
+ const edge = this.current_action_edge_for(newStateOrAction);
790
760
  valid = true;
761
+ newState = edge.to;
791
762
  }
792
763
  }
793
764
  else {
794
- if (this.valid_transition(newState, newData)) {
765
+ if (this.valid_transition(newStateOrAction, newData)) {
795
766
  valid = true;
767
+ newState = newStateOrAction;
796
768
  }
797
769
  }
798
770
  // todo whargarbl implement data stuff
@@ -805,12 +777,24 @@ class Machine {
805
777
  return false;
806
778
  }
807
779
  }
780
+ if (wasAction) {
781
+ const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
782
+ if (n_maybe_hook === undefined) {
783
+ hook_permits = true;
784
+ }
785
+ else {
786
+ hook_permits = n_maybe_hook({ from: this._state, to: newState, action: newStateOrAction });
787
+ }
788
+ if (!(hook_permits)) {
789
+ return false;
790
+ }
791
+ }
808
792
  const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
809
793
  if (maybe_hook === undefined) {
810
794
  hook_permits = true;
811
795
  }
812
796
  else {
813
- hook_permits = maybe_hook({ from: this._state, to: newState, forced: wasForced });
797
+ hook_permits = maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined });
814
798
  }
815
799
  if (hook_permits !== false) {
816
800
  this._state = newState;
@@ -829,6 +813,9 @@ class Machine {
829
813
  return false;
830
814
  }
831
815
  }
816
+ action(actionName, newData) {
817
+ return this.transition_impl(actionName, newData, false, true);
818
+ }
832
819
  transition(newState, newData) {
833
820
  return this.transition_impl(newState, newData, false, false);
834
821
  }
@@ -1,2 +1,2 @@
1
- const version = "5.50.0";
1
+ const version = "5.51.0";
2
2
  export { version };