jssm 5.46.0 → 5.49.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.
- package/dist/es6/jssm.d.ts +5 -0
- package/dist/es6/jssm.js +37 -6
- package/dist/es6/jssm_types.d.ts +5 -1
- package/dist/es6/version.js +1 -1
- package/dist/jssm.es5.cjs.js +1 -1
- package/dist/jssm.es5.iife.js +1 -0
- package/jssm.d.ts +5 -0
- package/jssm_types.d.ts +5 -1
- package/package.json +1 -1
package/dist/es6/jssm.d.ts
CHANGED
|
@@ -38,8 +38,11 @@ declare class Machine<mDT> {
|
|
|
38
38
|
_theme: FslTheme;
|
|
39
39
|
_flow: FslDirection;
|
|
40
40
|
_has_hooks: boolean;
|
|
41
|
+
_has_basic_hooks: boolean;
|
|
42
|
+
_has_named_hooks: boolean;
|
|
41
43
|
_hooks: Map<string, Function>;
|
|
42
44
|
_named_hooks: Map<string, Function>;
|
|
45
|
+
_any_transition_hook: HookHandler | undefined;
|
|
43
46
|
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>);
|
|
44
47
|
_new_state(state_config: JssmGenericState): StateType;
|
|
45
48
|
state(): StateType;
|
|
@@ -91,6 +94,8 @@ declare class Machine<mDT> {
|
|
|
91
94
|
has_completes(): boolean;
|
|
92
95
|
set_hook(HookDesc: HookDescription): void;
|
|
93
96
|
hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
|
|
97
|
+
hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
|
|
98
|
+
hook_any_transition(handler: HookHandler): Machine<mDT>;
|
|
94
99
|
action(name: StateType, newData?: mDT): boolean;
|
|
95
100
|
transition(newState: StateType, newData?: mDT): boolean;
|
|
96
101
|
force_transition(newState: StateType, newData?: mDT): boolean;
|
package/dist/es6/jssm.js
CHANGED
|
@@ -152,13 +152,13 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
|
|
|
152
152
|
// if ((wasIndex !== undefined) && (wasList === undefined)) { throw new TypeError("Must be in a list if transition has an index"); }
|
|
153
153
|
/*
|
|
154
154
|
if (typeof edge.to === 'object') {
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
if (edge.to.key === 'cycle') {
|
|
157
157
|
if (wasList === undefined) { throw "Must have a waslist if a to is type cycle"; }
|
|
158
158
|
const nextIndex = wrapBy(wasIndex, edge.to.value, wasList.length);
|
|
159
159
|
edge.to = wasList[nextIndex];
|
|
160
160
|
}
|
|
161
|
-
|
|
161
|
+
|
|
162
162
|
}
|
|
163
163
|
*/
|
|
164
164
|
const action = isRight ? 'r_action' : 'l_action', probability = isRight ? 'r_probability' : 'l_probability';
|
|
@@ -346,8 +346,11 @@ class Machine {
|
|
|
346
346
|
this._flow = flow;
|
|
347
347
|
this._graph_layout = graph_layout;
|
|
348
348
|
this._has_hooks = false;
|
|
349
|
+
this._has_basic_hooks = false;
|
|
350
|
+
this._has_named_hooks = false;
|
|
349
351
|
this._hooks = new Map();
|
|
350
352
|
this._named_hooks = new Map();
|
|
353
|
+
this._any_transition_hook = undefined;
|
|
351
354
|
if (state_declaration) {
|
|
352
355
|
state_declaration.map((state_decl) => {
|
|
353
356
|
if (this._state_declarations.has(state_decl.state)) { // no repeats
|
|
@@ -456,7 +459,7 @@ class Machine {
|
|
|
456
459
|
}
|
|
457
460
|
/* whargarbl todo major
|
|
458
461
|
when we reimplement this, reintroduce this change to the is_final call
|
|
459
|
-
|
|
462
|
+
|
|
460
463
|
is_changing(): boolean {
|
|
461
464
|
return true; // todo whargarbl
|
|
462
465
|
}
|
|
@@ -655,7 +658,8 @@ class Machine {
|
|
|
655
658
|
return Array.from(ra_base.values())
|
|
656
659
|
.map((edgeId) => this._edges[edgeId])
|
|
657
660
|
.filter((o) => o.from === whichState)
|
|
658
|
-
.map((filtered) => ({
|
|
661
|
+
.map((filtered) => ({
|
|
662
|
+
action: filtered.action,
|
|
659
663
|
probability: filtered.probability
|
|
660
664
|
}));
|
|
661
665
|
}
|
|
@@ -709,6 +713,10 @@ class Machine {
|
|
|
709
713
|
this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
|
|
710
714
|
this._has_hooks = true;
|
|
711
715
|
break;
|
|
716
|
+
case 'any transition':
|
|
717
|
+
this._any_transition_hook = HookDesc.handler;
|
|
718
|
+
this._has_hooks = true;
|
|
719
|
+
break;
|
|
712
720
|
// case 'entry':
|
|
713
721
|
// console.log('TODO: Should add entry hook here');
|
|
714
722
|
// throw 'TODO: Should add entry hook here';
|
|
@@ -725,6 +733,16 @@ class Machine {
|
|
|
725
733
|
this.set_hook({ kind: 'hook', from, to, handler });
|
|
726
734
|
return this;
|
|
727
735
|
}
|
|
736
|
+
hook_action(from, to, action, handler) {
|
|
737
|
+
// TODO: should this throw if setting the hook fails, or ignore it and continue?
|
|
738
|
+
this.set_hook({ kind: 'named', from, to, action, handler });
|
|
739
|
+
return this;
|
|
740
|
+
}
|
|
741
|
+
hook_any_transition(handler) {
|
|
742
|
+
// TODO: should this throw if setting the hook fails, or ignore it and continue?
|
|
743
|
+
this.set_hook({ kind: 'any transition', handler });
|
|
744
|
+
return this;
|
|
745
|
+
}
|
|
728
746
|
// remove_hook(HookDesc: HookDescription) {
|
|
729
747
|
// throw 'TODO: Should remove hook here';
|
|
730
748
|
// }
|
|
@@ -736,6 +754,11 @@ class Machine {
|
|
|
736
754
|
const edge = this.current_action_edge_for(name);
|
|
737
755
|
if (this._has_hooks) {
|
|
738
756
|
let hook_permits = undefined;
|
|
757
|
+
if (this._any_transition_hook !== undefined) {
|
|
758
|
+
if (this._any_transition_hook() === false) {
|
|
759
|
+
return false;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
739
762
|
const nhn = named_hook_name(this._state, edge.to, name), maybe_hook = this._named_hooks.get(nhn);
|
|
740
763
|
if (maybe_hook === undefined) {
|
|
741
764
|
hook_permits = true;
|
|
@@ -761,12 +784,16 @@ class Machine {
|
|
|
761
784
|
}
|
|
762
785
|
}
|
|
763
786
|
transition(newState, newData) {
|
|
764
|
-
// todo whargarbl implement hooks
|
|
765
787
|
// todo whargarbl implement data stuff
|
|
766
788
|
// todo major incomplete whargarbl comeback
|
|
767
789
|
if (this.valid_transition(newState, newData)) {
|
|
768
790
|
if (this._has_hooks) {
|
|
769
791
|
let hook_permits = undefined;
|
|
792
|
+
if (this._any_transition_hook !== undefined) {
|
|
793
|
+
if (this._any_transition_hook() === false) {
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
770
797
|
const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
|
|
771
798
|
if (maybe_hook === undefined) {
|
|
772
799
|
hook_permits = true;
|
|
@@ -793,12 +820,16 @@ class Machine {
|
|
|
793
820
|
}
|
|
794
821
|
// can leave machine in inconsistent state. generally do not use
|
|
795
822
|
force_transition(newState, newData) {
|
|
796
|
-
// todo whargarbl implement hooks
|
|
797
823
|
// todo whargarbl implement data stuff
|
|
798
824
|
// todo major incomplete whargarbl comeback
|
|
799
825
|
if (this.valid_force_transition(newState, newData)) {
|
|
800
826
|
if (this._has_hooks) {
|
|
801
827
|
let hook_permits = undefined;
|
|
828
|
+
if (this._any_transition_hook !== undefined) {
|
|
829
|
+
if (this._any_transition_hook() === false) {
|
|
830
|
+
return false;
|
|
831
|
+
}
|
|
832
|
+
}
|
|
802
833
|
const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
|
|
803
834
|
if (maybe_hook === undefined) {
|
|
804
835
|
hook_permits = true;
|
package/dist/es6/jssm_types.d.ts
CHANGED
|
@@ -162,6 +162,10 @@ declare type HookDescriptionWithAction = {
|
|
|
162
162
|
action: string;
|
|
163
163
|
handler: HookHandler;
|
|
164
164
|
};
|
|
165
|
+
declare type AnyTransitionHook = {
|
|
166
|
+
kind: 'any transition';
|
|
167
|
+
handler: HookHandler;
|
|
168
|
+
};
|
|
165
169
|
declare type EntryHook = {
|
|
166
170
|
kind: 'entry';
|
|
167
171
|
to: string;
|
|
@@ -172,5 +176,5 @@ declare type ExitHook = {
|
|
|
172
176
|
from: string;
|
|
173
177
|
handler: HookHandler;
|
|
174
178
|
};
|
|
175
|
-
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | EntryHook | ExitHook;
|
|
179
|
+
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | AnyTransitionHook | EntryHook | ExitHook;
|
|
176
180
|
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 };
|
package/dist/es6/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const version = "5.
|
|
1
|
+
const version = "5.49.0";
|
|
2
2
|
export { version };
|