Skip to content

Instantly share code, notes, and snippets.

@junhuif
Created April 7, 2020 07:33
Show Gist options
  • Save junhuif/1083b832280547ad1b9071f38d76637f to your computer and use it in GitHub Desktop.
Save junhuif/1083b832280547ad1b9071f38d76637f to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const checkoutMachine = Machine({
id: "checkout",
initial: "draft",
context: {},
states: {
draft: {
on: {
CONFIRM: {
target: "confirmed",
actions: assign({ order: (_context, event) => event.order })
},
ABORT: "aborted"
}
},
confirmed: {
on: {
CHECKIN: {
target: "checkedIn",
cond: hasOrder
},
CANCEL: {
target: "cancelled",
cond: hasOrder
}
}
},
checkedIn: {
on: {
PICKUP: "pickedUp"
}
},
pickedUp: {
type: "final"
},
cancelled: {
type: "final"
},
aborted: {
type: "final"
}
}
});
function hasOrder(context) {
return context.order != null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment