Skip to content

Instantly share code, notes, and snippets.

@Sparragus
Last active October 29, 2020 17:10
Show Gist options
  • Save Sparragus/ed2733fb9d5fa6c3e0ed614b706cadc1 to your computer and use it in GitHub Desktop.
Save Sparragus/ed2733fb9d5fa6c3e0ed614b706cadc1 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 initialContext = {
amount: undefined,
currency: undefined
};
const depositMachine = Machine({
id: 'deposit',
initial: 'selecting',
context: initialContext,
states: {
selecting: {
entry: [
"reset"
],
on: {
SUBMIT: {
target: "confirming",
cond: "validSubmit",
actions: [
'submit'
]
}
}
},
confirming: {
on: {
CONFIRM: "success",
RESTART: "selecting"
}
},
success: {
on: {
RESTART: "selecting"
}
},
}
}, {
actions: {
submit: assign({
amount: (context, event) => event.amount,
currency: (context, event) => event.currency,
}),
reset: assign(() => initialContext)
},
guards: {
validSubmit: (context, event) => event.amount && event.amount > 0 && event.currency
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment