Last active
October 2, 2020 15:05
-
-
Save She-Codes/59f3b2cf358e371094d7ac448f273280 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
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