Skip to content

Instantly share code, notes, and snippets.

@panesofglass
Last active June 17, 2020 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panesofglass/131b535a00993a926f3a4712fda302d5 to your computer and use it in GitHub Desktop.
Save panesofglass/131b535a00993a926f3a4712fda302d5 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 stepMachine = Machine({
id: 'step',
initial: 'preferences',
context: {
retries: 0
},
states: {
preferences: {
on: {
PREVIOUS: 'preferences',
SUBMIT: 'loading1'
}
},
loading1: {
on: {
RESOLVE: 'narrow',
REJECT: 'failure1'
}
},
narrow: {
on: {
NEXT: 'habits'
}
},
habits: {
on: {
PREVIOUS: 'preferences',
SUBMIT: 'loading2'
}
},
loading2: {
on: {
RESOLVE: 'recommendations',
REJECT: 'failure2'
}
},
recommendations: {
on: {
SUBMIT: 'complete',
RESET: 'preferences'
}
},
complete: {
type: 'final',
on: {
RESET: 'preferences'
}
},
failure1: {
on: {
RETRY: {
target: 'loading1',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
},
failure2: {
on: {
RETRY: {
target: 'loading2',
actions: assign({
retries: (context, event) => context.retries + 1
})
}
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment