Skip to content

Instantly share code, notes, and snippets.

@codeincontext
Created June 22, 2020 13:12
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 codeincontext/1244ecdcaf96599bd77c62d19de318f8 to your computer and use it in GitHub Desktop.
Save codeincontext/1244ecdcaf96599bd77c62d19de318f8 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const machine = Machine(
{
id: "wizard",
initial: "nameEntry",
context: { values: {} },
states: {
nameEntry: {
on: {
NEXT: {
target: "dobEntry",
actions: ["setValues"],
},
},
meta: {
step: 1,
},
},
dobEntry: {
on: {
BACK: "nameEntry",
NEXT: "phoneEntry",
},
meta: {
step: 2,
},
},
phoneEntry: {
on: {
BACK: "dobEntry",
NEXT: "addressEntry.hist",
},
meta: {
step: 3,
},
},
addressEntry: {
initial: "lookup",
states: {
lookup: {
on: {
FOUND: "manual",
FAILED: "manual",
MANUAL: "manual",
},
},
manual: {
on: {
ADD_PREVIOUS: "previous",
},
},
previous: {
on: {
REMOVE_PREVIOUS: "manual",
},
},
hist: {
type: "history",
},
},
on: {
BACK: "phoneEntry",
NEXT: "confirmation",
},
meta: {
step: 4,
},
},
confirmation: {
on: {
EDIT_NAME: "nameEntry",
EDIT_DOB: "dobEntry",
EDIT_PHONE: "phoneEntry",
EDIT_ADDRESS: "addressEntry.hist",
EDIT_PREVIOUS_ADDRESS: "addressEntry.previous",
BACK: "addressEntry",
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