Skip to content

Commit

Permalink
Update nested docs to reflect dontWalk should be final state
Browse files Browse the repository at this point in the history
Based on feedback from #77. Closes #77
  • Loading branch information
matthewpblog committed Nov 9, 2019
1 parent 056d0e8 commit 4f7f927
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions docs/guides/nested-states.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ An example of a nested state machine is a crosswalk light. You give the ✋ when
In Robot nested state machines are represented as separate [machines](../api/createMachine.html) with [invoke](../api/invoke.html) used to enter the child machine.

```js
import { createMachine, invoke, state, transition } from 'robot3';
import { createMachine, invoke, state, transition, state as final } from 'robot3';

const stopwalk = createMachine({
walk: state(
transition('toggle', 'dontWalk')
),
dontWalk: state(
transition('toggle', 'walk')
)
dontWalk: final()
});

const stoplight = createMachine({
Expand All @@ -47,7 +45,20 @@ console.log(service.machine.current); // yellow
service.send('next');
console.log(service.machine.current); // red

let child = service.send;
let child = service.child;
console.log(child.machine.current); // walk

child.send('toggle');
console.log(child.machine.current); // dontWalk
console.log(service.machine.current); // green

service.send('next');
console.log(service.machine.current); // yellow

service.send('next');
console.log(service.machine.current); // red

child = service.child;
console.log(child.machine.current); // walk

child.send('toggle');
Expand Down Expand Up @@ -76,9 +87,7 @@ const stoplight = createMachine({
walk: state(
transition('toggle', 'dontWalk')
),
dontWalk: state(
transition('toggle', 'walk')
)
dontWalk: final()
})
});
```

0 comments on commit 4f7f927

Please sign in to comment.