Last active
May 13, 2020 16:31
-
-
Save hnordt/bf132ea060e0a9826e5e72f9cce3d5c1 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
Machine({ | |
id: 'session', | |
initial: 'restoring', | |
states: { | |
restoring: { | |
initial: "loading", | |
states: { | |
loading: { | |
invoke: { | |
src: "restore", | |
onDone: "success", | |
onError: [ | |
{ | |
target: "expired", | |
cond: "isTokenExpired" | |
}, | |
{ | |
target: "failure" | |
} | |
] | |
} | |
}, | |
success: { | |
type: "final", | |
entry: "setToken" | |
}, | |
expired: { | |
type: "final", | |
entry: "resetToken" | |
}, | |
failure: { | |
entry: "setError", | |
exit: "resetError", | |
on: { | |
RETRY: "loading" | |
} | |
} | |
}, | |
onDone: [ | |
{ | |
target: "signedIn", | |
cond: "hasToken" | |
}, | |
{ | |
target: "signedOut" | |
} | |
] | |
}, | |
signedOut: { | |
on: { | |
SIGN_IN: 'signingIn' | |
} | |
}, | |
signingIn: { | |
initial: "loading", | |
states: { | |
loading: { | |
invoke: { | |
src: "signIn", | |
onDone: "success", | |
onError: "failure" | |
} | |
}, | |
success: { | |
type: "final", | |
entry: "setToken" | |
}, | |
failure: { | |
entry: "setError", | |
exit: "resetError", | |
on: { | |
RETRY: "loading" | |
} | |
} | |
}, | |
onDone: "signedIn" | |
}, | |
signedIn: { | |
initial: "idle", | |
states: { | |
idle: { | |
after: { | |
2000: 'refreshingToken' | |
} | |
}, | |
refreshingToken: { | |
initial: "loading", | |
states: { | |
loading: { | |
invoke: { | |
src: "refreshToken", | |
onDone: "success", | |
onError: "failure" | |
} | |
}, | |
success: { | |
type: "final", | |
entry: "setToken" | |
}, | |
failure: { | |
entry: "setError", | |
exit: "resetError", | |
on: { | |
RETRY: "loading" | |
} | |
} | |
}, | |
onDone: "idle" | |
} | |
}, | |
on: { | |
SIGN_OUT: "signingOut" | |
} | |
}, | |
signingOut: { | |
initial: "loading", | |
states: { | |
loading: { | |
invoke: { | |
src: "signOut", | |
onDone: "success", | |
onError: "failure" | |
} | |
}, | |
success: { | |
type: "final", | |
entry: "resetToken" | |
}, | |
failure: { | |
entry: "setError", | |
exit: "resetError", | |
on: { | |
RETRY: "loading" | |
} | |
} | |
}, | |
onDone: "signedOut" | |
}, | |
} | |
}, { | |
guards: { | |
isTokenExpired: () => true, | |
hasToken: () => false | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment