Skip to content

Commit

Permalink
Add conversion examples (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucmartens authored Aug 25, 2018
1 parent 2fed5f2 commit 246d5bd
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 0 deletions.
44 changes: 44 additions & 0 deletions examples/hierarchical.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const fs = require('fs');
const convert = require('../src/index').default;

const pedestrianStates = {
initial: 'walk',
states: {
walk: {
on: {
PED_TIMER: 'wait'
}
},
wait: {
on: {
PED_TIMER: 'stop'
}
},
stop: {}
}
};

const lightMachine = {
key: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: 'yellow'
}
},
yellow: {
on: {
TIMER: 'red'
}
},
red: {
on: {
TIMER: 'green'
},
...pedestrianStates
}
}
};

fs.writeFileSync('examples/hierarchical.puml', convert(lightMachine));
Binary file added examples/hierarchical.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions examples/hierarchical.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@startuml
state "light" as light {
state "green" as light_green
state "yellow" as light_yellow
[*] --> light_green
light_green --> light_yellow : TIMER
light_yellow --> light_red : TIMER
light_red --> light_green : TIMER
state "red" as light_red {
state "walk" as red_walk
state "wait" as red_wait
state "stop" as red_stop
[*] --> red_walk
red_walk --> red_wait : PED_TIMER
red_wait --> red_stop : PED_TIMER
}
}
@enduml
57 changes: 57 additions & 0 deletions examples/parallel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
const fs = require('fs');
const convert = require('../src/index').default;

const 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' }
}
}
}
}
};

fs.writeFileSync('examples/parallel.puml', convert(wordMachine));
Binary file added 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.
35 changes: 35 additions & 0 deletions examples/parallel.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@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
}
@enduml
26 changes: 26 additions & 0 deletions examples/simple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require('fs');
const convert = require('../src/index').default;

const lightMachine = {
key: 'light',
initial: 'green',
states: {
green: {
on: {
TIMER: 'yellow'
}
},
yellow: {
on: {
TIMER: 'red'
}
},
red: {
on: {
TIMER: 'green'
}
}
}
};

fs.writeFileSync('examples/simple.puml', convert(lightMachine));
Binary file added examples/simple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions examples/simple.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@startuml
state "light" as light {
state "green" as light_green
state "yellow" as light_yellow
state "red" as light_red
[*] --> light_green
light_green --> light_yellow : TIMER
light_yellow --> light_red : TIMER
light_red --> light_green : TIMER
}
@enduml

0 comments on commit 246d5bd

Please sign in to comment.