Last active
April 14, 2020 21:05
-
-
Save shshaw/c8fe79213a127f4b8a374cd660a41ef9 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 STATES = { | |
AUTHENTICATING: 'AUTHENTICATING', | |
AUTHORIZED: 'AUTHORIZED', | |
UNAUTHORIZED: 'UNAUTHORIZED', | |
STORAGE_FULL: 'STORAGE_FULL', | |
ERROR: 'ERROR' | |
}; | |
const EVENTS = { | |
AUTHENTICATED: 'AUTHENTICATED', | |
REJECTED: 'REJECTED', | |
STORAGE_FULL: 'STORAGE_FULL', | |
ERROR: 'ERROR', | |
RESET: 'RESET' | |
}; | |
const STATE_MACHINE = { | |
initial: STATES.AUTHENTICATING, | |
states: { | |
[STATES.AUTHENTICATING]: { | |
on: { | |
[EVENTS.AUTHENTICATED]: STATES.AUTHORIZED, | |
[EVENTS.REJECTED]: STATES.UNAUTHORIZED | |
} | |
}, | |
[STATES.AUTHORIZED]: { | |
on: { | |
[EVENTS.STORAGE_FULL]: STATES.STORAGE_FULL, | |
[EVENTS.ERROR]: STATES.ERROR | |
} | |
}, | |
[STATES.ERROR]: { | |
on: { | |
[EVENTS.RESET]: STATES.AUTHORIZED | |
} | |
}, | |
[STATES.STORAGE_FULL]: { | |
on: { | |
[EVENTS.RESET]: STATES.AUTHORIZED | |
} | |
}, | |
[STATES.UNAUTHORIZED]: {} | |
} | |
}; | |
const { state, transition } = Machine(STATE_MACHINE); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment