Skip to content

Commit

Permalink
Merge pull request #568 from StoneCypher/SetInitialState
Browse files Browse the repository at this point in the history
Set initial state
  • Loading branch information
StoneCypher authored Mar 27, 2024
2 parents e642702 + 9f66ad0 commit b2d953d
Show file tree
Hide file tree
Showing 37 changed files with 797 additions and 214 deletions.
179 changes: 177 additions & 2 deletions CHANGELOG.long.md

Large diffs are not rendered by default.

85 changes: 35 additions & 50 deletions CHANGELOG.md

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ Please edit the file it's derived from, instead: `./src/md/readme_base.md`
* Generated for version 5.97.1 at 2/5/2024, 2:56:05 PM
* Generated for version 5.98.0 at 3/25/2024, 7:17:45 PM
-->
# jssm 5.97.1
# jssm 5.98.0

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.

Readable, useful state machines as one-liner strings.

***5,062 tests***, run 5,953 times.
***5,070 tests***, run 5,961 times.

* 5,053 specs with 100.0% coverage.
* 9 fuzz tests with 12.5% coverage.
* 5,061 specs with 100.0% coverage.
* 9 fuzz tests with 12.4% coverage.

With 2,956 lines, that's about 1.7 tests per line, or 2.0 generated tests per line.
With 2,970 lines, that's about 1.7 tests per line, or 2.0 generated tests per line.

***Meet your new state machine library.***

Expand Down
12 changes: 6 additions & 6 deletions dist/deno/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ Please edit the file it's derived from, instead: `./src/md/readme_base.md`
* Generated for version 5.97.1 at 2/5/2024, 2:56:05 PM
* Generated for version 5.98.0 at 3/25/2024, 7:17:45 PM
-->
# jssm 5.97.1
# jssm 5.98.0

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.

Readable, useful state machines as one-liner strings.

***5,062 tests***, run 5,953 times.
***5,070 tests***, run 5,961 times.

* 5,053 specs with 100.0% coverage.
* 9 fuzz tests with 12.5% coverage.
* 5,061 specs with 100.0% coverage.
* 9 fuzz tests with 12.4% coverage.

With 2,956 lines, that's about 1.7 tests per line, or 2.0 generated tests per line.
With 2,970 lines, that's about 1.7 tests per line, or 2.0 generated tests per line.

***Meet your new state machine library.***

Expand Down
2 changes: 1 addition & 1 deletion dist/deno/jssm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ declare class Machine<mDT> {
_timeout_handle: number | undefined;
_timeout_target: string | undefined;
_timeout_target_time: number | undefined;
constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }: JssmGenericConfig<StateType, mDT>);
constructor({ start_states, end_states, initial_state, start_states_no_enforce, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }: JssmGenericConfig<StateType, mDT>);
/********
*
* Internal method for fabricating states. Not meant for external use.
Expand Down
2 changes: 1 addition & 1 deletion dist/deno/jssm.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/deno/jssm_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ declare type JssmGenericConfig<StateType, DataType> = {
dot_preamble?: string;
start_states: Array<StateType>;
end_states?: Array<StateType>;
initial_state?: StateType;
start_states_no_enforce?: boolean;
state_declaration?: Object[];
property_definition?: JssmPropertyDefinition[];
state_property?: JssmPropertyDefinition[];
Expand Down
2 changes: 1 addition & 1 deletion dist/es6/jssm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ declare class Machine<mDT> {
_timeout_handle: number | undefined;
_timeout_target: string | undefined;
_timeout_target_time: number | undefined;
constructor({ start_states, end_states, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }: JssmGenericConfig<StateType, mDT>);
constructor({ start_states, end_states, initial_state, start_states_no_enforce, complete, transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble, arrange_declaration, arrange_start_declaration, arrange_end_declaration, theme, flow, graph_layout, instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }: JssmGenericConfig<StateType, mDT>);
/********
*
* Internal method for fabricating states. Not meant for external use.
Expand Down
16 changes: 14 additions & 2 deletions dist/es6/jssm.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ function state_style_condense(jssk) {
// TODO add a lotta docblock here
class Machine {
// whargarbl this badly needs to be broken up, monolith master
constructor({ start_states, end_states = [], complete = [], transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = ['default'], flow = 'down', graph_layout = 'dot', instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }) {
constructor({ start_states, end_states = [], initial_state, start_states_no_enforce, complete = [], transitions, machine_author, machine_comment, machine_contributor, machine_definition, machine_language, machine_license, machine_name, machine_version, state_declaration, property_definition, state_property, fsl_version, dot_preamble = undefined, arrange_declaration = [], arrange_start_declaration = [], arrange_end_declaration = [], theme = ['default'], flow = 'down', graph_layout = 'dot', instance_name, history, data, default_state_config, default_active_state_config, default_hooked_state_config, default_terminal_state_config, default_start_state_config, default_end_state_config, allows_override, config_allows_override, rng_seed, time_source, timeout_source, clear_timeout_source }) {
this._time_source = () => new Date().getTime();
this._create_started = this._time_source();
this._instance_name = instance_name;
this._state = start_states[0];
this._states = new Map();
this._state_declarations = new Map();
this._edges = [];
Expand Down Expand Up @@ -352,6 +351,19 @@ class Machine {
this._state_properties.set(sp.name, sp.default_value);
});
}
// set initial state either from the specified or the start state list. validate admission behavior.
if (initial_state) {
if (!(this._states.has(initial_state))) {
throw new JssmError(this, `requested start state ${initial_state} does not exist`);
}
if ((!(start_states_no_enforce)) && (!(start_states.includes(initial_state)))) {
throw new JssmError(this, `requested start state ${initial_state} is not in start state list; add {start_states_no_enforce:true} to constructor options if desired`);
}
this._state = initial_state;
}
else {
this._state = start_states[0];
}
// done building, do checks
// assert all props are valid
this._state_properties.forEach((_value, key) => {
Expand Down
2 changes: 2 additions & 0 deletions dist/es6/jssm_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ declare type JssmGenericConfig<StateType, DataType> = {
dot_preamble?: string;
start_states: Array<StateType>;
end_states?: Array<StateType>;
initial_state?: StateType;
start_states_no_enforce?: boolean;
state_declaration?: Object[];
property_definition?: JssmPropertyDefinition[];
state_property?: JssmPropertyDefinition[];
Expand Down
2 changes: 1 addition & 1 deletion dist/es6/version.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const version = "5.97.1", build_time = 1707173654610;
const version = "5.98.0", build_time = 1711419354245;
export { version, build_time };
2 changes: 1 addition & 1 deletion dist/jssm.es5.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/jssm.es5.iife.cjs

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions dist/jssm.es5.iife.nonmin.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions dist/jssm.es5.nonmin.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/jssm.es6.mjs

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions dist/jssm.es6.nonmin.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/docs/assets/search.js

Large diffs are not rendered by default.

88 changes: 44 additions & 44 deletions docs/docs/classes/jssm.Machine.html

Large diffs are not rendered by default.

Loading

0 comments on commit b2d953d

Please sign in to comment.