Skip to content

Commit

Permalink
fix(demo/fsm): context object
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm authored and AliMD committed Mar 1, 2023
1 parent 823377e commit 1fa8aac
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions demo/finite-state-machine/light-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {FiniteStateMachine} from '@alwatr/fsm';
const lightMachine = new FiniteStateMachine({
id: 'light-machine',
initial: 'green',
context: <number>0,
context: {
a: <number> 0,
b: <number> 0,
},
states: {
$all: {
on: {
Expand Down Expand Up @@ -37,9 +40,9 @@ lightMachine.signal.subscribe((state) => {
console.log('****\nstate: %s, context: %s\n****', state, lightMachine.context);
}, {receivePrevious: 'No'});

lightMachine.transition('TIMER', 1);
lightMachine.transition('TIMER', 2);
lightMachine.transition('TIMER', 3);
lightMachine.transition('POWER_LOST', 4);
lightMachine.transition('TIMER', 5);
lightMachine.transition('POWER_BACK', 6);
lightMachine.transition('TIMER', {a: 1});
lightMachine.transition('TIMER', {b: 2});
lightMachine.transition('TIMER');
lightMachine.transition('POWER_LOST', {a: 4});
lightMachine.transition('TIMER', {a: 5, b: 5});
lightMachine.transition('POWER_BACK', {a: 6});

0 comments on commit 1fa8aac

Please sign in to comment.