Last active
May 3, 2021 01:27
-
-
Save airandopal/ac06dbaf108091de1490cfb2fa4c1bf6 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
| // Available variables: | |
| // - Machine | |
| // - interpret | |
| // - assign | |
| // - send | |
| // - sendParent | |
| // - spawn | |
| // - raise | |
| // - actions | |
| // - XState (all XState exports) | |
| const guards = { | |
| isSessionPresent: (context, event) => { return null }, // todo: get info from global state about whether there is a user | |
| sessionNotPresent: (context, event) => { return null }, | |
| } | |
| const mainStates = { | |
| 'loading': { | |
| on: { | |
| '': 'checkingForSession', | |
| // TRANSIENT TRANSITION | |
| '': [ | |
| { target: 'checkingForSession' }, | |
| { target: 'loggedIn', cond: 'isSessionPresent' }, | |
| { target: 'notLoggedIn', cond: 'sessionNotPresent' } | |
| ], | |
| } | |
| }, | |
| 'checkingForSession': { | |
| on: { | |
| SUCCESS: 'loggedIn', | |
| FAILURE: 'notLoggedIn', // whats the difference between this and error | |
| ERROR: 'error', // must pass error along | |
| } | |
| }, | |
| 'loggedIn': { | |
| on: { | |
| LOGOUT: 'loggedOut' | |
| } | |
| }, | |
| 'notLoggedIn': { | |
| on: { | |
| LOGIN: 'tryingLogin' | |
| } | |
| }, | |
| 'tryingLogin': { | |
| on: { | |
| SUCCESS: 'loggedIn', | |
| FAILURE: 'notLoggedIn', // whats the difference between this and error | |
| ERROR: 'error', // must pass error along | |
| } | |
| }, | |
| // 'BAD_LOGIN': {}, | |
| 'loggedOut': {}, | |
| 'error': {}, | |
| } | |
| const config = { | |
| id: 'app', | |
| initial: 'loading', | |
| context: {}, | |
| states: mainStates | |
| } | |
| // Transient transition | |
| // Will transition to either 'win' or 'lose' immediately upon | |
| // (re)entering 'playing' state if the condition is met. | |
| const fetchMachine = Machine(config, { guards }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment