Skip to content

Commit

Permalink
Merge pull request #444 from StoneCypher/HooksConvenienceApi
Browse files Browse the repository at this point in the history
Hooks convenience api
  • Loading branch information
StoneCypher authored May 5, 2022
2 parents bd684b2 + fa1bf46 commit a72652c
Show file tree
Hide file tree
Showing 23 changed files with 3,066 additions and 5,052 deletions.
14 changes: 13 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,16 @@ dist/jssm.es5.iife.nonmin.js
dist/jssm.es5.cjs.nonmin.js
dist/es6/jssm-dot.nonmin.js

benchmark/
benchmark/
src/
.codeclimate.yml
.editorconfig
.eslintrc
.nycrc
.travis.yml
jest-spec.config.js
jest-stoch.config.js
rollup.config.iife.js
rollup.config.js
tsconfig.json
dist/jssm.es5.iife.js
14 changes: 7 additions & 7 deletions benchmark/results/general.chart.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</head>
<body>
<div class="container">
<canvas id="chart1651636100388" width="16" height="9"></canvas>
<canvas id="chart1651779155663" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -51,18 +51,18 @@
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
)
}
const ctx1651636100388 = document
.getElementById('chart1651636100388')
const ctx1651779155663 = document
.getElementById('chart1651779155663')
.getContext('2d')
const chart1651636100388 = new Chart(ctx1651636100388, {
const chart1651779155663 = new Chart(ctx1651779155663, {
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: [20924,1805,14638,1565],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(10.355999999999995, 85%, 55%)","hsl(83.95200000000001, 85%, 55%)","hsl(8.976000000000004, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(10.355999999999995, 85%, 55%)","hsl(83.95200000000001, 85%, 55%)","hsl(8.976000000000004, 85%, 55%)"],
data: [19086,1615,13476,1429],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(10.151999999999992, 85%, 55%)","hsl(84.732, 85%, 55%)","hsl(8.987999999999994, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(10.151999999999992, 85%, 55%)","hsl(84.732, 85%, 55%)","hsl(8.987999999999994, 85%, 55%)"],
borderWidth: 2,
},
],
Expand Down
24 changes: 12 additions & 12 deletions benchmark/results/general.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"name": "General performance suite",
"date": "2022-05-04T03:48:20.388Z",
"date": "2022-05-05T19:32:35.663Z",
"version": "1.1.0",
"results": [
{
"name": "Blind cycle a traffic light 500 times by transition",
"ops": 20924,
"margin": 2.51,
"ops": 19086,
"margin": 1.86,
"percentSlower": 0
},
{
"name": "Blind cycle a hooked traffic light 500 times by transition",
"ops": 1805,
"margin": 0.7,
"percentSlower": 91.37
"ops": 1615,
"margin": 2.44,
"percentSlower": 91.54
},
{
"name": "Blind cycle a traffic light 500 times by action",
"ops": 14638,
"margin": 2.41,
"percentSlower": 30.04
"ops": 13476,
"margin": 3.02,
"percentSlower": 29.39
},
{
"name": "Blind cycle a hooked traffic light 500 times by action",
"ops": 1565,
"margin": 0.72,
"percentSlower": 92.52
"ops": 1429,
"margin": 1.4,
"percentSlower": 92.51
}
],
"fastest": {
Expand Down
3 changes: 2 additions & 1 deletion dist/es6/jssm.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare type StateType = string;
import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription } from './jssm_types';
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler } from './jssm_types';
import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
import { version } from './version';
declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
Expand Down Expand Up @@ -90,6 +90,7 @@ declare class Machine<mDT> {
state_is_complete(whichState: StateType): boolean;
has_completes(): boolean;
set_hook(HookDesc: HookDescription): void;
hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
action(name: StateType, newData?: mDT): boolean;
transition(newState: StateType, newData?: mDT): boolean;
force_transition(newState: StateType, newData?: mDT): boolean;
Expand Down
5 changes: 5 additions & 0 deletions dist/es6/jssm.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,11 @@ class Machine {
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
}
}
hook(from, to, handler) {
// TODO: should this throw if setting the hook fails, or ignore it and continue?
this.set_hook({ kind: 'hook', from, to, handler });
return this;
}
// remove_hook(HookDesc: HookDescription) {
// throw 'TODO: Should remove hook here';
// }
Expand Down
11 changes: 6 additions & 5 deletions dist/es6/jssm_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,29 @@ declare type JssmCompileSeStart<DataType> = {
};
declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
declare type JssmParseFunctionType = (string: any) => JssmParseTree;
declare type HookHandler = Function;
declare type BasicHookDescription = {
kind: 'hook';
from: string;
to: string;
handler: Function;
handler: HookHandler;
};
declare type HookDescriptionWithAction = {
kind: 'named';
from: string;
to: string;
action: string;
handler: Function;
handler: HookHandler;
};
declare type EntryHook = {
kind: 'entry';
to: string;
handler: Function;
handler: HookHandler;
};
declare type ExitHook = {
kind: 'exit';
from: string;
handler: Function;
handler: HookHandler;
};
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | 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 };
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
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const version = "5.45.2";
const version = "5.46.0";
export { version };
2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion dist/jssm.es5.cjs.nonmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15887,7 +15887,7 @@ function peg$parse(input, options) {
}
}

const version = "5.45.2";
const version = "5.46.0";

// whargarbl lots of these return arrays could/should be sets
/* eslint-disable complexity */
Expand Down Expand Up @@ -16607,6 +16607,11 @@ class Machine {
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
}
}
hook(from, to, handler) {
// TODO: should this throw if setting the hook fails, or ignore it and continue?
this.set_hook({ kind: 'hook', from, to, handler });
return this;
}
// remove_hook(HookDesc: HookDescription) {
// throw 'TODO: Should remove hook here';
// }
Expand Down
2 changes: 1 addition & 1 deletion dist/jssm.es5.iife.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion dist/jssm.es5.iife.nonmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15886,7 +15886,7 @@ var jssm = (function (exports) {
}
}

const version = "5.45.2";
const version = "5.46.0";

// whargarbl lots of these return arrays could/should be sets
/* eslint-disable complexity */
Expand Down Expand Up @@ -16606,6 +16606,11 @@ var jssm = (function (exports) {
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
}
}
hook(from, to, handler) {
// TODO: should this throw if setting the hook fails, or ignore it and continue?
this.set_hook({ kind: 'hook', from, to, handler });
return this;
}
// remove_hook(HookDesc: HookDescription) {
// throw 'TODO: Should remove hook here';
// }
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/assets/search.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/docs/classes/Machine.html

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/docs/modules.html

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion jssm.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
declare type StateType = string;
import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription } from './jssm_types';
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler } from './jssm_types';
import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
import { version } from './version';
declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
Expand Down Expand Up @@ -90,6 +90,7 @@ declare class Machine<mDT> {
state_is_complete(whichState: StateType): boolean;
has_completes(): boolean;
set_hook(HookDesc: HookDescription): void;
hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
action(name: StateType, newData?: mDT): boolean;
transition(newState: StateType, newData?: mDT): boolean;
force_transition(newState: StateType, newData?: mDT): boolean;
Expand Down
11 changes: 6 additions & 5 deletions jssm_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,29 @@ declare type JssmCompileSeStart<DataType> = {
};
declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
declare type JssmParseFunctionType = (string: any) => JssmParseTree;
declare type HookHandler = Function;
declare type BasicHookDescription = {
kind: 'hook';
from: string;
to: string;
handler: Function;
handler: HookHandler;
};
declare type HookDescriptionWithAction = {
kind: 'named';
from: string;
to: string;
action: string;
handler: Function;
handler: HookHandler;
};
declare type EntryHook = {
kind: 'entry';
to: string;
handler: Function;
handler: HookHandler;
};
declare type ExitHook = {
kind: 'exit';
from: string;
handler: Function;
handler: HookHandler;
};
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | 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 };
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 };
Loading

0 comments on commit a72652c

Please sign in to comment.