Last active
July 27, 2020 16:24
-
-
Save wesleycoder/9938615697c01d4ef0d0bebb6cea6642 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 appMachine = Machine({ | |
id: "App", | |
initial: "CLOSED", | |
context: { | |
isAuthenticated: false, | |
}, | |
states: { | |
CLOSED: { | |
id: "closed", | |
on: { | |
open: "STARTING", | |
}, | |
}, | |
STARTING: { | |
id: "starting", | |
invoke: { | |
id: "startApp", | |
src: 'startApp', | |
onDone: "#started", | |
onError: "#crashed", | |
}, | |
}, | |
STARTED: { | |
id: "started", | |
on: { | |
"": [ | |
{ | |
target: "AUTHENTICATED", | |
cond: (ctx) => ctx.isAuthenticated, | |
}, | |
{ target: "NOT_AUTHENTICATED", cond: (ctx) => !ctx.isAuthenticated }, | |
], | |
}, | |
}, | |
AUTHENTICATED: { | |
id: "authenticated", | |
initial: 'HOME', | |
states: { | |
HOME: { | |
on: { | |
goToProfile: 'PROFILE' | |
}, | |
}, | |
PROFILE: { | |
on: { | |
get logout () { | |
return appMachine.states.NOT_AUTHENTICATED | |
}, | |
}, | |
}, | |
}, | |
}, | |
NOT_AUTHENTICATED: { | |
id: "notAuthenticated", | |
initial: "LOGIN", | |
invoke: (ctx) => ctx.isAuthenticated = false, | |
states: { | |
LOGIN: { | |
on: { | |
get login () { | |
return { | |
target: appMachine.states.AUTHENTICATED, | |
actions: (ctx) => { | |
ctx.isAuthenticated = true; | |
} | |
} | |
}, | |
}, | |
}, | |
SIGN_UP: {} | |
}, | |
}, | |
CRASHED: { | |
id: "crashed", | |
type: "final", | |
}, | |
}, | |
}, { | |
services: { | |
startApp: async () => new Promise( | |
(res, rej) => | |
setTimeout(res, 1000) | |
) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment