Last active
August 14, 2019 11:24
-
-
Save lailo/e8928c8d497848f930b45828a10021b9 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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const fetchMachine = Machine( | |
{ | |
id: 'onboarding', | |
initial: 'entry', | |
context: { | |
completedFlow: false, | |
}, | |
states: { | |
entry: { | |
on: { | |
EXIT: 'hardExit', | |
CONTINUE: 'userData', | |
}, | |
}, | |
userData: { | |
on: { | |
CONTINUE: { | |
actions: 'continueUserData', | |
}, | |
UPDATE: { | |
target: 'confirmation', | |
cond: 'hasCompletedFlow', | |
}, | |
SAVE: { | |
target: 'importantQuestions', | |
cond: 'hasNotCompletedFlow', | |
}, | |
}, | |
}, | |
importantQuestions: { | |
on: { | |
CONTINUE: 'addressData', | |
}, | |
}, | |
addressData: { | |
on: { | |
CONTINUE: { | |
actions: 'continueAddressData', | |
}, | |
UPDATE: { | |
target: 'confirmation', | |
cond: 'hasCompletedFlow', | |
}, | |
SAVE: { | |
target: 'confirmation', | |
cond: 'hasNotCompletedFlow', | |
}, | |
}, | |
}, | |
confirmation: { | |
entry: 'completeFlow', | |
on: { | |
EDIT_USER_DATA: 'userData', | |
EDIT_ADDRESS_DATA: 'addressData', | |
CONTINUE: 'saveData', | |
}, | |
}, | |
saveData: { | |
type: 'final', | |
}, | |
hardExit: { | |
type: 'final', | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
completeFlow: assign({ completedFlow: true }), | |
continueUserData: send(context => { | |
if (context.completedFlow) return { type: 'UPDATE' } | |
return { type: 'SAVE' } | |
}), | |
continueAddressData: send(context => { | |
if (context.completedFlow) return { type: 'UPDATE' } | |
return { type: 'SAVE' } | |
}), | |
}, | |
guards: { | |
hasCompletedFlow: context => context.completedFlow, | |
hasNotCompletedFlow: context => !context.completedFlow, | |
}, | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment