Last active
November 28, 2020 15:55
-
-
Save AndresRodH/91f849789d3fd8b6e489b8a91021c018 to your computer and use it in GitHub Desktop.
Example 4
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 doTheThingMachine = Machine({ | |
id: 'do-the-thing', | |
initial: 'validating', | |
states: { | |
validating: { | |
invoke: { | |
src: 'validateArgs', | |
onDone: 'handlingThings', | |
onError: { | |
target: 'failure', | |
actions: 'invalidArgsError' | |
} | |
} | |
}, | |
handlingThings: { | |
type: 'parallel', | |
onDone: [ | |
{target: 'success', cond: 'noErrorsHappened'}, | |
{target: 'failure', actions: 'performCleanups'}, | |
], | |
states: { | |
thingOne: { | |
initial: 'handlingA', | |
states: { | |
handlingA: { | |
invoke: { | |
src: 'handleA', | |
onDone: { | |
target: 'complete', | |
actions: 'handleASuccess', | |
}, | |
onError: { | |
target: 'complete', | |
actions: 'handleAError', | |
}, | |
}, | |
}, | |
complete: { | |
type: 'final', | |
}, | |
}, | |
}, | |
thingTwo: { | |
initial: 'handlingB', | |
states: { | |
handlingB: { | |
invoke: { | |
src: 'handleB', | |
onDone: { | |
target: 'handlingC', | |
actions: 'handleBSuccess', | |
}, | |
onError: { | |
target: 'complete', | |
actions: 'handleBError', | |
}, | |
}, | |
}, | |
handlingC: { | |
invoke: { | |
src: 'handleC', | |
onDone: { | |
target: 'complete', | |
actions: 'handleCSuccess', | |
}, | |
onError: { | |
target: 'complete', | |
actions: ['handleCError', 'cleanupB'], | |
}, | |
}, | |
}, | |
complete: { | |
type: 'final' | |
} | |
}, | |
}, | |
}, | |
}, | |
success: { | |
type: 'final', | |
}, | |
failure: { | |
type: 'final', | |
}, | |
}, | |
}, | |
{ | |
guards: { | |
noErrorsHappened: () => /* check for errors */ true | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment