Skip to content

Instantly share code, notes, and snippets.

@RafalFilipek
Created April 2, 2020 08:28
Show Gist options
  • Save RafalFilipek/f9ae5c7bedb72d2a55f9761400ca987f to your computer and use it in GitHub Desktop.
Save RafalFilipek/f9ae5c7bedb72d2a55f9761400ca987f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const auth = Machine({
id: 'auth',
initial: 'idle',
context: {
strategy: 'phone',
availableStrategies: ['phone', 'email']
},
states: {
idle: {
on: {
SET_STRATEGY: {
target: 'verification',
cond: 'isValidStrategy'
}
}
},
verification: {
initial: 'idle',
states: {
idle: {
on: {
AUTHENTICATE: {
target: 'processing'
}
}
},
processing: {
}
}
}
}
}, {
actions: {
setStrategy: assign({
strategy: (c, e) => e.data,
})
},
guards: {
isValidStrategy: (c, e) => c.availableStrategies.includes(e.data)
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment