Skip to content

Commit

Permalink
Merge branch 'main' into FmtAndCleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed May 12, 2022
2 parents 7c6fff9 + 5f75d87 commit 56e3433
Show file tree
Hide file tree
Showing 20 changed files with 343 additions and 63 deletions.
14 changes: 7 additions & 7 deletions benchmark/results/general.chart.html
Expand Up @@ -28,7 +28,7 @@
</head>
<body>
<div class="container">
<canvas id="chart1652115720275" width="16" height="9"></canvas>
<canvas id="chart1652377906624" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -51,18 +51,18 @@
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
)
}
const ctx1652115720275 = document
.getElementById('chart1652115720275')
const ctx1652377906624 = document
.getElementById('chart1652377906624')
.getContext('2d')
const chart1652115720275 = new Chart(ctx1652115720275, {
const chart1652377906624 = new Chart(ctx1652377906624, {
type: 'bar',
data: {
labels: ["Blind cycle a traffic light 500 times by transition","Blind cycle a hooked traffic light 500 times by transition","Blind cycle a traffic light 500 times by action","Blind cycle a hooked traffic light 500 times by action"],
datasets: [
{
data: [19229,1609,13038,795],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(10.044000000000006, 85%, 55%)","hsl(81.35999999999999, 85%, 55%)","hsl(4.955999999999994, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(10.044000000000006, 85%, 55%)","hsl(81.35999999999999, 85%, 55%)","hsl(4.955999999999994, 85%, 55%)"],
data: [18712,1544,13380,818],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(9.9, 85%, 55%)","hsl(85.8, 85%, 55%)","hsl(5.244000000000005, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(9.9, 85%, 55%)","hsl(85.8, 85%, 55%)","hsl(5.244000000000005, 85%, 55%)"],
borderWidth: 2,
},
],
Expand Down
24 changes: 12 additions & 12 deletions benchmark/results/general.json
@@ -1,31 +1,31 @@
{
"name": "General performance suite",
"date": "2022-05-09T17:02:00.275Z",
"date": "2022-05-12T17:51:46.624Z",
"version": "1.1.0",
"results": [
{
"name": "Blind cycle a traffic light 500 times by transition",
"ops": 19229,
"margin": 1.37,
"ops": 18712,
"margin": 3.67,
"percentSlower": 0
},
{
"name": "Blind cycle a hooked traffic light 500 times by transition",
"ops": 1609,
"margin": 3.02,
"percentSlower": 91.63
"ops": 1544,
"margin": 4.11,
"percentSlower": 91.75
},
{
"name": "Blind cycle a traffic light 500 times by action",
"ops": 13038,
"margin": 8.4,
"percentSlower": 32.2
"ops": 13380,
"margin": 0.92,
"percentSlower": 28.5
},
{
"name": "Blind cycle a hooked traffic light 500 times by action",
"ops": 795,
"margin": 2.86,
"percentSlower": 95.87
"ops": 818,
"margin": 0.8,
"percentSlower": 95.63
}
],
"fastest": {
Expand Down
4 changes: 4 additions & 0 deletions dist/es6/jssm.d.ts
Expand Up @@ -46,6 +46,8 @@ declare class Machine<mDT> {
_named_hooks: Map<string, Function>;
_entry_hooks: Map<string, Function>;
_exit_hooks: Map<string, Function>;
_global_action_hooks: Map<string, Function>;
_any_action_hook: HookHandler | undefined;
_any_transition_hook: HookHandler | undefined;
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>);
_new_state(state_config: JssmGenericState): StateType;
Expand Down Expand Up @@ -99,6 +101,8 @@ declare class Machine<mDT> {
set_hook(HookDesc: HookDescription): void;
hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
hook_action(from: string, to: string, action: string, handler: HookHandler): Machine<mDT>;
hook_global_action(action: string, handler: HookHandler): Machine<mDT>;
hook_any_action(handler: HookHandler): Machine<mDT>;
hook_any_transition(handler: HookHandler): Machine<mDT>;
hook_entry(to: string, handler: HookHandler): Machine<mDT>;
hook_exit(from: string, handler: HookHandler): Machine<mDT>;
Expand Down
49 changes: 41 additions & 8 deletions dist/es6/jssm.js
Expand Up @@ -355,6 +355,8 @@ class Machine {
this._named_hooks = new Map();
this._entry_hooks = new Map();
this._exit_hooks = new Map();
this._global_action_hooks = new Map();
this._any_action_hook = undefined;
this._any_transition_hook = undefined;
if (state_declaration) {
state_declaration.map((state_decl) => {
Expand Down Expand Up @@ -718,6 +720,14 @@ class Machine {
this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
this._has_hooks = true;
break;
case 'global action':
this._global_action_hooks.set(HookDesc.action, HookDesc.handler);
this._has_hooks = true;
break;
case 'any action':
this._any_action_hook = HookDesc.handler;
this._has_hooks = true;
break;
case 'any transition':
this._any_transition_hook = HookDesc.handler;
this._has_hooks = true;
Expand Down Expand Up @@ -745,6 +755,16 @@ class Machine {
this.set_hook({ kind: 'named', from, to, action, handler });
return this;
}
hook_global_action(action, handler) {
// TODO: should this throw if setting the hook fails, or ignore it and continue?
this.set_hook({ kind: 'global action', action, handler });
return this;
}
hook_any_action(handler) {
// TODO: should this throw if setting the hook fails, or ignore it and continue?
this.set_hook({ kind: 'any action', handler });
return this;
}
hook_any_transition(handler) {
// TODO: should this throw if setting the hook fails, or ignore it and continue?
this.set_hook({ kind: 'any transition', handler });
Expand Down Expand Up @@ -788,22 +808,35 @@ class Machine {
// todo major incomplete whargarbl comeback
if (valid) {
if (this._has_hooks) {
// 1. any action hook
// not yet implemented
// 2. any transition hook
if (wasAction) {
// 1. any action hook
if (this._any_action_hook !== undefined) {
if (this._any_action_hook() === false) {
return false;
}
}
// 2. global specific action hook
const maybe_ga_hook = this._global_action_hooks.get(newStateOrAction);
if (maybe_ga_hook !== undefined) {
if (maybe_ga_hook({ action: newStateOrAction, forced: wasForced }) === false) {
return false;
}
}
}
// 3. any transition hook
if (this._any_transition_hook !== undefined) {
if (this._any_transition_hook() === false) {
return false;
}
}
// 3. exit hook
// 4. exit hook
const maybe_ex_hook = this._exit_hooks.get(this._state);
if (maybe_ex_hook !== undefined) {
if (maybe_ex_hook({ from: this._state, forced: wasForced }) === false) {
return false;
}
}
// 4. named transition / action hook
// 5. named transition / action hook
if (wasAction) {
const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
if (n_maybe_hook !== undefined) {
Expand All @@ -812,16 +845,16 @@ class Machine {
}
}
}
// 5. regular hook
// 6. regular hook
const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
if (maybe_hook !== undefined) {
if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined }) === false) {
return false;
}
}
// 6. edge type hook
// 7. edge type hook
// not yet implemented
// 7. entry hook
// 8. entry hook
const maybe_en_hook = this._entry_hooks.get(newState);
if (maybe_en_hook !== undefined) {
if (maybe_en_hook({ to: newState, forced: wasForced }) === false) {
Expand Down
11 changes: 10 additions & 1 deletion dist/es6/jssm_types.d.ts
Expand Up @@ -166,6 +166,15 @@ declare type AnyTransitionHook = {
kind: 'any transition';
handler: HookHandler;
};
declare type GlobalActionHook = {
kind: 'global action';
action: string;
handler: HookHandler;
};
declare type AnyActionHook = {
kind: 'any action';
handler: HookHandler;
};
declare type EntryHook = {
kind: 'entry';
to: string;
Expand All @@ -176,5 +185,5 @@ declare type ExitHook = {
from: string;
handler: HookHandler;
};
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | AnyTransitionHook | EntryHook | ExitHook;
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | GlobalActionHook | AnyActionHook | AnyTransitionHook | EntryHook | ExitHook;
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 };
2 changes: 1 addition & 1 deletion dist/es6/version.js
@@ -1,2 +1,2 @@
const version = "5.57.1";
const version = "5.59.1";
export { version };
2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.js

Large diffs are not rendered by default.

51 changes: 42 additions & 9 deletions dist/jssm.es5.cjs.nonmin.js
Expand Up @@ -15886,7 +15886,7 @@ function peg$parse(input, options) {
}
}

const version = "5.57.1";
const version = "5.59.1";

// whargarbl lots of these return arrays could/should be sets
/* eslint-disable complexity */
Expand Down Expand Up @@ -16241,6 +16241,8 @@ class Machine {
this._named_hooks = new Map();
this._entry_hooks = new Map();
this._exit_hooks = new Map();
this._global_action_hooks = new Map();
this._any_action_hook = undefined;
this._any_transition_hook = undefined;
if (state_declaration) {
state_declaration.map((state_decl) => {
Expand Down Expand Up @@ -16604,6 +16606,14 @@ class Machine {
this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
this._has_hooks = true;
break;
case 'global action':
this._global_action_hooks.set(HookDesc.action, HookDesc.handler);
this._has_hooks = true;
break;
case 'any action':
this._any_action_hook = HookDesc.handler;
this._has_hooks = true;
break;
case 'any transition':
this._any_transition_hook = HookDesc.handler;
this._has_hooks = true;
Expand Down Expand Up @@ -16631,6 +16641,16 @@ class Machine {
this.set_hook({ kind: 'named', from, to, action, handler });
return this;
}
hook_global_action(action, handler) {
// TODO: should this throw if setting the hook fails, or ignore it and continue?
this.set_hook({ kind: 'global action', action, handler });
return this;
}
hook_any_action(handler) {
// TODO: should this throw if setting the hook fails, or ignore it and continue?
this.set_hook({ kind: 'any action', handler });
return this;
}
hook_any_transition(handler) {
// TODO: should this throw if setting the hook fails, or ignore it and continue?
this.set_hook({ kind: 'any transition', handler });
Expand Down Expand Up @@ -16674,22 +16694,35 @@ class Machine {
// todo major incomplete whargarbl comeback
if (valid) {
if (this._has_hooks) {
// 1. any action hook
// not yet implemented
// 2. any transition hook
if (wasAction) {
// 1. any action hook
if (this._any_action_hook !== undefined) {
if (this._any_action_hook() === false) {
return false;
}
}
// 2. global specific action hook
const maybe_ga_hook = this._global_action_hooks.get(newStateOrAction);
if (maybe_ga_hook !== undefined) {
if (maybe_ga_hook({ action: newStateOrAction, forced: wasForced }) === false) {
return false;
}
}
}
// 3. any transition hook
if (this._any_transition_hook !== undefined) {
if (this._any_transition_hook() === false) {
return false;
}
}
// 3. exit hook
// 4. exit hook
const maybe_ex_hook = this._exit_hooks.get(this._state);
if (maybe_ex_hook !== undefined) {
if (maybe_ex_hook({ from: this._state, forced: wasForced }) === false) {
return false;
}
}
// 4. named transition / action hook
// 5. named transition / action hook
if (wasAction) {
const nhn = named_hook_name(this._state, newState, newStateOrAction), n_maybe_hook = this._named_hooks.get(nhn);
if (n_maybe_hook !== undefined) {
Expand All @@ -16698,16 +16731,16 @@ class Machine {
}
}
}
// 5. regular hook
// 6. regular hook
const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
if (maybe_hook !== undefined) {
if (maybe_hook({ from: this._state, to: newState, forced: wasForced, action: wasAction ? newStateOrAction : undefined }) === false) {
return false;
}
}
// 6. edge type hook
// 7. edge type hook
// not yet implemented
// 7. entry hook
// 8. entry hook
const maybe_en_hook = this._entry_hooks.get(newState);
if (maybe_en_hook !== undefined) {
if (maybe_en_hook({ to: newState, forced: wasForced }) === false) {
Expand Down
2 changes: 1 addition & 1 deletion dist/jssm.es5.iife.js

Large diffs are not rendered by default.

0 comments on commit 56e3433

Please sign in to comment.