Last active
October 29, 2020 17:10
-
-
Save Sparragus/ed2733fb9d5fa6c3e0ed614b706cadc1 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
// 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