Skip to content

Commit a72652c

Browse files
authored
Merge pull request #444 from StoneCypher/HooksConvenienceApi
Hooks convenience api
2 parents bd684b2 + fa1bf46 commit a72652c

23 files changed

+3066
-5052
lines changed

.npmignore

+13-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,16 @@ dist/jssm.es5.iife.nonmin.js
5656
dist/jssm.es5.cjs.nonmin.js
5757
dist/es6/jssm-dot.nonmin.js
5858

59-
benchmark/
59+
benchmark/
60+
src/
61+
.codeclimate.yml
62+
.editorconfig
63+
.eslintrc
64+
.nycrc
65+
.travis.yml
66+
jest-spec.config.js
67+
jest-stoch.config.js
68+
rollup.config.iife.js
69+
rollup.config.js
70+
tsconfig.json
71+
dist/jssm.es5.iife.js

benchmark/results/general.chart.html

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</head>
2929
<body>
3030
<div class="container">
31-
<canvas id="chart1651636100388" width="16" height="9"></canvas>
31+
<canvas id="chart1651779155663" width="16" height="9"></canvas>
3232
</div>
3333
<script>
3434
const format = (num) => {
@@ -51,18 +51,18 @@
5151
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
5252
)
5353
}
54-
const ctx1651636100388 = document
55-
.getElementById('chart1651636100388')
54+
const ctx1651779155663 = document
55+
.getElementById('chart1651779155663')
5656
.getContext('2d')
57-
const chart1651636100388 = new Chart(ctx1651636100388, {
57+
const chart1651779155663 = new Chart(ctx1651779155663, {
5858
type: 'bar',
5959
data: {
6060
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"],
6161
datasets: [
6262
{
63-
data: [20924,1805,14638,1565],
64-
backgroundColor: ["hsl(120, 85%, 55%)","hsl(10.355999999999995, 85%, 55%)","hsl(83.95200000000001, 85%, 55%)","hsl(8.976000000000004, 85%, 55%)"],
65-
borderColor: ["hsl(120, 85%, 55%)","hsl(10.355999999999995, 85%, 55%)","hsl(83.95200000000001, 85%, 55%)","hsl(8.976000000000004, 85%, 55%)"],
63+
data: [19086,1615,13476,1429],
64+
backgroundColor: ["hsl(120, 85%, 55%)","hsl(10.151999999999992, 85%, 55%)","hsl(84.732, 85%, 55%)","hsl(8.987999999999994, 85%, 55%)"],
65+
borderColor: ["hsl(120, 85%, 55%)","hsl(10.151999999999992, 85%, 55%)","hsl(84.732, 85%, 55%)","hsl(8.987999999999994, 85%, 55%)"],
6666
borderWidth: 2,
6767
},
6868
],

benchmark/results/general.json

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
{
22
"name": "General performance suite",
3-
"date": "2022-05-04T03:48:20.388Z",
3+
"date": "2022-05-05T19:32:35.663Z",
44
"version": "1.1.0",
55
"results": [
66
{
77
"name": "Blind cycle a traffic light 500 times by transition",
8-
"ops": 20924,
9-
"margin": 2.51,
8+
"ops": 19086,
9+
"margin": 1.86,
1010
"percentSlower": 0
1111
},
1212
{
1313
"name": "Blind cycle a hooked traffic light 500 times by transition",
14-
"ops": 1805,
15-
"margin": 0.7,
16-
"percentSlower": 91.37
14+
"ops": 1615,
15+
"margin": 2.44,
16+
"percentSlower": 91.54
1717
},
1818
{
1919
"name": "Blind cycle a traffic light 500 times by action",
20-
"ops": 14638,
21-
"margin": 2.41,
22-
"percentSlower": 30.04
20+
"ops": 13476,
21+
"margin": 3.02,
22+
"percentSlower": 29.39
2323
},
2424
{
2525
"name": "Blind cycle a hooked traffic light 500 times by action",
26-
"ops": 1565,
27-
"margin": 0.72,
28-
"percentSlower": 92.52
26+
"ops": 1429,
27+
"margin": 1.4,
28+
"percentSlower": 92.51
2929
}
3030
],
3131
"fastest": {

dist/es6/jssm.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare type StateType = string;
22
import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3-
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription } from './jssm_types';
3+
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler } from './jssm_types';
44
import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
55
import { version } from './version';
66
declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
@@ -90,6 +90,7 @@ declare class Machine<mDT> {
9090
state_is_complete(whichState: StateType): boolean;
9191
has_completes(): boolean;
9292
set_hook(HookDesc: HookDescription): void;
93+
hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
9394
action(name: StateType, newData?: mDT): boolean;
9495
transition(newState: StateType, newData?: mDT): boolean;
9596
force_transition(newState: StateType, newData?: mDT): boolean;

dist/es6/jssm.js

+5
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,11 @@ class Machine {
720720
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
721721
}
722722
}
723+
hook(from, to, handler) {
724+
// TODO: should this throw if setting the hook fails, or ignore it and continue?
725+
this.set_hook({ kind: 'hook', from, to, handler });
726+
return this;
727+
}
723728
// remove_hook(HookDesc: HookDescription) {
724729
// throw 'TODO: Should remove hook here';
725730
// }

dist/es6/jssm_types.d.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,29 @@ declare type JssmCompileSeStart<DataType> = {
148148
};
149149
declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
150150
declare type JssmParseFunctionType = (string: any) => JssmParseTree;
151+
declare type HookHandler = Function;
151152
declare type BasicHookDescription = {
152153
kind: 'hook';
153154
from: string;
154155
to: string;
155-
handler: Function;
156+
handler: HookHandler;
156157
};
157158
declare type HookDescriptionWithAction = {
158159
kind: 'named';
159160
from: string;
160161
to: string;
161162
action: string;
162-
handler: Function;
163+
handler: HookHandler;
163164
};
164165
declare type EntryHook = {
165166
kind: 'entry';
166167
to: string;
167-
handler: Function;
168+
handler: HookHandler;
168169
};
169170
declare type ExitHook = {
170171
kind: 'exit';
171172
from: string;
172-
handler: Function;
173+
handler: HookHandler;
173174
};
174175
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | EntryHook | ExitHook;
175-
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 };
176+
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 };

dist/es6/version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const version = "5.45.2";
1+
const version = "5.46.0";
22
export { version };

dist/jssm.es5.cjs.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jssm.es5.cjs.nonmin.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -15887,7 +15887,7 @@ function peg$parse(input, options) {
1588715887
}
1588815888
}
1588915889

15890-
const version = "5.45.2";
15890+
const version = "5.46.0";
1589115891

1589215892
// whargarbl lots of these return arrays could/should be sets
1589315893
/* eslint-disable complexity */
@@ -16607,6 +16607,11 @@ class Machine {
1660716607
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
1660816608
}
1660916609
}
16610+
hook(from, to, handler) {
16611+
// TODO: should this throw if setting the hook fails, or ignore it and continue?
16612+
this.set_hook({ kind: 'hook', from, to, handler });
16613+
return this;
16614+
}
1661016615
// remove_hook(HookDesc: HookDescription) {
1661116616
// throw 'TODO: Should remove hook here';
1661216617
// }

dist/jssm.es5.iife.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/jssm.es5.iife.nonmin.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -15886,7 +15886,7 @@ var jssm = (function (exports) {
1588615886
}
1588715887
}
1588815888

15889-
const version = "5.45.2";
15889+
const version = "5.46.0";
1589015890

1589115891
// whargarbl lots of these return arrays could/should be sets
1589215892
/* eslint-disable complexity */
@@ -16606,6 +16606,11 @@ var jssm = (function (exports) {
1660616606
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
1660716607
}
1660816608
}
16609+
hook(from, to, handler) {
16610+
// TODO: should this throw if setting the hook fails, or ignore it and continue?
16611+
this.set_hook({ kind: 'hook', from, to, handler });
16612+
return this;
16613+
}
1660916614
// remove_hook(HookDesc: HookDescription) {
1661016615
// throw 'TODO: Should remove hook here';
1661116616
// }

docs/docs/assets/search.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/docs/classes/Machine.html

+1-1
Large diffs are not rendered by default.

docs/docs/modules.html

+1-1
Large diffs are not rendered by default.

jssm.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
declare type StateType = string;
22
import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
3-
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription } from './jssm_types';
3+
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler } from './jssm_types';
44
import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
55
import { version } from './version';
66
declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
@@ -90,6 +90,7 @@ declare class Machine<mDT> {
9090
state_is_complete(whichState: StateType): boolean;
9191
has_completes(): boolean;
9292
set_hook(HookDesc: HookDescription): void;
93+
hook(from: string, to: string, handler: HookHandler): Machine<mDT>;
9394
action(name: StateType, newData?: mDT): boolean;
9495
transition(newState: StateType, newData?: mDT): boolean;
9596
force_transition(newState: StateType, newData?: mDT): boolean;

jssm_types.d.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -148,28 +148,29 @@ declare type JssmCompileSeStart<DataType> = {
148148
};
149149
declare type JssmParseTree = Array<JssmCompileSeStart<StateType>>;
150150
declare type JssmParseFunctionType = (string: any) => JssmParseTree;
151+
declare type HookHandler = Function;
151152
declare type BasicHookDescription = {
152153
kind: 'hook';
153154
from: string;
154155
to: string;
155-
handler: Function;
156+
handler: HookHandler;
156157
};
157158
declare type HookDescriptionWithAction = {
158159
kind: 'named';
159160
from: string;
160161
to: string;
161162
action: string;
162-
handler: Function;
163+
handler: HookHandler;
163164
};
164165
declare type EntryHook = {
165166
kind: 'entry';
166167
to: string;
167-
handler: Function;
168+
handler: HookHandler;
168169
};
169170
declare type ExitHook = {
170171
kind: 'exit';
171172
from: string;
172-
handler: Function;
173+
handler: HookHandler;
173174
};
174175
declare type HookDescription = BasicHookDescription | HookDescriptionWithAction | EntryHook | ExitHook;
175-
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 };
176+
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 };

0 commit comments

Comments
 (0)