Skip to content

Commit

Permalink
Nicely tied up, basic set_hook posthooks, all simply tested
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Jul 2, 2022
1 parent 99847f8 commit 0222ce4
Show file tree
Hide file tree
Showing 68 changed files with 17,183 additions and 96 deletions.
32 changes: 31 additions & 1 deletion CHANGELOG.long.md
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

937 merges; 124 releases
939 merges; 124 releases



Expand All @@ -18,6 +18,36 @@ Published tags:



 

 

## [Untagged] - 7/1/2022 4:56:32 PM

Commit [99847f8ef8c60b521c6d3e979bcf07dd60125a56](https://github.com/StoneCypher/jssm/commit/99847f8ef8c60b521c6d3e979bcf07dd60125a56)

Author: `John Haugeland <stonecypher@gmail.com>`

* Post global action hook, fixes StoneCypher/fsl#905; post any action hook, fixes StoneCypher/fsl#906




&nbsp;

&nbsp;

## [Untagged] - 7/1/2022 4:03:56 PM

Commit [e5bfa2acf8edefe9322bd17540307ffb1f9eeb4d](https://github.com/StoneCypher/jssm/commit/e5bfa2acf8edefe9322bd17540307ffb1f9eeb4d)

Author: `John Haugeland <stonecypher@gmail.com>`

* Adds call points in set_hook for basic post-hooks, fixes #958




&nbsp;

&nbsp;
Expand Down
64 changes: 32 additions & 32 deletions CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file.

937 merges; 124 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)
939 merges; 124 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)



Expand All @@ -18,6 +18,36 @@ Published tags:



&nbsp;

&nbsp;

## [Untagged] - 7/1/2022 4:56:32 PM

Commit [99847f8ef8c60b521c6d3e979bcf07dd60125a56](https://github.com/StoneCypher/jssm/commit/99847f8ef8c60b521c6d3e979bcf07dd60125a56)

Author: `John Haugeland <stonecypher@gmail.com>`

* Post global action hook, fixes StoneCypher/fsl#905; post any action hook, fixes StoneCypher/fsl#906




&nbsp;

&nbsp;

## [Untagged] - 7/1/2022 4:03:56 PM

Commit [e5bfa2acf8edefe9322bd17540307ffb1f9eeb4d](https://github.com/StoneCypher/jssm/commit/e5bfa2acf8edefe9322bd17540307ffb1f9eeb4d)

Author: `John Haugeland <stonecypher@gmail.com>`

* Adds call points in set_hook for basic post-hooks, fixes #958




&nbsp;

&nbsp;
Expand Down Expand Up @@ -150,34 +180,4 @@ Commit [8762d17bd69cdf48f522dbd6ee188f46e29a0c06](https://github.com/StoneCypher

Author: `John Haugeland <stonecypher@gmail.com>`

* Hooks can change data, fixes StoneCypher/fsl#932




&nbsp;

&nbsp;

## [Untagged] - 6/25/2022 7:15:46 AM

Commit [fb82aff27a911a29304c8b7c211e48c1b6ac454e](https://github.com/StoneCypher/jssm/commit/fb82aff27a911a29304c8b7c211e48c1b6ac454e)

Author: `John Haugeland <stonecypher@gmail.com>`

* prepping to test main and forced




&nbsp;

&nbsp;

## [Untagged] - 6/25/2022 7:05:36 AM

Commit [3ffc6c2a0b76d1a4870cd80a0f94d745e1c976c9](https://github.com/StoneCypher/jssm/commit/3ffc6c2a0b76d1a4870cd80a0f94d745e1c976c9)

Author: `John Haugeland <stonecypher@gmail.com>`

* everything now tested but standard and main
* Hooks can change data, fixes StoneCypher/fsl#932
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -18,14 +18,14 @@ Please edit the file it's derived from, instead: `./src/md/readme_base.md`
* Generated for version 5.74.0 at 7/1/2022, 3:59:15 PM
* Generated for version 5.74.0 at 7/2/2022, 10:57:07 AM
-->
# jssm

Easy. Small. Fast. TS, es6, es5. Node, Browser. 100% coverage. Property
tests. Fuzz tests. Language tests for a dozen languages and emoji. Easy to
share online. Easy to embed. ***4,617 tests***.
share online. Easy to embed. ***4,634 tests***.

Readable, useful state machines as one-liner strings.

Expand Down
73 changes: 67 additions & 6 deletions dist/es6/jssm.js
Expand Up @@ -581,7 +581,6 @@ class Machine {
this._main_transition_hook = undefined;
this._forced_transition_hook = undefined;
this._any_transition_hook = undefined;
this._standard_transition_hook = undefined;
this._has_post_hooks = false;
this._has_post_basic_hooks = false;
this._has_post_named_hooks = false;
Expand All @@ -600,7 +599,6 @@ class Machine {
this._post_main_transition_hook = undefined;
this._post_forced_transition_hook = undefined;
this._post_any_transition_hook = undefined;
this._post_standard_transition_hook = undefined;
this._data = data;
this._history_length = history || 0;
this._history = new circular_buffer(this._history_length);
Expand Down Expand Up @@ -1274,12 +1272,12 @@ class Machine {
case 'post hook':
this._post_hooks.set(hook_name(HookDesc.from, HookDesc.to), HookDesc.handler);
this._has_post_hooks = true;
this._has_basic_hooks = true;
this._has_post_basic_hooks = true;
break;
case 'post named':
this._post_named_hooks.set(named_hook_name(HookDesc.from, HookDesc.to, HookDesc.action), HookDesc.handler);
this._has_post_hooks = true;
this._has_named_hooks = true;
this._has_post_named_hooks = true;
break;
case 'post global action':
this._post_global_action_hooks.set(HookDesc.action, HookDesc.handler);
Expand All @@ -1291,16 +1289,19 @@ class Machine {
this._has_post_hooks = true;
break;
case 'post standard transition':
console.log(`l1a ${JSON.stringify(HookDesc)}`);
this._post_standard_transition_hook = HookDesc.handler;
this._has_post_transition_hooks = true;
this._has_post_hooks = true;
break;
case 'post main transition':
console.log(`l1b ${JSON.stringify(HookDesc)}`);
this._post_main_transition_hook = HookDesc.handler;
this._has_post_transition_hooks = true;
this._has_post_hooks = true;
break;
case 'post forced transition':
console.log(`l1c ${JSON.stringify(HookDesc)}`);
this._post_forced_transition_hook = HookDesc.handler;
this._has_post_transition_hooks = true;
this._has_post_hooks = true;
Expand Down Expand Up @@ -1443,7 +1444,8 @@ class Machine {
action: fromAction,
from: this._state,
to: newState,
forced: wasForced
forced: wasForced,
trans_type
};
if (valid) {
if (this._has_hooks) {
Expand Down Expand Up @@ -1568,11 +1570,70 @@ class Machine {
this._post_any_action_hook(hook_args);
}
// 2. global specific action hook
const pgah = this._post_global_action_hooks.get(newStateOrAction);
const pgah = this._post_global_action_hooks.get(hook_args.action);
if (pgah !== undefined) {
pgah(hook_args);
}
}
// 3. any transition hook
if (this._post_any_transition_hook !== undefined) {
this._post_any_transition_hook(hook_args);
}
// 4. exit hook
if (this._has_post_exit_hooks) {
const peh = this._post_exit_hooks.get(hook_args.from); // todo this is probably from instead
if (peh !== undefined) {
peh(hook_args);
}
}
// 5. named transition / action hook
if (this._has_post_named_hooks) {
if (wasAction) {
const nhn = named_hook_name(hook_args.from, hook_args.to, hook_args.action), pnh = this._post_named_hooks.get(nhn);
if (pnh !== undefined) {
pnh(hook_args);
}
}
}
// 6. regular hook
if (this._has_post_basic_hooks) {
const hook = this._post_hooks.get(hook_name(hook_args.from, hook_args.to));
if (hook !== undefined) {
hook(hook_args);
}
}
// 7. edge type hook
// 7a. standard transition hook
if (trans_type === 'legal') {
console.log(`l2a ${JSON.stringify(hook_args)}`);
if (this._post_standard_transition_hook !== undefined) {
console.log(`l3a ${JSON.stringify(hook_args)} ${JSON.stringify(this._post_standard_transition_hook)}`);
this._post_standard_transition_hook(hook_args);
}
}
// 7b. main type hook
if (trans_type === 'main') {
console.log(`l2b ${JSON.stringify(hook_args)}`);
if (this._post_main_transition_hook !== undefined) {
console.log(`l3b ${JSON.stringify(hook_args)} ${JSON.stringify(this._post_main_transition_hook)}`);
this._post_main_transition_hook(hook_args);
}
}
// 7c. forced transition hook
if (trans_type === 'forced') {
console.log(`l2c ${JSON.stringify(hook_args)}`);
if (this._post_forced_transition_hook !== undefined) {
console.log(`l3c ${JSON.stringify(hook_args)} ${JSON.stringify(this._post_forced_transition_hook)}`);
this._post_forced_transition_hook(hook_args);
}
}
// 8. entry hook
if (this._has_post_entry_hooks) {
const hook = this._post_entry_hooks.get(hook_args.to);
if (hook !== undefined) {
hook(hook_args);
}
}
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.js

Large diffs are not rendered by default.

0 comments on commit 0222ce4

Please sign in to comment.