Created
April 2, 2021 04:59
-
-
Save gpittau/132dea0c6082625ff9e03343065d687c to your computer and use it in GitHub Desktop.
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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) | |
const loginMachine = Machine({ | |
id: 'login', | |
context: {}, | |
initial: 'boot', | |
states: { | |
boot: { | |
on: { | |
'': [ | |
{ target: 'loggedOut', cond: 'isLoggedOut' }, | |
{ target: 'loggedIn' } | |
] | |
} | |
}, | |
loggedOut: { | |
on: { | |
SUBMIT: [ | |
{ | |
target: 'loading' | |
} | |
] | |
} | |
}, | |
loggedIn: { | |
type: 'final' | |
}, | |
requestErr: { | |
on: { | |
SUBMIT: 'loading' | |
} | |
}, | |
loading: { | |
invoke: { | |
id: 'login', | |
src: 'requestLogin' | |
}, | |
on: { | |
SUCCESS: { | |
target: 'loggedIn', | |
actions: ['assignUser', 'loginSuccess'] | |
}, | |
FAILURE: { | |
target: 'requestErr', | |
actions: ['assignErrors'] | |
} | |
} | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment