Last active
December 31, 2019 23:04
-
-
Save erickeno/e2bd757c2e6f31397b2e182824551c39 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 reservationModal = { | |
initial: 'closed', | |
states: { | |
closed: { | |
on: { | |
OPEN: 'open' | |
} | |
}, | |
open: { | |
on: { | |
CLOSE: 'closed' | |
} | |
} | |
} | |
} | |
const signoutModal = { | |
initial: 'hidden', | |
states: { | |
hidden: { | |
on: { | |
SHOW: 'shown' | |
} | |
}, | |
shown: { | |
on: { | |
HIDE: 'hidden', | |
SIGNOUT: 'logout' | |
} | |
}, | |
logout: { type: 'final'} | |
} | |
} | |
const fetchUser = () => { | |
return Promise.resolve({ id: 33, name: 'Test'}) | |
} | |
const classMachine = Machine({ | |
id: 'class', | |
context: { data: undefined, error: undefined }, | |
initial: 'loading', | |
states: { | |
loading: { | |
invoke: { | |
id: 'geData', | |
src: (context, event) => fetchUser(), | |
onDone: { | |
target: 'success', | |
actions: assign({ data: (context, event) => event.data }) | |
}, | |
onError: { | |
target: 'failure', | |
actions: assign({ error: (context, event) => event.data }) | |
} | |
}, | |
}, | |
failure: { | |
on: { | |
RETRY: 'loading' | |
} | |
}, | |
success: { | |
type: 'parallel', | |
states: { | |
reservation: reservationModal, | |
logout: signoutModal | |
} | |
}, | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment