Skip to content

Instantly share code, notes, and snippets.

@MichielDeMey
Last active October 31, 2019 09:01
Show Gist options
  • Save MichielDeMey/ff1a3edf3ec55c827fae2d745b4f3502 to your computer and use it in GitHub Desktop.
Save MichielDeMey/ff1a3edf3ec55c827fae2d745b4f3502 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 fetchMachine = Machine({
id: 'onboard',
initial: 'onboardHub',
context: {
retries: 0,
},
states: {
onboardHub: {
initial: 'intro',
states: {
intro: {
on: {
NEXT: 'searchingHub'
}
},
searchingHub: {
initial: 'polling',
states: {
polling: {
after: {
60000: 'failure'
},
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
after: {
3000: '#onboard.pairButtons'
}
},
failure: {
on: {
RETRY: {
target: 'polling',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
}
}
},
pairButtons: {
initial: 'intro',
states: {
intro: {},
pollButton: {}
}
},
pairMotionSensors: {
initial: 'intro',
states: {
intro: {}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment