Last active
April 25, 2021 21:30
-
-
Save hitrik/d129273655ea718a7856df9523901be2 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 startUserAuth = () => new Promise(res => setTimeout(res('qazzaq'), 1000)) | |
const userMachine = Machine({ | |
id: 'user', | |
context: { | |
user: null, | |
error: false | |
}, | |
initial: 'idle', | |
states: { | |
authorize: { | |
on: { | |
'LOGOUT': 'idle' | |
} | |
}, | |
loading: { | |
invoke: { | |
id: 'userAuth', | |
src: () => startUserAuth(), | |
onDone: { | |
target: 'success', | |
actions: assign({ | |
user: (_, event) => event.data | |
}) | |
}, | |
onError: { | |
target: 'failure', | |
actions: assign({ | |
error: (_, event) => event.data | |
}) | |
} | |
} | |
}, | |
success: { | |
type: 'final' | |
}, | |
failure: { | |
}, | |
idle: { | |
on: { | |
'AUTH': 'loading' | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment