Created
April 2, 2020 08:28
-
-
Save RafalFilipek/f9ae5c7bedb72d2a55f9761400ca987f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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