jssm 5.59.0 → 5.60.3

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.
@@ -48,6 +48,9 @@ declare class Machine<mDT> {
48
48
  _exit_hooks: Map<string, Function>;
49
49
  _global_action_hooks: Map<string, Function>;
50
50
  _any_action_hook: HookHandler | undefined;
51
+ _standard_transition_hook: HookHandler | undefined;
52
+ _main_transition_hook: HookHandler | undefined;
53
+ _forced_transition_hook: HookHandler | undefined;
51
54
  _any_transition_hook: HookHandler | undefined;
52
55
  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>);
53
56
  _new_state(state_config: JssmGenericState): StateType;
@@ -101,10 +104,12 @@ declare class Machine<mDT> {
101
104
  set_hook(HookDesc: HookDescription): void;
102
105
  hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
103
106
  hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
107
+ hook_global_action(action: string, handler: HookHandler): Machine<mDT>;
104
108
  hook_any_action(handler: HookHandler): Machine<mDT>;
105
109
  hook_any_transition(handler: HookHandler): Machine<mDT>;
106
110
  hook_entry(to: string, handler: HookHandler): Machine<mDT>;
107
111
  hook_exit(from: string, handler: HookHandler): Machine<mDT>;
112
+ edges_between(from: string, to: string): JssmTransition<mDT>[];
108
113
  transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
109
114
  action(actionName: StateType, newData?: mDT): boolean;
110
115
  transition(newState: StateType, newData?: mDT): boolean;
package/dist/es6/jssm.js CHANGED
@@ -357,7 +357,11 @@ class Machine {
357
357
  this._exit_hooks = new Map();
358
358
  this._global_action_hooks = new Map();
359
359
  this._any_action_hook = undefined;
360
+ this._standard_transition_hook = undefined;
361
+ this._main_transition_hook = undefined;
362
+ this._forced_transition_hook = undefined;
360
363
  this._any_transition_hook = undefined;
364
+ this._standard_transition_hook = undefined;
361
365
  if (state_declaration) {
362
366
  state_declaration.map((state_decl) => {
363
367
  if (this._state_declarations.has(state_decl.state)) { // no repeats
@@ -728,6 +732,18 @@ class Machine {
728
732
  this._any_action_hook = HookDesc.handler;
729
733
  this._has_hooks = true;
730
734
  break;
735
+ case 'standard transition':
736
+ this._standard_transition_hook = HookDesc.handler;
737
+ this._has_hooks = true;
738
+ break;
739
+ case 'main transition':
740
+ this._main_transition_hook = HookDesc.handler;
741
+ this._has_hooks = true;
742
+ break;
743
+ case 'forced transition':
744
+ this._forced_transition_hook = HookDesc.handler;
745
+ this._has_hooks = true;
746
+ break;
731
747
  case 'any transition':
732
748
  this._any_transition_hook = HookDesc.handler;
733
749
  this._has_hooks = true;
@@ -755,6 +771,11 @@ class Machine {
755
771
  this.set_hook({ kind: 'named', from, to, action, handler });
756
772
  return this;
757
773
  }
774
+ hook_global_action(action, handler) {
775
+ // TODO: should this throw if setting the hook fails, or ignore it and continue?
776
+ this.set_hook({ kind: 'global action', action, handler });
777
+ return this;
778
+ }
758
779
  hook_any_action(handler) {
759
780
  // TODO: should this throw if setting the hook fails, or ignore it and continue?
760
781
  this.set_hook({ kind: 'any action', handler });
@@ -778,11 +799,17 @@ class Machine {
778
799
  // remove_hook(HookDesc: HookDescription) {
779
800
  // throw 'TODO: Should remove hook here';
780
801
  // }
802
+ edges_between(from, to) {
803
+ return this._edges.filter(edge => ((edge.from === from) && (edge.to === to)));
804
+ }
781
805
  transition_impl(newStateOrAction, newData, wasForced, wasAction) {
782
- let valid = false, newState;
806
+ // TODO the forced-ness behavior needs to be cleaned up a lot here
807
+ // TODO all the callbacks are wrong on forced, action, etc
808
+ let valid = false, trans_type, newState;
783
809
  if (wasForced) {
784
810
  if (this.valid_force_transition(newStateOrAction, newData)) {
785
811
  valid = true;
812
+ trans_type = 'forced';
786
813
  newState = newStateOrAction;
787
814
  }
788
815
  }
@@ -790,12 +817,14 @@ class Machine {
790
817
  if (this.valid_action(newStateOrAction, newData)) {
791
818
  const edge = this.current_action_edge_for(newStateOrAction);
792
819
  valid = true;
820
+ trans_type = edge.kind;
793
821
  newState = edge.to;
794
822
  }
795
823
  }
796
824
  else {
797
825
  if (this.valid_transition(newStateOrAction, newData)) {
798
826
  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
799
828
  newState = newStateOrAction;
800
829
  }
801
830
  }
@@ -848,7 +877,36 @@ class Machine {
848
877
  }
849
878
  }
850
879
  // 7. edge type hook
851
- // not yet implemented
880
+ // 7a. standard transition hook
881
+ if (trans_type === 'legal') {
882
+ if (this._standard_transition_hook !== undefined) {
883
+ // todo handle actions
884
+ // todo handle forced
885
+ if (this._standard_transition_hook({ from: this._state, to: newState }) === false) {
886
+ return false;
887
+ }
888
+ }
889
+ }
890
+ // 7b. main type hook
891
+ if (trans_type === 'main') {
892
+ if (this._main_transition_hook !== undefined) {
893
+ // todo handle actions
894
+ // todo handle forced
895
+ if (this._main_transition_hook({ from: this._state, to: newState }) === false) {
896
+ return false;
897
+ }
898
+ }
899
+ }
900
+ // 7c. forced transition hook
901
+ if (trans_type === 'forced') {
902
+ if (this._forced_transition_hook !== undefined) {
903
+ // todo handle actions
904
+ // todo handle forced
905
+ if (this._forced_transition_hook({ from: this._state, to: newState }) === false) {
906
+ return false;
907
+ }
908
+ }
909
+ }
852
910
  // 8. entry hook
853
911
  const maybe_en_hook = this._entry_hooks.get(newState);
854
912
  if (maybe_en_hook !== undefined) {
@@ -162,6 +162,24 @@ declare type HookDescriptionWithAction = {
162
162
  action: string;
163
163
  handler: HookHandler;
164
164
  };
165
+ declare type StandardTransitionHook = {
166
+ kind: 'standard transition';
167
+ from: string;
168
+ to: string;
169
+ handler: HookHandler;
170
+ };
171
+ declare type MainTransitionHook = {
172
+ kind: 'main transition';
173
+ from: string;
174
+ to: string;
175
+ handler: HookHandler;
176
+ };
177
+ declare type ForcedTransitionHook = {
178
+ kind: 'forced transition';
179
+ from: string;
180
+ to: string;
181
+ handler: HookHandler;
182
+ };
165
183
  declare type AnyTransitionHook = {
166
184
  kind: 'any transition';
167
185
  handler: HookHandler;
@@ -185,5 +203,5 @@ declare type ExitHook = {
185
203
  from: string;
186
204
  handler: HookHandler;
187
205
  };
188
- declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | GlobalActionHook | AnyActionHook | AnyTransitionHook | EntryHook | ExitHook;
206
+ declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | GlobalActionHook | AnyActionHook | StandardTransitionHook | MainTransitionHook | ForcedTransitionHook | AnyTransitionHook | EntryHook | ExitHook;
189
207
  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.59.0";
1
+ const version = "5.60.3";
2
2
  export { version };