Skip to content

Commit

Permalink
Document list_edges, list_transitions, list_entrances, list_exits, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed May 22, 2022
1 parent 8809458 commit 86eeb1e
Show file tree
Hide file tree
Showing 4 changed files with 16,301 additions and 1 deletion.
16,086 changes: 16,085 additions & 1 deletion dist/es6/jssm-dot.js

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions dist/es6/jssm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,81 @@ declare class Machine<mDT> {
*
*/
has_state(whichState: StateType): boolean;
/*********
*
* Lists all edges of a machine.
*
* ```typescript
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
*
* lswitch.list_edges();
* [
* {
* from: 'on',
* to: 'off',
* kind: 'main',
* forced_only: false,
* main_path: true,
* action: 'toggle'
* },
* {
* from: 'off',
* to: 'on',
* kind: 'main',
* forced_only: false,
* main_path: true,
* action: 'toggle'
* }
* ]
* ```
*
*/
list_edges(): Array<JssmTransition<mDT>>;
list_named_transitions(): Map<StateType, number>;
list_actions(): Array<StateType>;
theme(): FslTheme;
flow(): FslDirection;
get_transition_by_state_names(from: StateType, to: StateType): number;
lookup_transition_for(from: StateType, to: StateType): JssmTransition<mDT>;
/********
*
* List all transitions attached to the current state, sorted by entrance and
* exit. The order of each sublist is not defined. A node could appear in
* both lists.
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_transitions(); // { entrances: [ 'yellow', 'off' ], exits: [ 'green', 'off' ] }
*
*/
list_transitions(whichState?: StateType): JssmTransitionList;
/********
*
* List all entrances attached to the current state. Please note that the
* order of the list is not defined.
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_entrances(); // [ 'yellow', 'off' ]
*
*/
list_entrances(whichState?: StateType): Array<StateType>;
/********
*
* List all exits attached to the current state. Please note that the order
* of the list is not defined.
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_exits(); // [ 'green', 'off' ]
*
*/
list_exits(whichState?: StateType): Array<StateType>;
probable_exits_for(whichState: StateType): Array<JssmTransition<mDT>>;
probabilistic_transition(): boolean;
Expand Down
66 changes: 66 additions & 0 deletions dist/es6/jssm.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,35 @@ class Machine {
has_state(whichState) {
return this._states.get(whichState) !== undefined;
}
/*********
*
* Lists all edges of a machine.
*
* ```typescript
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
*
* lswitch.list_edges();
* [
* {
* from: 'on',
* to: 'off',
* kind: 'main',
* forced_only: false,
* main_path: true,
* action: 'toggle'
* },
* {
* from: 'off',
* to: 'on',
* kind: 'main',
* forced_only: false,
* main_path: true,
* action: 'toggle'
* }
* ]
* ```
*
*/
list_edges() {
return this._edges;
}
Expand Down Expand Up @@ -848,14 +877,51 @@ class Machine {
const id = this.get_transition_by_state_names(from, to);
return ((id === undefined) || (id === null)) ? undefined : this._edges[id];
}
/********
*
* List all transitions attached to the current state, sorted by entrance and
* exit. The order of each sublist is not defined. A node could appear in
* both lists.
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_transitions(); // { entrances: [ 'yellow', 'off' ], exits: [ 'green', 'off' ] }
*
*/
list_transitions(whichState = this.state()) {
return { entrances: this.list_entrances(whichState), exits: this.list_exits(whichState) };
}
/********
*
* List all entrances attached to the current state. Please note that the
* order of the list is not defined.
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_entrances(); // [ 'yellow', 'off' ]
*
*/
list_entrances(whichState = this.state()) {
return (this._states.get(whichState)
|| { from: undefined }).from
|| [];
}
/********
*
* List all exits attached to the current state. Please note that the order
* of the list is not defined.
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_exits(); // [ 'green', 'off' ]
*
*/
list_exits(whichState = this.state()) {
return (this._states.get(whichState)
|| { to: undefined }).to
Expand Down
84 changes: 84 additions & 0 deletions src/ts/jssm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,38 @@ class Machine<mDT> {





/*********
*
* Lists all edges of a machine.
*
* ```typescript
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
*
* lswitch.list_edges();
* [
* {
* from: 'on',
* to: 'off',
* kind: 'main',
* forced_only: false,
* main_path: true,
* action: 'toggle'
* },
* {
* from: 'off',
* to: 'on',
* kind: 'main',
* forced_only: false,
* main_path: true,
* action: 'toggle'
* }
* ]
* ```
*
*/

list_edges(): Array<JssmTransition<mDT>> {
return this._edges;
}
Expand Down Expand Up @@ -1196,16 +1228,66 @@ class Machine<mDT> {





/********
*
* List all transitions attached to the current state, sorted by entrance and
* exit. The order of each sublist is not defined. A node could appear in
* both lists.
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_transitions(); // { entrances: [ 'yellow', 'off' ], exits: [ 'green', 'off' ] }
*
*/

list_transitions(whichState: StateType = this.state()): JssmTransitionList {
return { entrances: this.list_entrances(whichState), exits: this.list_exits(whichState) };
}





/********
*
* List all entrances attached to the current state. Please note that the
* order of the list is not defined.
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_entrances(); // [ 'yellow', 'off' ]
*
*/

list_entrances(whichState: StateType = this.state()): Array<StateType> {
return (this._states.get(whichState)
|| { from: undefined }).from
|| [];
}





/********
*
* List all exits attached to the current state. Please note that the order
* of the list is not defined.
*
* const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
* const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
*
* light.state(); // 'red'
* light.list_exits(); // [ 'green', 'off' ]
*
*/

list_exits(whichState: StateType = this.state()): Array<StateType> {
return (this._states.get(whichState)
|| { to: undefined }).to
Expand All @@ -1214,6 +1296,8 @@ class Machine<mDT> {





probable_exits_for(whichState: StateType): Array<JssmTransition<mDT>> {

const wstate: JssmGenericState = this._states.get(whichState);
Expand Down

0 comments on commit 86eeb1e

Please sign in to comment.