Skip to content

Instantly share code, notes, and snippets.

@shshaw
Last active April 14, 2020 21:05
Show Gist options
  • Save shshaw/c8fe79213a127f4b8a374cd660a41ef9 to your computer and use it in GitHub Desktop.
Save shshaw/c8fe79213a127f4b8a374cd660a41ef9 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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