Skip to content

Instantly share code, notes, and snippets.

@mr-mig
Created November 22, 2019 11:52
Show Gist options
  • Save mr-mig/31e8f7c26cf937a0f8e9d0f3f6b4f1e4 to your computer and use it in GitHub Desktop.
Save mr-mig/31e8f7c26cf937a0f8e9d0f3f6b4f1e4 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const queue = Machine(
{
id: 'pushQueue',
initial: 'working',
context: {
changes: []
},
states: {
working: {
invoke: {
src: 'pushingService',
onDone: 'cleared',
onError: 'failed'
},
on: {
'': {
target: 'cleared',
cond: 'isQueueEmpty'
}
}
},
failed: {
type: 'final',
entry: [send('SYNC_FAILURE'), sendParent('SYNC_FAILURE')],
on: {
'': 'cleared'
},
data: {
remainingChanges: ctx => ctx.changes
}
},
cleared: {
type: 'final',
data: {
remainingChanges: ctx => ctx.changes
}
}
}
},
{
guards: {
isQueueEmpty: ctx => ctx.changes.length === 0
},
services: {
pushingService: ctx => {
// TODO
return Promise.resolve()
},
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment