Skip to content

Commit

Permalink
Working external API hooks with rejection, fixes StoneCypher/fsl#701, f…
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed May 4, 2022
1 parent 58f4df2 commit 3041204
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 84 deletions.
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="chart1651618762036" width="16" height="9"></canvas>
<canvas id="chart1651624732492" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -51,18 +51,18 @@
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
)
}
const ctx1651618762036 = document
.getElementById('chart1651618762036')
const ctx1651624732492 = document
.getElementById('chart1651624732492')
.getContext('2d')
const chart1651618762036 = new Chart(ctx1651618762036, {
const chart1651624732492 = new Chart(ctx1651624732492, {
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: [21597,1823,15725,1578],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(10.127999999999997, 85%, 55%)","hsl(87.372, 85%, 55%)","hsl(8.772000000000004, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(10.127999999999997, 85%, 55%)","hsl(87.372, 85%, 55%)","hsl(8.772000000000004, 85%, 55%)"],
data: [20799,1784,15032,1486],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(10.296, 85%, 55%)","hsl(86.724, 85%, 55%)","hsl(8.568000000000001, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(10.296, 85%, 55%)","hsl(86.724, 85%, 55%)","hsl(8.568000000000001, 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-03T22:59:22.036Z",
"date": "2022-05-04T00:38:52.492Z",
"version": "1.0.0",
"results": [
{
"name": "Blind cycle a traffic light 500 times by transition",
"ops": 21597,
"margin": 3.84,
"ops": 20799,
"margin": 4.1,
"percentSlower": 0
},
{
"name": "Blind cycle a hooked traffic light 500 times by transition",
"ops": 1823,
"margin": 0.39,
"percentSlower": 91.56
"ops": 1784,
"margin": 0.65,
"percentSlower": 91.42
},
{
"name": "Blind cycle a traffic light 500 times by action",
"ops": 15725,
"margin": 0.86,
"percentSlower": 27.19
"ops": 15032,
"margin": 0.94,
"percentSlower": 27.73
},
{
"name": "Blind cycle a hooked traffic light 500 times by action",
"ops": 1578,
"margin": 0.73,
"percentSlower": 92.69
"ops": 1486,
"margin": 3.43,
"percentSlower": 92.86
}
],
"fastest": {
Expand Down
1 change: 0 additions & 1 deletion dist/es6/jssm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ declare class Machine<mDT> {
state_is_complete(whichState: StateType): boolean;
has_completes(): boolean;
set_hook(HookDesc: HookDescription): void;
remove_hook(HookDesc: HookDescription): void;
action(name: StateType, newData?: mDT): boolean;
transition(newState: StateType, newData?: mDT): boolean;
force_transition(newState: StateType, newData?: mDT): boolean;
Expand Down
28 changes: 14 additions & 14 deletions dist/es6/jssm.js
Original file line number Diff line number Diff line change
Expand Up @@ -709,20 +709,20 @@ class Machine {
this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
this._has_hooks = true;
break;
case 'entry':
console.log('TODO: Should add entry hook here');
throw 'TODO: Should add entry hook here';
case 'exit':
console.log('TODO: Should add exit hook here');
throw 'TODO: Should add exit hook here';
// case 'entry':
// console.log('TODO: Should add entry hook here');
// throw 'TODO: Should add entry hook here';
// case 'exit':
// console.log('TODO: Should add exit hook here');
// throw 'TODO: Should add exit hook here';
default:
console.log(`Unknown hook type ${HookDesc.kind}, should be impossible`);
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
}
}
remove_hook(HookDesc) {
throw 'TODO: Should remove hook here';
}
// remove_hook(HookDesc: HookDescription) {
// throw 'TODO: Should remove hook here';
// }
action(name, newData) {
// todo whargarbl implement hooks
// todo whargarbl implement data stuff
Expand All @@ -738,7 +738,7 @@ class Machine {
else {
hook_permits = maybe_hook({ from: this._state, to: edge.to, action: name });
}
if (hook_permits) {
if (hook_permits !== false) {
this._state = edge.to;
return true;
}
Expand Down Expand Up @@ -769,7 +769,7 @@ class Machine {
else {
hook_permits = maybe_hook({ from: this._state, to: newState });
}
if (hook_permits) {
if (hook_permits !== false) {
this._state = newState;
return true;
}
Expand All @@ -794,14 +794,14 @@ class Machine {
if (this.valid_force_transition(newState, newData)) {
if (this._has_hooks) {
let hook_permits = undefined;
const hn = hook_name(this._state, newState), maybe_hook = this._named_hooks.get(hn);
const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
if (maybe_hook === undefined) {
hook_permits = true;
}
else {
hook_permits = maybe_hook({ from: this._state, to: newState });
hook_permits = maybe_hook({ from: this._state, to: newState, forced: true });
}
if (hook_permits) {
if (hook_permits !== false) {
this._state = newState;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions dist/jssm.es5.cjs.nonmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16596,20 +16596,20 @@ class Machine {
this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
this._has_hooks = true;
break;
case 'entry':
console.log('TODO: Should add entry hook here');
throw 'TODO: Should add entry hook here';
case 'exit':
console.log('TODO: Should add exit hook here');
throw 'TODO: Should add exit hook here';
// case 'entry':
// console.log('TODO: Should add entry hook here');
// throw 'TODO: Should add entry hook here';
// case 'exit':
// console.log('TODO: Should add exit hook here');
// throw 'TODO: Should add exit hook here';
default:
console.log(`Unknown hook type ${HookDesc.kind}, should be impossible`);
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
}
}
remove_hook(HookDesc) {
throw 'TODO: Should remove hook here';
}
// remove_hook(HookDesc: HookDescription) {
// throw 'TODO: Should remove hook here';
// }
action(name, newData) {
// todo whargarbl implement hooks
// todo whargarbl implement data stuff
Expand All @@ -16625,7 +16625,7 @@ class Machine {
else {
hook_permits = maybe_hook({ from: this._state, to: edge.to, action: name });
}
if (hook_permits) {
if (hook_permits !== false) {
this._state = edge.to;
return true;
}
Expand Down Expand Up @@ -16656,7 +16656,7 @@ class Machine {
else {
hook_permits = maybe_hook({ from: this._state, to: newState });
}
if (hook_permits) {
if (hook_permits !== false) {
this._state = newState;
return true;
}
Expand All @@ -16681,14 +16681,14 @@ class Machine {
if (this.valid_force_transition(newState, newData)) {
if (this._has_hooks) {
let hook_permits = undefined;
const hn = hook_name(this._state, newState), maybe_hook = this._named_hooks.get(hn);
const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
if (maybe_hook === undefined) {
hook_permits = true;
}
else {
hook_permits = maybe_hook({ from: this._state, to: newState });
hook_permits = maybe_hook({ from: this._state, to: newState, forced: true });
}
if (hook_permits) {
if (hook_permits !== false) {
this._state = newState;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/jssm.es5.iife.js

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions dist/jssm.es5.iife.nonmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -16595,20 +16595,20 @@ var jssm = (function (exports) {
this._named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
this._has_hooks = true;
break;
case 'entry':
console.log('TODO: Should add entry hook here');
throw 'TODO: Should add entry hook here';
case 'exit':
console.log('TODO: Should add exit hook here');
throw 'TODO: Should add exit hook here';
// case 'entry':
// console.log('TODO: Should add entry hook here');
// throw 'TODO: Should add entry hook here';
// case 'exit':
// console.log('TODO: Should add exit hook here');
// throw 'TODO: Should add exit hook here';
default:
console.log(`Unknown hook type ${HookDesc.kind}, should be impossible`);
throw new RangeError(`Unknown hook type ${HookDesc.kind}, should be impossible`);
}
}
remove_hook(HookDesc) {
throw 'TODO: Should remove hook here';
}
// remove_hook(HookDesc: HookDescription) {
// throw 'TODO: Should remove hook here';
// }
action(name, newData) {
// todo whargarbl implement hooks
// todo whargarbl implement data stuff
Expand All @@ -16624,7 +16624,7 @@ var jssm = (function (exports) {
else {
hook_permits = maybe_hook({ from: this._state, to: edge.to, action: name });
}
if (hook_permits) {
if (hook_permits !== false) {
this._state = edge.to;
return true;
}
Expand Down Expand Up @@ -16655,7 +16655,7 @@ var jssm = (function (exports) {
else {
hook_permits = maybe_hook({ from: this._state, to: newState });
}
if (hook_permits) {
if (hook_permits !== false) {
this._state = newState;
return true;
}
Expand All @@ -16680,14 +16680,14 @@ var jssm = (function (exports) {
if (this.valid_force_transition(newState, newData)) {
if (this._has_hooks) {
let hook_permits = undefined;
const hn = hook_name(this._state, newState), maybe_hook = this._named_hooks.get(hn);
const hn = hook_name(this._state, newState), maybe_hook = this._hooks.get(hn);
if (maybe_hook === undefined) {
hook_permits = true;
}
else {
hook_permits = maybe_hook({ from: this._state, to: newState });
hook_permits = maybe_hook({ from: this._state, to: newState, forced: true });
}
if (hook_permits) {
if (hook_permits !== false) {
this._state = newState;
return true;
}
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.

1 change: 0 additions & 1 deletion jssm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ declare class Machine<mDT> {
state_is_complete(whichState: StateType): boolean;
has_completes(): boolean;
set_hook(HookDesc: HookDescription): void;
remove_hook(HookDesc: HookDescription): void;
action(name: StateType, newData?: mDT): boolean;
transition(newState: StateType, newData?: mDT): boolean;
force_transition(newState: StateType, newData?: mDT): boolean;
Expand Down
32 changes: 16 additions & 16 deletions src/ts/jssm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1000,13 +1000,13 @@ class Machine<mDT> {
this._has_hooks = true;
break;

case 'entry':
console.log('TODO: Should add entry hook here');
throw 'TODO: Should add entry hook here';
// case 'entry':
// console.log('TODO: Should add entry hook here');
// throw 'TODO: Should add entry hook here';

case 'exit':
console.log('TODO: Should add exit hook here');
throw 'TODO: Should add exit hook here';
// case 'exit':
// console.log('TODO: Should add exit hook here');
// throw 'TODO: Should add exit hook here';

default:
console.log(`Unknown hook type ${(HookDesc as any).kind}, should be impossible`);
Expand All @@ -1015,9 +1015,9 @@ class Machine<mDT> {
}
}

remove_hook(HookDesc: HookDescription) {
throw 'TODO: Should remove hook here';
}
// remove_hook(HookDesc: HookDescription) {
// throw 'TODO: Should remove hook here';
// }



Expand All @@ -1033,13 +1033,13 @@ class Machine<mDT> {

let hook_permits : boolean | undefined = undefined;

const nhn : string = named_hook_name(this._state, edge.to, name),
maybe_hook : Function | undefined = this._named_hooks.get(nhn);
const nhn : string = named_hook_name(this._state, edge.to, name),
maybe_hook = this._named_hooks.get(nhn);

if (maybe_hook === undefined) { hook_permits = true; }
else { hook_permits = maybe_hook( { from: this._state, to: edge.to, action: name } ); }

if (hook_permits) {
if (hook_permits !== false) {
this._state = edge.to;
return true;
} else {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ class Machine<mDT> {
if (maybe_hook === undefined) { hook_permits = true; }
else { hook_permits = maybe_hook( { from: this._state, to: newState } ); }

if (hook_permits) {
if (hook_permits !== false) {
this._state = newState;
return true;
} else {
Expand Down Expand Up @@ -1104,12 +1104,12 @@ class Machine<mDT> {
let hook_permits : boolean | undefined = undefined;

const hn : string = hook_name(this._state, newState),
maybe_hook : Function | undefined = this._named_hooks.get(hn);
maybe_hook : Function | undefined = this._hooks.get(hn);

if (maybe_hook === undefined) { hook_permits = true; }
else { hook_permits = maybe_hook({ from: this._state, to: newState }); }
else { hook_permits = maybe_hook({ from: this._state, to: newState, forced: true }); }

if (hook_permits) {
if (hook_permits !== false) {
this._state = newState;
return true;
} else {
Expand Down

0 comments on commit 3041204

Please sign in to comment.