Skip to content

Instantly share code, notes, and snippets.

@She-Codes
Last active October 2, 2020 15:05
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 She-Codes/59f3b2cf358e371094d7ac448f273280 to your computer and use it in GitHub Desktop.
Save She-Codes/59f3b2cf358e371094d7ac448f273280 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
const formMachine = Machine({
id: 'form',
initial: 'editing',
context: {
startDate: undefined,
returnDate: undefined,
},
states: {
editing: {
initial: 'oneWayFlight',
states: {
oneWayFlight: {},
returnFlight: {
on: {
CHANGE_END_DATE: {
actions: assign({
returnDate: (c, event) => event.value,
}),
},
},
},
},
on: {
CHANGE_START_DATE: {
actions: assign({
startDate: (c, event) => event.value,
}),
},
ONE_WAY_FLIGHT: '.oneWayFlight',
RETURN_FLIGHT: '.returnFlight',
SUBMIT: 'submitting',
},
},
submitting: {
initial: 'validating',
states: {
validating: {
on: {
INVALID: '#form.editing',
VALID: 'loading',
},
},
loading: {
on: {
SUCCESS: '#form.submitted',
ERROR: '#form.editing',
},
},
},
},
submitted: {
type: 'final',
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment