Skip to content

Commit

Permalink
Unified transition and force_transition, fixes StoneCypher/fsl#707
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed May 8, 2022
1 parent c89d67e commit 8b8e675
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 46 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="chart1651999501365" width="16" height="9"></canvas>
<canvas id="chart1651999690706" width="16" height="9"></canvas>
</div>
<script>
const format = (num) => {
Expand All @@ -51,18 +51,18 @@
chunked.map((chunk) => chunk.join('')).join(' ') + fractionStr
)
}
const ctx1651999501365 = document
.getElementById('chart1651999501365')
const ctx1651999690706 = document
.getElementById('chart1651999690706')
.getContext('2d')
const chart1651999501365 = new Chart(ctx1651999501365, {
const chart1651999690706 = new Chart(ctx1651999690706, {
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: [14117,1635,14353,1481],
backgroundColor: ["hsl(118.03200000000001, 85%, 55%)","hsl(13.668, 85%, 55%)","hsl(120, 85%, 55%)","hsl(12.383999999999991, 85%, 55%)"],
borderColor: ["hsl(118.03200000000001, 85%, 55%)","hsl(13.668, 85%, 55%)","hsl(120, 85%, 55%)","hsl(12.383999999999991, 85%, 55%)"],
data: [17682,1687,13782,1469],
backgroundColor: ["hsl(120, 85%, 55%)","hsl(11.448000000000008, 85%, 55%)","hsl(93.52799999999999, 85%, 55%)","hsl(9.972000000000003, 85%, 55%)"],
borderColor: ["hsl(120, 85%, 55%)","hsl(11.448000000000008, 85%, 55%)","hsl(93.52799999999999, 85%, 55%)","hsl(9.972000000000003, 85%, 55%)"],
borderWidth: 2,
},
],
Expand Down
30 changes: 15 additions & 15 deletions benchmark/results/general.json
@@ -1,36 +1,36 @@
{
"name": "General performance suite",
"date": "2022-05-08T08:45:01.365Z",
"date": "2022-05-08T08:48:10.706Z",
"version": "1.1.0",
"results": [
{
"name": "Blind cycle a traffic light 500 times by transition",
"ops": 14117,
"margin": 0.87,
"percentSlower": 1.64
"ops": 17682,
"margin": 1.53,
"percentSlower": 0
},
{
"name": "Blind cycle a hooked traffic light 500 times by transition",
"ops": 1635,
"margin": 0.66,
"percentSlower": 88.61
"ops": 1687,
"margin": 0.84,
"percentSlower": 90.46
},
{
"name": "Blind cycle a traffic light 500 times by action",
"ops": 14353,
"margin": 0.75,
"percentSlower": 0
"ops": 13782,
"margin": 1.9,
"percentSlower": 22.06
},
{
"name": "Blind cycle a hooked traffic light 500 times by action",
"ops": 1481,
"margin": 0.5,
"percentSlower": 89.68
"ops": 1469,
"margin": 0.94,
"percentSlower": 91.69
}
],
"fastest": {
"name": "Blind cycle a traffic light 500 times by action",
"index": 2
"name": "Blind cycle a traffic light 500 times by transition",
"index": 0
},
"slowest": {
"name": "Blind cycle a hooked traffic light 500 times by action",
Expand Down
17 changes: 12 additions & 5 deletions dist/es6/jssm.js
Expand Up @@ -784,13 +784,20 @@ class Machine {
}
}
transition_impl(newState, newData, wasForced, wasAction) {
// can't just be direct references because then it loses object context
const validator = wasForced
? (newState, newData) => this.valid_force_transition(newState, newData)
: (newState, newData) => this.valid_transition(newState, newData);
let valid = false;
if (wasForced) {
if (this.valid_force_transition(newState, newData)) {
valid = true;
}
}
else {
if (this.valid_transition(newState, newData)) {
valid = true;
}
}
// todo whargarbl implement data stuff
// todo major incomplete whargarbl comeback
if (validator(newState, newData)) {
if (valid) {
if (this._has_hooks) {
let hook_permits = undefined;
if (this._any_transition_hook !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions dist/jssm.es5.cjs.nonmin.js
Expand Up @@ -16671,13 +16671,20 @@ class Machine {
}
}
transition_impl(newState, newData, wasForced, wasAction) {
// can't just be direct references because then it loses object context
const validator = wasForced
? (newState, newData) => this.valid_force_transition(newState, newData)
: (newState, newData) => this.valid_transition(newState, newData);
let valid = false;
if (wasForced) {
if (this.valid_force_transition(newState, newData)) {
valid = true;
}
}
else {
if (this.valid_transition(newState, newData)) {
valid = true;
}
}
// todo whargarbl implement data stuff
// todo major incomplete whargarbl comeback
if (validator(newState, newData)) {
if (valid) {
if (this._has_hooks) {
let hook_permits = undefined;
if (this._any_transition_hook !== undefined) {
Expand Down
2 changes: 1 addition & 1 deletion dist/jssm.es5.iife.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions dist/jssm.es5.iife.nonmin.js
Expand Up @@ -16670,13 +16670,20 @@ var jssm = (function (exports) {
}
}
transition_impl(newState, newData, wasForced, wasAction) {
// can't just be direct references because then it loses object context
const validator = wasForced
? (newState, newData) => this.valid_force_transition(newState, newData)
: (newState, newData) => this.valid_transition(newState, newData);
let valid = false;
if (wasForced) {
if (this.valid_force_transition(newState, newData)) {
valid = true;
}
}
else {
if (this.valid_transition(newState, newData)) {
valid = true;
}
}
// todo whargarbl implement data stuff
// todo major incomplete whargarbl comeback
if (validator(newState, newData)) {
if (valid) {
if (this._has_hooks) {
let hook_permits = undefined;
if (this._any_transition_hook !== undefined) {
Expand Down
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.

9 changes: 4 additions & 5 deletions src/ts/jssm.ts
Expand Up @@ -1110,14 +1110,13 @@ class Machine<mDT> {

transition_impl(newState: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean {

// can't just be direct references because then it loses object context
const validator = wasForced
? (newState, newData) => this.valid_force_transition(newState, newData)
: (newState, newData) => this.valid_transition(newState, newData);
let valid: boolean = false;
if (wasForced) { if (this.valid_force_transition(newState, newData)) { valid = true; } }
else { if (this.valid_transition( newState, newData)) { valid = true; } }

// todo whargarbl implement data stuff
// todo major incomplete whargarbl comeback
if (validator(newState, newData)) {
if (valid) {

if (this._has_hooks) {

Expand Down

0 comments on commit 8b8e675

Please sign in to comment.