Skip to content

Commit

Permalink
Hooks can change data, fixes StoneCypher/fsl#932
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed Jun 25, 2022
1 parent fb82aff commit 8762d17
Show file tree
Hide file tree
Showing 18 changed files with 339 additions and 157 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.long.md
Expand Up @@ -2,7 +2,7 @@

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

928 merges; 120 releases
929 merges; 120 releases



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



 

 

## [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;
Expand Down
36 changes: 17 additions & 19 deletions CHANGELOG.md
Expand Up @@ -2,7 +2,7 @@

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

928 merges; 120 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)
929 merges; 120 releases; Changlogging the last 10 commits; Full changelog at [CHANGELOG.long.md](CHANGELOG.long.md)



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



&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;
Expand Down Expand Up @@ -157,21 +172,4 @@ Commit [547e35599ed312bf5300d3f1685e2cb16b80a73e](https://github.com/StoneCypher

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

* Can read data from outside, fixes StoneCypher/fsl#929




&nbsp;

&nbsp;

<a name="5__72__0" />

## [5.72.0] - 6/24/2022 4:08:35 PM

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

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

* First steps towards being a Moore machine - initial data in constructor fixes StoneCypher/fsl#923 , can read in hooks fixes StoneCypher/fsl#924
* Can read data from outside, fixes StoneCypher/fsl#929
6 changes: 4 additions & 2 deletions dist/es6/jssm.d.ts
@@ -1,6 +1,6 @@
declare type StateType = string;
import { JssmGenericState, JssmGenericConfig, JssmTransition, JssmTransitionList, // JssmTransitionRule,
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler, HookResult } from './jssm_types';
JssmMachineInternalState, JssmParseTree, JssmStateDeclaration, JssmArrow, JssmArrowDirection, JssmArrowKind, JssmLayout, FslDirection, FslTheme, HookDescription, HookHandler, HookContext, HookResult, HookComplexResult } from './jssm_types';
import { seq, weighted_rand_select, weighted_sample_select, histograph, weighted_histo_key } from './jssm_util';
import { shapes, gviz_shapes, named_colors } from './jssm_constants';
import { version } from './version';
Expand Down Expand Up @@ -669,5 +669,7 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
*
*/
declare function from<mDT>(MachineAsString: string, ExtraConstructorFields?: Partial<JssmGenericConfig<mDT>> | undefined): Machine<mDT>;
declare function is_hook_complex_result<mDT>(hr: unknown): hr is HookComplexResult<mDT>;
declare function is_hook_rejection<mDT>(hr: HookResult<mDT>): boolean;
export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, shapes, gviz_shapes, named_colors, is_hook_rejection };
declare function abstract_hook_step<mDT>(maybe_hook: HookHandler<mDT> | undefined, hook_args: HookContext<mDT>): HookComplexResult<mDT>;
export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind, seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, shapes, gviz_shapes, named_colors, is_hook_rejection, is_hook_complex_result, abstract_hook_step };
24 changes: 12 additions & 12 deletions dist/es6/jssm.js
Expand Up @@ -1346,29 +1346,29 @@ class Machine {
let data_changed = false;
if (wasAction) {
// 1. any action hook
const outcome = AbstractHookStep(this._any_action_hook, hook_args);
const outcome = abstract_hook_step(this._any_action_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
// 2. global specific action hook
const outcome2 = AbstractHookStep(this._global_action_hooks.get(newStateOrAction), hook_args);
const outcome2 = abstract_hook_step(this._global_action_hooks.get(newStateOrAction), hook_args);
if (outcome2.pass === false) {
return false;
}
update_fields(outcome2);
}
// 3. any transition hook
if (this._any_transition_hook !== undefined) {
const outcome = AbstractHookStep(this._any_transition_hook, hook_args);
const outcome = abstract_hook_step(this._any_transition_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
}
// 4. exit hook
if (this._has_exit_hooks) {
const outcome = AbstractHookStep(this._exit_hooks.get(this._state), hook_args);
const outcome = abstract_hook_step(this._exit_hooks.get(this._state), hook_args);
if (outcome.pass === false) {
return false;
}
Expand All @@ -1377,7 +1377,7 @@ class Machine {
// 5. named transition / action hook
if (this._has_named_hooks) {
if (wasAction) {
const nhn = named_hook_name(this._state, newState, newStateOrAction), outcome = AbstractHookStep(this._named_hooks.get(nhn), hook_args);
const nhn = named_hook_name(this._state, newState, newStateOrAction), outcome = abstract_hook_step(this._named_hooks.get(nhn), hook_args);
if (outcome.pass === false) {
return false;
}
Expand All @@ -1386,7 +1386,7 @@ class Machine {
}
// 6. regular hook
if (this._has_basic_hooks) {
const hn = hook_name(this._state, newState), outcome = AbstractHookStep(this._hooks.get(hn), hook_args);
const hn = hook_name(this._state, newState), outcome = abstract_hook_step(this._hooks.get(hn), hook_args);
if (outcome.pass === false) {
return false;
}
Expand All @@ -1395,31 +1395,31 @@ class Machine {
// 7. edge type hook
// 7a. standard transition hook
if (trans_type === 'legal') {
const outcome = AbstractHookStep(this._standard_transition_hook, hook_args);
const outcome = abstract_hook_step(this._standard_transition_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
}
// 7b. main type hook
if (trans_type === 'main') {
const outcome = AbstractHookStep(this._main_transition_hook, hook_args);
const outcome = abstract_hook_step(this._main_transition_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
}
// 7c. forced transition hook
if (trans_type === 'forced') {
const outcome = AbstractHookStep(this._forced_transition_hook, hook_args);
const outcome = abstract_hook_step(this._forced_transition_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
}
// 8. entry hook
if (this._has_entry_hooks) {
const outcome = AbstractHookStep(this._entry_hooks.get(newState), hook_args);
const outcome = abstract_hook_step(this._entry_hooks.get(newState), hook_args);
if (outcome.pass === false) {
return false;
}
Expand Down Expand Up @@ -1644,7 +1644,7 @@ function is_hook_rejection(hr) {
}
throw new TypeError('unknown hook rejection type result');
}
function AbstractHookStep(maybe_hook, hook_args) {
function abstract_hook_step(maybe_hook, hook_args) {
if (maybe_hook !== undefined) {
const result = maybe_hook(hook_args);
if (result === undefined) {
Expand All @@ -1667,4 +1667,4 @@ function AbstractHookStep(maybe_hook, hook_args) {
}
export { version, transfer_state_properties, Machine, make, wrap_parse as parse, compile, sm, from, arrow_direction, arrow_left_kind, arrow_right_kind,
// WHARGARBL TODO these should be exported to a utility library
seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, shapes, gviz_shapes, named_colors, is_hook_rejection };
seq, weighted_rand_select, histograph, weighted_sample_select, weighted_histo_key, shapes, gviz_shapes, named_colors, is_hook_rejection, is_hook_complex_result, abstract_hook_step };
2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs.js

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions dist/jssm.es5.cjs.nonmin.js
Expand Up @@ -18154,29 +18154,29 @@ class Machine {
let data_changed = false;
if (wasAction) {
// 1. any action hook
const outcome = AbstractHookStep(this._any_action_hook, hook_args);
const outcome = abstract_hook_step(this._any_action_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
// 2. global specific action hook
const outcome2 = AbstractHookStep(this._global_action_hooks.get(newStateOrAction), hook_args);
const outcome2 = abstract_hook_step(this._global_action_hooks.get(newStateOrAction), hook_args);
if (outcome2.pass === false) {
return false;
}
update_fields(outcome2);
}
// 3. any transition hook
if (this._any_transition_hook !== undefined) {
const outcome = AbstractHookStep(this._any_transition_hook, hook_args);
const outcome = abstract_hook_step(this._any_transition_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
}
// 4. exit hook
if (this._has_exit_hooks) {
const outcome = AbstractHookStep(this._exit_hooks.get(this._state), hook_args);
const outcome = abstract_hook_step(this._exit_hooks.get(this._state), hook_args);
if (outcome.pass === false) {
return false;
}
Expand All @@ -18185,7 +18185,7 @@ class Machine {
// 5. named transition / action hook
if (this._has_named_hooks) {
if (wasAction) {
const nhn = named_hook_name(this._state, newState, newStateOrAction), outcome = AbstractHookStep(this._named_hooks.get(nhn), hook_args);
const nhn = named_hook_name(this._state, newState, newStateOrAction), outcome = abstract_hook_step(this._named_hooks.get(nhn), hook_args);
if (outcome.pass === false) {
return false;
}
Expand All @@ -18194,7 +18194,7 @@ class Machine {
}
// 6. regular hook
if (this._has_basic_hooks) {
const hn = hook_name(this._state, newState), outcome = AbstractHookStep(this._hooks.get(hn), hook_args);
const hn = hook_name(this._state, newState), outcome = abstract_hook_step(this._hooks.get(hn), hook_args);
if (outcome.pass === false) {
return false;
}
Expand All @@ -18203,31 +18203,31 @@ class Machine {
// 7. edge type hook
// 7a. standard transition hook
if (trans_type === 'legal') {
const outcome = AbstractHookStep(this._standard_transition_hook, hook_args);
const outcome = abstract_hook_step(this._standard_transition_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
}
// 7b. main type hook
if (trans_type === 'main') {
const outcome = AbstractHookStep(this._main_transition_hook, hook_args);
const outcome = abstract_hook_step(this._main_transition_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
}
// 7c. forced transition hook
if (trans_type === 'forced') {
const outcome = AbstractHookStep(this._forced_transition_hook, hook_args);
const outcome = abstract_hook_step(this._forced_transition_hook, hook_args);
if (outcome.pass === false) {
return false;
}
update_fields(outcome);
}
// 8. entry hook
if (this._has_entry_hooks) {
const outcome = AbstractHookStep(this._entry_hooks.get(newState), hook_args);
const outcome = abstract_hook_step(this._entry_hooks.get(newState), hook_args);
if (outcome.pass === false) {
return false;
}
Expand Down Expand Up @@ -18452,7 +18452,7 @@ function is_hook_rejection(hr) {
}
throw new TypeError('unknown hook rejection type result');
}
function AbstractHookStep(maybe_hook, hook_args) {
function abstract_hook_step(maybe_hook, hook_args) {
if (maybe_hook !== undefined) {
const result = maybe_hook(hook_args);
if (result === undefined) {
Expand All @@ -18475,13 +18475,15 @@ function AbstractHookStep(maybe_hook, hook_args) {
}

exports.Machine = Machine;
exports.abstract_hook_step = abstract_hook_step;
exports.arrow_direction = arrow_direction;
exports.arrow_left_kind = arrow_left_kind;
exports.arrow_right_kind = arrow_right_kind;
exports.compile = compile;
exports.from = from;
exports.gviz_shapes = gviz_shapes;
exports.histograph = histograph;
exports.is_hook_complex_result = is_hook_complex_result;
exports.is_hook_rejection = is_hook_rejection;
exports.make = make;
exports.named_colors = named_colors;
Expand Down
2 changes: 1 addition & 1 deletion dist/jssm.es5.iife.js

Large diffs are not rendered by default.

0 comments on commit 8762d17

Please sign in to comment.