Skip to content

Commit

Permalink
Use normalized StateNode instead of raw config (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucmartens authored Aug 28, 2018
1 parent 246d5bd commit 1424d6a
Show file tree
Hide file tree
Showing 26 changed files with 332 additions and 848 deletions.
41 changes: 17 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Convert a [xstate](https://github.com/davidkpiano/xstate) or [react-automata](https://github.com/MicheleBertoli/react-automata) statechart to a [plantuml](http://plantuml.com/state-diagram) state diagram

## Installation

```
npm install xstate-plantuml
```
Expand All @@ -17,11 +18,6 @@ const config = {
initial: 'green',
states: {
green: {
on: {
TIMER: 'yellow'
}
},
yellow: {
on: {
TIMER: 'red'
}
Expand All @@ -34,24 +30,21 @@ const config = {
}
};

console.log(convert(config));
convert(config, options);
```

## Supports

- [x] Single machine
- [x] Parallel machine
- [x] Hierarchical machine
- [ ] History machine
- [x] Initial event
- [x] Internal string events `{on: {x: '.y'}}`
- [x] Internal obj events `{on {x: {target: 'y'}}}`
- [x] String event `{on: {x: 'y'}}`
- [x] Object event `{on: {x: {y: {}}}}`
- [x] Array event `{on: {x: [{target: 'y'}]}}`
- [x] String action `fetch`
- [ ] Object action `{ type: 'fetch'}`
- [ ] Function action
- [x] `onEntry` actions
- [x] `onExit` actions
- [ ] `transition` actions
## Examples

### Hierarchical machine

- [json](./examples/alarm.json)
- [puml](./examples/alarm.puml)

![alarm](./examples/alarm.png)

### Parallel machine

- [json](./examples/parallel.json)
- [puml](./examples/parallel.puml)

![parallel](./examples/parallel.png)
17 changes: 17 additions & 0 deletions examples/alarm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"key": "alarm",
"initial": "inactive",
"states": {
"inactive": { "on": { "ENABLE": "active.waiting" } },
"active": {
"states": {
"snoozing": { "on": { "TIMER": "beeping" } },
"waiting": { "on": { "TIMER": "beeping" } },
"beeping": { "on": { "SNOOZE": "snoozing" } }
},
"on": {
"DISABLE": "inactive"
}
}
}
}
Binary file added examples/alarm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions examples/alarm.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@startuml
left to right direction
state "alarm" as alarm {
[*] --> alarm.inactive

state "inactive" as alarm.inactive {
alarm.inactive --> alarm.active.waiting : ENABLE
}

state "active" as alarm.active {
alarm.active --> alarm.inactive : DISABLE
state "snoozing" as alarm.active.snoozing {
alarm.active.snoozing --> alarm.active.beeping : TIMER
}

state "waiting" as alarm.active.waiting {
alarm.active.waiting --> alarm.active.beeping : TIMER
}

state "beeping" as alarm.active.beeping {
alarm.active.beeping --> alarm.active.snoozing : SNOOZE
}
}
}
@enduml
44 changes: 0 additions & 44 deletions examples/hierarchical.js

This file was deleted.

Binary file removed examples/hierarchical.png
Binary file not shown.
18 changes: 0 additions & 18 deletions examples/hierarchical.puml

This file was deleted.

57 changes: 0 additions & 57 deletions examples/parallel.js

This file was deleted.

37 changes: 37 additions & 0 deletions examples/parallel.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"key": "wordmachine",
"parallel": true,
"states": {
"bold": {
"initial": "off",
"states": {
"on": { "on": { "TOGGLE_BOLD": "off" } },
"off": { "on": { "TOGGLE_BOLD": "on" } }
}
},
"underline": {
"initial": "off",
"states": {
"on": { "on": { "TOGGLE_UNDERLINE": "off" } },
"off": { "on": { "TOGGLE_UNDERLINE": "on" } }
}
},
"italics": {
"initial": "off",
"states": {
"on": { "on": { "TOGGLE_ITALICS": "off" } },
"off": { "on": { "TOGGLE_ITALICS": "on" } }
}
},
"list": {
"initial": "none",
"states": {
"none": {
"on": { "BULLETS": "bullets", "NUMBERS": "numbers" }
},
"bullets": { "on": { "NONE": "none", "NUMBERS": "numbers" } },
"numbers": { "on": { "BULLETS": "bullets", "NONE": "none" } }
}
}
}
}
Binary file modified examples/parallel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 56 additions & 32 deletions examples/parallel.puml
Original file line number Diff line number Diff line change
@@ -1,35 +1,59 @@
@startuml
state "bold" as bold {
state "on" as bold_on
state "off" as bold_off
[*] --> bold_off
bold_on --> bold_off : TOGGLE_BOLD
bold_off --> bold_on : TOGGLE_BOLD
}
state "underline" as underline {
state "on" as underline_on
state "off" as underline_off
[*] --> underline_off
underline_on --> underline_off : TOGGLE_UNDERLINE
underline_off --> underline_on : TOGGLE_UNDERLINE
}
state "italics" as italics {
state "on" as italics_on
state "off" as italics_off
[*] --> italics_off
italics_on --> italics_off : TOGGLE_ITALICS
italics_off --> italics_on : TOGGLE_ITALICS
}
state "list" as list {
state "none" as list_none
state "bullets" as list_bullets
state "numbers" as list_numbers
[*] --> list_none
list_none --> list_bullets : BULLETS
list_none --> list_numbers : NUMBERS
list_bullets --> list_none : NONE
list_bullets --> list_numbers : NUMBERS
list_numbers --> list_bullets : BULLETS
list_numbers --> list_none : NONE
left to right direction
state "wordmachine" as wordmachine {
state "bold" as wordmachine.bold {
[*] --> wordmachine.bold.off

state "on" as wordmachine.bold.on {
wordmachine.bold.on --> wordmachine.bold.off : TOGGLE_BOLD
}

state "off" as wordmachine.bold.off {
wordmachine.bold.off --> wordmachine.bold.on : TOGGLE_BOLD
}
}

state "underline" as wordmachine.underline {
[*] --> wordmachine.underline.off

state "on" as wordmachine.underline.on {
wordmachine.underline.on --> wordmachine.underline.off : TOGGLE_UNDERLINE
}

state "off" as wordmachine.underline.off {
wordmachine.underline.off --> wordmachine.underline.on : TOGGLE_UNDERLINE
}
}

state "italics" as wordmachine.italics {
[*] --> wordmachine.italics.off

state "on" as wordmachine.italics.on {
wordmachine.italics.on --> wordmachine.italics.off : TOGGLE_ITALICS
}

state "off" as wordmachine.italics.off {
wordmachine.italics.off --> wordmachine.italics.on : TOGGLE_ITALICS
}
}

state "list" as wordmachine.list {
[*] --> wordmachine.list.none

state "none" as wordmachine.list.none {
wordmachine.list.none --> wordmachine.list.bullets : BULLETS
wordmachine.list.none --> wordmachine.list.numbers : NUMBERS
}

state "bullets" as wordmachine.list.bullets {
wordmachine.list.bullets --> wordmachine.list.none : NONE
wordmachine.list.bullets --> wordmachine.list.numbers : NUMBERS
}

state "numbers" as wordmachine.list.numbers {
wordmachine.list.numbers --> wordmachine.list.bullets : BULLETS
wordmachine.list.numbers --> wordmachine.list.none : NONE
}
}
}
@enduml
26 changes: 0 additions & 26 deletions examples/simple.js

This file was deleted.

Binary file removed examples/simple.png
Binary file not shown.
11 changes: 0 additions & 11 deletions examples/simple.puml

This file was deleted.

Loading

0 comments on commit 1424d6a

Please sign in to comment.