Last active
November 1, 2020 21:52
-
-
Save snikch/2646102e50e7c1b64395116842ad2ae4 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 defProcessed = { | |
saving: { | |
invoke: { | |
src: 'saveEvent', | |
onDone: { | |
target: 'saved' | |
}, | |
onError: { | |
target: 'error' | |
} | |
} | |
}, | |
saved: { | |
type: 'final' | |
}, | |
error: { | |
on : { | |
RETRY: 'saving' | |
} | |
} | |
} | |
const definition = { | |
id: 'machine', | |
initial: 'received', | |
context: { | |
retries: 0 | |
}, | |
states: { | |
received: { | |
always: [{ | |
target: 'processed', | |
cond: 'isSuperseded' | |
}, { | |
target: 'processing' | |
}] | |
}, | |
processing: { | |
invoke: { | |
src: 'processEvent', | |
onDone: { | |
target: 'processed' | |
}, | |
onError: { | |
target: 'failure' | |
} | |
} | |
}, | |
processed: { | |
invoke: { | |
// Go off and store the cursor | |
'src': 'didProcessEvent' | |
}, | |
type: 'final', | |
states: defProcessed, | |
}, | |
failure: { | |
type: 'final' | |
} | |
} | |
}; | |
const machine = Machine(definition); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment