Last active
February 21, 2020 16:52
-
-
Save andrewgordstewart/319012b0c128bac986cf8da0f4003ca9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const machine = Machine({ | |
id: 'stepMachine', | |
initial: 'step1', | |
on: { | |
// Accepted in step1, step2 or step3 | |
FINISH_MACHINE: 'step3' | |
}, | |
states: { | |
step1: { | |
initial: 'a', | |
on: { | |
// Accepted in state step1.a, step1.b, or step1.c | |
// Targets state c relative to a | |
RELATIVE_JUMP: '.c' | |
}, | |
states: { | |
a: { | |
on: { | |
// Accepted in state step1.a | |
NEXT: 'b' | |
} | |
}, | |
b: { | |
invoke: { | |
src: 'someService', | |
// Built in events | |
onDone: 'c', | |
// Target a node's (default) id | |
onError: '#stepMachine.error' | |
} | |
}, | |
c: { | |
on: { | |
// Accepted in state step1.c | |
// Target a node's custom id | |
ABSOLUTE_JUMP: '#customId' | |
} | |
} | |
} | |
}, | |
step2: { | |
id: 'customId', | |
type: 'parallel', | |
on: { | |
// Accepted in state step2 | |
// Targets multiple | |
FINISH_LEFT: {target: ['.left.c']}, | |
FINISH_RIGHT: {target: ['.right.c']}, | |
FINISH_BOTH: {target: ['.left.c', '.right.c']} | |
}, | |
states: { | |
left: { | |
initial: 'a', | |
states: { | |
a: {on: {NEXT_LEFT: 'b'}}, | |
b: {on: {NEXT_LEFT: 'c'}}, | |
c: {type: 'final'} | |
} | |
}, | |
right: { | |
initial: 'a', | |
states: { | |
a: {on: {NEXT_RIGHT: 'b'}}, | |
b: {on: {NEXT_RIGHT: 'c'}}, | |
c: {type: 'final'} | |
} | |
} | |
}, | |
onDone: 'step3' | |
}, | |
step3: {type: 'final'}, | |
error: {} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment