Skip to content

Instantly share code, notes, and snippets.

@snikch
Last active November 1, 2020 21:52
Show Gist options
  • Save snikch/2646102e50e7c1b64395116842ad2ae4 to your computer and use it in GitHub Desktop.
Save snikch/2646102e50e7c1b64395116842ad2ae4 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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