// 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 });