jssm 5.65.9 → 5.65.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ import { version } from './version';
9
9
  * Return the direction of an arrow - `right`, `left`, or `both`.
10
10
  *
11
11
  * ```typescript
12
- * import { arrow_direction } from './jssm';
12
+ * import { arrow_direction } from 'jssm';
13
13
  *
14
14
  * arrow_direction('->'); // 'right'
15
15
  * arrow_direction('<~=>'); // 'both'
@@ -22,7 +22,7 @@ declare function arrow_direction(arrow: JssmArrow): JssmArrowDirection;
22
22
  * Return the direction of an arrow - `right`, `left`, or `both`.
23
23
  *
24
24
  * ```typescript
25
- * import { arrow_left_kind } from './jssm';
25
+ * import { arrow_left_kind } from 'jssm';
26
26
  *
27
27
  * arrow_left_kind('<-'); // 'legal'
28
28
  * arrow_left_kind('<='); // 'main'
@@ -38,7 +38,7 @@ declare function arrow_left_kind(arrow: JssmArrow): JssmArrowKind;
38
38
  * Return the direction of an arrow - `right`, `left`, or `both`.
39
39
  *
40
40
  * ```typescript
41
- * import { arrow_left_kind } from './jssm';
41
+ * import { arrow_left_kind } from 'jssm';
42
42
  *
43
43
  * arrow_left_kind('->'); // 'legal'
44
44
  * arrow_left_kind('=>'); // 'main'
@@ -60,7 +60,7 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
60
60
  * probably also using {@link compile} and {@link Machine.constructor}.
61
61
  *
62
62
  * ```typescript
63
- * import { parse, compile, Machine } from './jssm';
63
+ * import { parse, compile, Machine } from 'jssm';
64
64
  *
65
65
  * const intermediate = wrap_parse('a -> b;', {});
66
66
  * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
@@ -85,7 +85,7 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
85
85
  * Operator {@link sm}:
86
86
  *
87
87
  * ```typescript
88
- * import { sm } from './jssm';
88
+ * import { sm } from 'jssm';
89
89
  *
90
90
  * const switch = sm`on <=> off;`;
91
91
  * ```
@@ -93,7 +93,7 @@ declare function arrow_right_kind(arrow: JssmArrow): JssmArrowKind;
93
93
  * Method {@link from}:
94
94
  *
95
95
  * ```typescript
96
- * import * as jssm from './jssm';
96
+ * import * as jssm from 'jssm';
97
97
  *
98
98
  * const toggle = jssm.from('up <=> down;');
99
99
  * ```
@@ -111,7 +111,7 @@ declare function wrap_parse(input: string, options?: Object): any;
111
111
  * {@link Machine.construct} to turn the config object into a workable machine.
112
112
  *
113
113
  * ```typescript
114
- * import { parse, compile, Machine } from './jssm';
114
+ * import { parse, compile, Machine } from 'jssm';
115
115
  *
116
116
  * const intermediate = parse('a -> b;');
117
117
  * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
@@ -136,7 +136,7 @@ declare function wrap_parse(input: string, options?: Object): any;
136
136
  * Operator {@link sm}:
137
137
  *
138
138
  * ```typescript
139
- * import { sm } from './jssm';
139
+ * import { sm } from 'jssm';
140
140
  *
141
141
  * const switch = sm`on <=> off;`;
142
142
  * ```
@@ -144,7 +144,7 @@ declare function wrap_parse(input: string, options?: Object): any;
144
144
  * Method {@link from}:
145
145
  *
146
146
  * ```typescript
147
- * import * as jssm from './jssm';
147
+ * import * as jssm from 'jssm';
148
148
  *
149
149
  * const toggle = jssm.from('up <=> down;');
150
150
  * ```
@@ -224,7 +224,7 @@ declare class Machine<mDT> {
224
224
  * Get the current state of a machine.
225
225
  *
226
226
  * ```typescript
227
- * import * as jssm from './jssm';
227
+ * import * as jssm from 'jssm';
228
228
  *
229
229
  * const switch = jssm.from('on <=> off;');
230
230
  * console.log( switch.state() ); // 'on'
@@ -241,7 +241,7 @@ declare class Machine<mDT> {
241
241
  * `complete`.)
242
242
  *
243
243
  * ```typescript
244
- * import { sm, state_is_final } from './jssm';
244
+ * import { sm, state_is_final } from 'jssm';
245
245
  *
246
246
  * const final_test = sm`first -> second;`;
247
247
  *
@@ -257,7 +257,7 @@ declare class Machine<mDT> {
257
257
  * `complete`.)
258
258
  *
259
259
  * ```typescript
260
- * import { sm, state_is_final } from './jssm';
260
+ * import { sm, state_is_final } from 'jssm';
261
261
  *
262
262
  * const final_test = sm`first -> second;`;
263
263
  *
@@ -289,7 +289,7 @@ declare class Machine<mDT> {
289
289
  * these states is not guaranteed.
290
290
  *
291
291
  * ```typescript
292
- * import * as jssm from './jssm';
292
+ * import * as jssm from 'jssm';
293
293
  *
294
294
  * const switch = jssm.from('on <=> off;');
295
295
  * console.log( switch.states() ); // ['on', 'off']
@@ -303,16 +303,47 @@ declare class Machine<mDT> {
303
303
  * Check whether the machine knows a given state.
304
304
  *
305
305
  * ```typescript
306
- * import * as jssm from './jssm';
306
+ * import * as jssm from 'jssm';
307
307
  *
308
308
  * const switch = jssm.from('on <=> off;');
309
-
309
+ *
310
310
  * console.log( switch.has_state('off') ); // true
311
311
  * console.log( switch.has_state('dance') ); // false
312
312
  * ```
313
313
  *
314
314
  */
315
315
  has_state(whichState: StateType): boolean;
316
+ /*********
317
+ *
318
+ * Lists all edges of a machine.
319
+ *
320
+ * ```typescript
321
+ * import { sm } from 'jssm';
322
+ *
323
+ * const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
324
+ *
325
+ * lswitch.list_edges();
326
+ * [
327
+ * {
328
+ * from: 'on',
329
+ * to: 'off',
330
+ * kind: 'main',
331
+ * forced_only: false,
332
+ * main_path: true,
333
+ * action: 'toggle'
334
+ * },
335
+ * {
336
+ * from: 'off',
337
+ * to: 'on',
338
+ * kind: 'main',
339
+ * forced_only: false,
340
+ * main_path: true,
341
+ * action: 'toggle'
342
+ * }
343
+ * ]
344
+ * ```
345
+ *
346
+ */
316
347
  list_edges(): Array<JssmTransition<mDT>>;
317
348
  list_named_transitions(): Map<StateType, number>;
318
349
  list_actions(): Array<StateType>;
@@ -320,14 +351,108 @@ declare class Machine<mDT> {
320
351
  flow(): FslDirection;
321
352
  get_transition_by_state_names(from: StateType, to: StateType): number;
322
353
  lookup_transition_for(from: StateType, to: StateType): JssmTransition<mDT>;
354
+ /********
355
+ *
356
+ * List all transitions attached to the current state, sorted by entrance and
357
+ * exit. The order of each sublist is not defined. A node could appear in
358
+ * both lists.
359
+ *
360
+ * ```typescript
361
+ * import { sm } from 'jssm';
362
+ *
363
+ * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
364
+ *
365
+ * light.state(); // 'red'
366
+ * light.list_transitions(); // { entrances: [ 'yellow', 'off' ], exits: [ 'green', 'off' ] }
367
+ * ```
368
+ *
369
+ */
323
370
  list_transitions(whichState?: StateType): JssmTransitionList;
371
+ /********
372
+ *
373
+ * List all entrances attached to the current state. Please note that the
374
+ * order of the list is not defined.
375
+ *
376
+ * ```typescript
377
+ * import { sm } from 'jssm';
378
+ *
379
+ * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
380
+ *
381
+ * light.state(); // 'red'
382
+ * light.list_entrances(); // [ 'yellow', 'off' ]
383
+ * ```
384
+ *
385
+ */
324
386
  list_entrances(whichState?: StateType): Array<StateType>;
387
+ /********
388
+ *
389
+ * List all exits attached to the current state. Please note that the order
390
+ * of the list is not defined.
391
+ *
392
+ * ```typescript
393
+ * import { sm } from 'jssm';
394
+ *
395
+ * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
396
+ *
397
+ * light.state(); // 'red'
398
+ * light.list_exits(); // [ 'green', 'off' ]
399
+ * ```
400
+ *
401
+ */
325
402
  list_exits(whichState?: StateType): Array<StateType>;
326
403
  probable_exits_for(whichState: StateType): Array<JssmTransition<mDT>>;
327
404
  probabilistic_transition(): boolean;
328
405
  probabilistic_walk(n: number): Array<StateType>;
329
406
  probabilistic_histo_walk(n: number): Map<StateType, number>;
407
+ /********
408
+ *
409
+ * List all actions available from this state. Please note that the order of
410
+ * the actions is not guaranteed.
411
+ *
412
+ * ```typescript
413
+ * import { sm } from 'jssm';
414
+ *
415
+ * const machine = sm`
416
+ * red 'next' -> green 'next' -> yellow 'next' -> red;
417
+ * [red yellow green] 'shutdown' ~> off 'start' -> red;
418
+ * `;
419
+ *
420
+ * console.log( machine.state() ); // logs 'red'
421
+ * console.log( machine.actions() ); // logs ['next', 'shutdown']
422
+ *
423
+ * machine.action('next'); // true
424
+ * console.log( machine.state() ); // logs 'green'
425
+ * console.log( machine.actions() ); // logs ['next', 'shutdown']
426
+ *
427
+ * machine.action('shutdown'); // true
428
+ * console.log( machine.state() ); // logs 'off'
429
+ * console.log( machine.actions() ); // logs ['start']
430
+ *
431
+ * machine.action('start'); // true
432
+ * console.log( machine.state() ); // logs 'red'
433
+ * console.log( machine.actions() ); // logs ['next', 'shutdown']
434
+ * ```
435
+ *
436
+ */
330
437
  actions(whichState?: StateType): Array<StateType>;
438
+ /********
439
+ *
440
+ * List all states that have a specific action attached. Please note that
441
+ * the order of the states is not guaranteed.
442
+ *
443
+ * ```typescript
444
+ * import { sm } from 'jssm';
445
+ *
446
+ * const machine = sm`
447
+ * red 'next' -> green 'next' -> yellow 'next' -> red;
448
+ * [red yellow green] 'shutdown' ~> off 'start' -> red;
449
+ * `;
450
+ *
451
+ * console.log( machine.list_states_having_action('next') ); // ['red', 'green', 'yellow']
452
+ * console.log( machine.list_states_having_action('start') ); // ['off']
453
+ * ```
454
+ *
455
+ */
331
456
  list_states_having_action(whichState: StateType): Array<StateType>;
332
457
  list_exit_actions(whichState?: StateType): Array<StateType>;
333
458
  probable_action_exits(whichState?: StateType): Array<any>;
@@ -352,8 +477,50 @@ declare class Machine<mDT> {
352
477
  hook_exit(from: string, handler: HookHandler): Machine<mDT>;
353
478
  edges_between(from: string, to: string): JssmTransition<mDT>[];
354
479
  transition_impl(newStateOrAction: StateType, newData: mDT | undefined, wasForced: boolean, wasAction: boolean): boolean;
480
+ /********
481
+ *
482
+ * Instruct the machine to complete an action.
483
+ *
484
+ * ```typescript
485
+ * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
486
+ *
487
+ * light.state(); // 'red'
488
+ * light.action('next'); // true
489
+ * light.state(); // 'green'
490
+ * ```
491
+ *
492
+ */
355
493
  action(actionName: StateType, newData?: mDT): boolean;
494
+ /********
495
+ *
496
+ * Instruct the machine to complete a transition.
497
+ *
498
+ * ```typescript
499
+ * const light = sm`red -> green -> yellow -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
500
+ *
501
+ * light.state(); // 'red'
502
+ * light.transition('green'); // true
503
+ * light.state(); // 'green'
504
+ * ```
505
+ *
506
+ */
356
507
  transition(newState: StateType, newData?: mDT): boolean;
508
+ /********
509
+ *
510
+ * Instruct the machine to complete a forced transition (which will reject if
511
+ * called with a normal {@link transition} call.)
512
+ *
513
+ * ```typescript
514
+ * const light = sm`red -> green -> yellow -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
515
+ *
516
+ * light.state(); // 'red'
517
+ * light.transition('off'); // false
518
+ * light.state(); // 'red'
519
+ * light.force_transition('off'); // true
520
+ * light.state(); // 'off'
521
+ * ```
522
+ *
523
+ */
357
524
  force_transition(newState: StateType, newData?: mDT): boolean;
358
525
  current_action_for(action: StateType): number;
359
526
  current_action_edge_for(action: StateType): JssmTransition<mDT>;
@@ -374,7 +541,7 @@ declare class Machine<mDT> {
374
541
  *
375
542
  *
376
543
  * ```typescript
377
- * import * as jssm from './jssm';
544
+ * import * as jssm from 'jssm';
378
545
  *
379
546
  * const switch = jssm.from('on <=> off;');
380
547
  * ```
@@ -391,7 +558,7 @@ declare function sm<mDT>(template_strings: TemplateStringsArray, ...remainder: a
391
558
  * template expression.
392
559
  *
393
560
  * ```typescript
394
- * import * as jssm from './jssm';
561
+ * import * as jssm from 'jssm';
395
562
  *
396
563
  * const switch = jssm.from('on <=> off;');
397
564
  * ```
package/dist/es6/jssm.js CHANGED
@@ -11,7 +11,7 @@ import { JssmError } from './jssm_error';
11
11
  * Return the direction of an arrow - `right`, `left`, or `both`.
12
12
  *
13
13
  * ```typescript
14
- * import { arrow_direction } from './jssm';
14
+ * import { arrow_direction } from 'jssm';
15
15
  *
16
16
  * arrow_direction('->'); // 'right'
17
17
  * arrow_direction('<~=>'); // 'both'
@@ -76,7 +76,7 @@ function arrow_direction(arrow) {
76
76
  * Return the direction of an arrow - `right`, `left`, or `both`.
77
77
  *
78
78
  * ```typescript
79
- * import { arrow_left_kind } from './jssm';
79
+ * import { arrow_left_kind } from 'jssm';
80
80
  *
81
81
  * arrow_left_kind('<-'); // 'legal'
82
82
  * arrow_left_kind('<='); // 'main'
@@ -133,7 +133,7 @@ function arrow_left_kind(arrow) {
133
133
  * Return the direction of an arrow - `right`, `left`, or `both`.
134
134
  *
135
135
  * ```typescript
136
- * import { arrow_left_kind } from './jssm';
136
+ * import { arrow_left_kind } from 'jssm';
137
137
  *
138
138
  * arrow_left_kind('->'); // 'legal'
139
139
  * arrow_left_kind('=>'); // 'main'
@@ -231,7 +231,7 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
231
231
  * probably also using {@link compile} and {@link Machine.constructor}.
232
232
  *
233
233
  * ```typescript
234
- * import { parse, compile, Machine } from './jssm';
234
+ * import { parse, compile, Machine } from 'jssm';
235
235
  *
236
236
  * const intermediate = wrap_parse('a -> b;', {});
237
237
  * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
@@ -256,7 +256,7 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
256
256
  * Operator {@link sm}:
257
257
  *
258
258
  * ```typescript
259
- * import { sm } from './jssm';
259
+ * import { sm } from 'jssm';
260
260
  *
261
261
  * const switch = sm`on <=> off;`;
262
262
  * ```
@@ -264,7 +264,7 @@ function makeTransition(this_se, from, to, isRight, _wasList, _wasIndex) {
264
264
  * Method {@link from}:
265
265
  *
266
266
  * ```typescript
267
- * import * as jssm from './jssm';
267
+ * import * as jssm from 'jssm';
268
268
  *
269
269
  * const toggle = jssm.from('up <=> down;');
270
270
  * ```
@@ -356,7 +356,7 @@ function compile_rule_handler(rule) {
356
356
  * {@link Machine.construct} to turn the config object into a workable machine.
357
357
  *
358
358
  * ```typescript
359
- * import { parse, compile, Machine } from './jssm';
359
+ * import { parse, compile, Machine } from 'jssm';
360
360
  *
361
361
  * const intermediate = parse('a -> b;');
362
362
  * // [ {key:'transition', from:'a', se:{kind:'->',to:'b'}} ]
@@ -381,7 +381,7 @@ function compile_rule_handler(rule) {
381
381
  * Operator {@link sm}:
382
382
  *
383
383
  * ```typescript
384
- * import { sm } from './jssm';
384
+ * import { sm } from 'jssm';
385
385
  *
386
386
  * const switch = sm`on <=> off;`;
387
387
  * ```
@@ -389,7 +389,7 @@ function compile_rule_handler(rule) {
389
389
  * Method {@link from}:
390
390
  *
391
391
  * ```typescript
392
- * import * as jssm from './jssm';
392
+ * import * as jssm from 'jssm';
393
393
  *
394
394
  * const toggle = jssm.from('up <=> down;');
395
395
  * ```
@@ -660,7 +660,7 @@ class Machine {
660
660
  * Get the current state of a machine.
661
661
  *
662
662
  * ```typescript
663
- * import * as jssm from './jssm';
663
+ * import * as jssm from 'jssm';
664
664
  *
665
665
  * const switch = jssm.from('on <=> off;');
666
666
  * console.log( switch.state() ); // 'on'
@@ -686,7 +686,7 @@ class Machine {
686
686
  * `complete`.)
687
687
  *
688
688
  * ```typescript
689
- * import { sm, state_is_final } from './jssm';
689
+ * import { sm, state_is_final } from 'jssm';
690
690
  *
691
691
  * const final_test = sm`first -> second;`;
692
692
  *
@@ -704,7 +704,7 @@ class Machine {
704
704
  * `complete`.)
705
705
  *
706
706
  * ```typescript
707
- * import { sm, state_is_final } from './jssm';
707
+ * import { sm, state_is_final } from 'jssm';
708
708
  *
709
709
  * const final_test = sm`first -> second;`;
710
710
  *
@@ -784,7 +784,7 @@ class Machine {
784
784
  * these states is not guaranteed.
785
785
  *
786
786
  * ```typescript
787
- * import * as jssm from './jssm';
787
+ * import * as jssm from 'jssm';
788
788
  *
789
789
  * const switch = jssm.from('on <=> off;');
790
790
  * console.log( switch.states() ); // ['on', 'off']
@@ -808,10 +808,10 @@ class Machine {
808
808
  * Check whether the machine knows a given state.
809
809
  *
810
810
  * ```typescript
811
- * import * as jssm from './jssm';
811
+ * import * as jssm from 'jssm';
812
812
  *
813
813
  * const switch = jssm.from('on <=> off;');
814
-
814
+ *
815
815
  * console.log( switch.has_state('off') ); // true
816
816
  * console.log( switch.has_state('dance') ); // false
817
817
  * ```
@@ -820,6 +820,37 @@ class Machine {
820
820
  has_state(whichState) {
821
821
  return this._states.get(whichState) !== undefined;
822
822
  }
823
+ /*********
824
+ *
825
+ * Lists all edges of a machine.
826
+ *
827
+ * ```typescript
828
+ * import { sm } from 'jssm';
829
+ *
830
+ * const lswitch = sm`on 'toggle' <=> 'toggle' off;`;
831
+ *
832
+ * lswitch.list_edges();
833
+ * [
834
+ * {
835
+ * from: 'on',
836
+ * to: 'off',
837
+ * kind: 'main',
838
+ * forced_only: false,
839
+ * main_path: true,
840
+ * action: 'toggle'
841
+ * },
842
+ * {
843
+ * from: 'off',
844
+ * to: 'on',
845
+ * kind: 'main',
846
+ * forced_only: false,
847
+ * main_path: true,
848
+ * action: 'toggle'
849
+ * }
850
+ * ]
851
+ * ```
852
+ *
853
+ */
823
854
  list_edges() {
824
855
  return this._edges;
825
856
  }
@@ -848,14 +879,60 @@ class Machine {
848
879
  const id = this.get_transition_by_state_names(from, to);
849
880
  return ((id === undefined) || (id === null)) ? undefined : this._edges[id];
850
881
  }
882
+ /********
883
+ *
884
+ * List all transitions attached to the current state, sorted by entrance and
885
+ * exit. The order of each sublist is not defined. A node could appear in
886
+ * both lists.
887
+ *
888
+ * ```typescript
889
+ * import { sm } from 'jssm';
890
+ *
891
+ * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
892
+ *
893
+ * light.state(); // 'red'
894
+ * light.list_transitions(); // { entrances: [ 'yellow', 'off' ], exits: [ 'green', 'off' ] }
895
+ * ```
896
+ *
897
+ */
851
898
  list_transitions(whichState = this.state()) {
852
899
  return { entrances: this.list_entrances(whichState), exits: this.list_exits(whichState) };
853
900
  }
901
+ /********
902
+ *
903
+ * List all entrances attached to the current state. Please note that the
904
+ * order of the list is not defined.
905
+ *
906
+ * ```typescript
907
+ * import { sm } from 'jssm';
908
+ *
909
+ * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
910
+ *
911
+ * light.state(); // 'red'
912
+ * light.list_entrances(); // [ 'yellow', 'off' ]
913
+ * ```
914
+ *
915
+ */
854
916
  list_entrances(whichState = this.state()) {
855
917
  return (this._states.get(whichState)
856
918
  || { from: undefined }).from
857
919
  || [];
858
920
  }
921
+ /********
922
+ *
923
+ * List all exits attached to the current state. Please note that the order
924
+ * of the list is not defined.
925
+ *
926
+ * ```typescript
927
+ * import { sm } from 'jssm';
928
+ *
929
+ * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
930
+ *
931
+ * light.state(); // 'red'
932
+ * light.list_exits(); // [ 'green', 'off' ]
933
+ * ```
934
+ *
935
+ */
859
936
  list_exits(whichState = this.state()) {
860
937
  return (this._states.get(whichState)
861
938
  || { to: undefined }).to
@@ -887,6 +964,36 @@ class Machine {
887
964
  probabilistic_histo_walk(n) {
888
965
  return histograph(this.probabilistic_walk(n));
889
966
  }
967
+ /********
968
+ *
969
+ * List all actions available from this state. Please note that the order of
970
+ * the actions is not guaranteed.
971
+ *
972
+ * ```typescript
973
+ * import { sm } from 'jssm';
974
+ *
975
+ * const machine = sm`
976
+ * red 'next' -> green 'next' -> yellow 'next' -> red;
977
+ * [red yellow green] 'shutdown' ~> off 'start' -> red;
978
+ * `;
979
+ *
980
+ * console.log( machine.state() ); // logs 'red'
981
+ * console.log( machine.actions() ); // logs ['next', 'shutdown']
982
+ *
983
+ * machine.action('next'); // true
984
+ * console.log( machine.state() ); // logs 'green'
985
+ * console.log( machine.actions() ); // logs ['next', 'shutdown']
986
+ *
987
+ * machine.action('shutdown'); // true
988
+ * console.log( machine.state() ); // logs 'off'
989
+ * console.log( machine.actions() ); // logs ['start']
990
+ *
991
+ * machine.action('start'); // true
992
+ * console.log( machine.state() ); // logs 'red'
993
+ * console.log( machine.actions() ); // logs ['next', 'shutdown']
994
+ * ```
995
+ *
996
+ */
890
997
  actions(whichState = this.state()) {
891
998
  const wstate = this._reverse_actions.get(whichState);
892
999
  if (wstate) {
@@ -896,6 +1003,24 @@ class Machine {
896
1003
  throw new JssmError(this, `No such state ${JSON.stringify(whichState)}`);
897
1004
  }
898
1005
  }
1006
+ /********
1007
+ *
1008
+ * List all states that have a specific action attached. Please note that
1009
+ * the order of the states is not guaranteed.
1010
+ *
1011
+ * ```typescript
1012
+ * import { sm } from 'jssm';
1013
+ *
1014
+ * const machine = sm`
1015
+ * red 'next' -> green 'next' -> yellow 'next' -> red;
1016
+ * [red yellow green] 'shutdown' ~> off 'start' -> red;
1017
+ * `;
1018
+ *
1019
+ * console.log( machine.list_states_having_action('next') ); // ['red', 'green', 'yellow']
1020
+ * console.log( machine.list_states_having_action('start') ); // ['off']
1021
+ * ```
1022
+ *
1023
+ */
899
1024
  list_states_having_action(whichState) {
900
1025
  const wstate = this._actions.get(whichState);
901
1026
  if (wstate) {
@@ -1223,13 +1348,54 @@ class Machine {
1223
1348
  return false;
1224
1349
  }
1225
1350
  }
1351
+ /********
1352
+ *
1353
+ * Instruct the machine to complete an action.
1354
+ *
1355
+ * ```typescript
1356
+ * const light = sm`red 'next' -> green 'next' -> yellow 'next' -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
1357
+ *
1358
+ * light.state(); // 'red'
1359
+ * light.action('next'); // true
1360
+ * light.state(); // 'green'
1361
+ * ```
1362
+ *
1363
+ */
1226
1364
  action(actionName, newData) {
1227
1365
  return this.transition_impl(actionName, newData, false, true);
1228
1366
  }
1367
+ /********
1368
+ *
1369
+ * Instruct the machine to complete a transition.
1370
+ *
1371
+ * ```typescript
1372
+ * const light = sm`red -> green -> yellow -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
1373
+ *
1374
+ * light.state(); // 'red'
1375
+ * light.transition('green'); // true
1376
+ * light.state(); // 'green'
1377
+ * ```
1378
+ *
1379
+ */
1229
1380
  transition(newState, newData) {
1230
1381
  return this.transition_impl(newState, newData, false, false);
1231
1382
  }
1232
- // can leave machine in inconsistent state. generally do not use
1383
+ /********
1384
+ *
1385
+ * Instruct the machine to complete a forced transition (which will reject if
1386
+ * called with a normal {@link transition} call.)
1387
+ *
1388
+ * ```typescript
1389
+ * const light = sm`red -> green -> yellow -> red; [red yellow green] 'shutdown' ~> off 'start' -> red;`;
1390
+ *
1391
+ * light.state(); // 'red'
1392
+ * light.transition('off'); // false
1393
+ * light.state(); // 'red'
1394
+ * light.force_transition('off'); // true
1395
+ * light.state(); // 'off'
1396
+ * ```
1397
+ *
1398
+ */
1233
1399
  force_transition(newState, newData) {
1234
1400
  return this.transition_impl(newState, newData, true, false);
1235
1401
  }
@@ -1288,7 +1454,7 @@ class Machine {
1288
1454
  *
1289
1455
  *
1290
1456
  * ```typescript
1291
- * import * as jssm from './jssm';
1457
+ * import * as jssm from 'jssm';
1292
1458
  *
1293
1459
  * const switch = jssm.from('on <=> off;');
1294
1460
  * ```
@@ -1317,7 +1483,7 @@ function sm(template_strings, ...remainder /* , arguments */) {
1317
1483
  * template expression.
1318
1484
  *
1319
1485
  * ```typescript
1320
- * import * as jssm from './jssm';
1486
+ * import * as jssm from 'jssm';
1321
1487
  *
1322
1488
  * const switch = jssm.from('on <=> off;');
1323
1489
  * ```