Created
June 23, 2020 17:31
-
-
Save codeincontext/b3a7813e13263eba6c2b4ac9642bc2cf to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 machine = Machine( | |
{ | |
id: "wizard", | |
initial: "nameEntry", | |
context: { values: {} }, | |
meta: { version: 2 }, | |
states: { | |
nameEntry: { | |
on: { | |
NEXT: { | |
target: "dobEntry", | |
actions: ["setValues", "persist"], | |
}, | |
}, | |
meta: { | |
step: 1, | |
}, | |
}, | |
dobEntry: { | |
on: { | |
BACK: "nameEntry", | |
NEXT: { | |
target: "phoneEntry", | |
actions: ["setValues", "persist"], | |
}, | |
}, | |
meta: { | |
step: 2, | |
}, | |
}, | |
phoneEntry: { | |
on: { | |
BACK: "dobEntry", | |
NEXT: { | |
target: "addressEntry.hist", | |
actions: ["setValues", "persist"], | |
}, | |
}, | |
meta: { | |
step: 3, | |
}, | |
}, | |
addressEntry: { | |
initial: "lookup", | |
states: { | |
lookup: { | |
on: { | |
FOUND: "full", | |
FAILED: "full", | |
MANUAL: "full", | |
}, | |
}, | |
full: { | |
initial: "primaryOnly", | |
states: { | |
primaryOnly: { | |
on: { | |
ADD_PREVIOUS: "previous", | |
}, | |
}, | |
previous: { | |
initial: "lookup", | |
states: { | |
lookup: { | |
on: { | |
FOUND: "full", | |
FAILED: "full", | |
MANUAL: "full", | |
}, | |
}, | |
full: {}, | |
}, | |
on: { | |
REMOVE_PREVIOUS: "primaryOnly", | |
}, | |
}, | |
}, | |
}, | |
hist: { | |
type: "history", | |
history: "deep", | |
}, | |
}, | |
on: { | |
BACK: "phoneEntry", | |
NEXT: { | |
target: "confirmation", | |
actions: ["setValues", "persist"], | |
}, | |
}, | |
meta: { | |
step: 4, | |
}, | |
}, | |
confirmation: { | |
on: { | |
EDIT_NAME: "nameEntry", | |
EDIT_DOB: "dobEntry", | |
EDIT_PHONE: "phoneEntry", | |
EDIT_ADDRESS: "addressEntry.hist", | |
EDIT_PREVIOUS_ADDRESS: "addressEntry.full.previous", | |
BACK: "addressEntry.hist", | |
SAVE: "completed", | |
}, | |
meta: { | |
step: 5, | |
}, | |
}, | |
completed: { | |
type: "final", | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
setValues: assign({ | |
values: (context, event) => ({ ...context.values, ...event.values }), | |
}), | |
}, | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment