Last active
May 28, 2020 22:05
-
-
Save bultas/09ba55bb517c15328ff2be04c639a365 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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 persooMachine = Machine({ | |
id: "persoo", | |
initial: "initialize", | |
states: { | |
initialize: { | |
type: "parallel", | |
states: { | |
waitForPersooJS: { | |
initial: "fetching", | |
states: { | |
fetching: { | |
invoke: { | |
src: "check-if-persoo", | |
onDone: { | |
target: "success", | |
}, | |
onError: { | |
actions: "log-general-error", | |
target: "failure", | |
}, | |
}, | |
}, | |
success: { | |
type: "final", | |
}, | |
failure: { | |
type: "final", | |
}, | |
}, | |
}, | |
checkingAuth: { | |
initial: "fetching", | |
states: { | |
fetching: { | |
invoke: { | |
src: "check-if-auth", | |
onDone: { | |
actions: ["assign-is-auth"], | |
target: "success", | |
}, | |
onError: { | |
actions: "log-general-error", | |
target: "failure", | |
}, | |
}, | |
}, | |
success: { | |
type: "final", | |
}, | |
failure: { | |
type: "final", | |
}, | |
}, | |
}, | |
}, | |
onDone: { | |
target: "initialized", | |
actions: ["initialized"], | |
}, | |
}, | |
initialized: { | |
initial: "switch", | |
states: { | |
switch: { | |
on: { | |
"": [{ target: "auth", cond: "isAuth" }, { target: "not-auth" }], | |
}, | |
}, | |
"not-auth": { | |
on: { | |
"highlight-locations": [ | |
{ | |
actions: [ | |
"switch-highlight-locations-state", | |
"turn-off-highlight", | |
"highlight-changed", | |
], | |
cond: "is-highlight-on", | |
}, | |
{ | |
actions: [ | |
"switch-highlight-locations-state", | |
"turn-on-highlight-no-auth", | |
"highlight-changed", | |
], | |
}, | |
], | |
"offers-in-locations.updated": { | |
actions: "offersInLocationsUpdated", | |
}, | |
}, | |
}, | |
auth: { | |
initial: "idle", | |
states: { | |
idle: { | |
on: { | |
"offers-in-locations.updated": { | |
target: "update-offers-data", | |
}, | |
"highlight-locations": { | |
target: "highlight", | |
}, | |
"fetch-abtests-data": [ | |
{ | |
actions: "abtests-fetched", | |
cond: "ifAbTestsAndProfileFetched", | |
}, | |
{ | |
target: "fetching-data-for-ab-tests", | |
}, | |
], | |
"switch-abtest-variant": { | |
actions: "switch-abtest-variant", | |
}, | |
}, | |
}, | |
highlight: { | |
initial: "init", | |
states: { | |
init: { | |
on: { | |
"": [ | |
{ | |
target: "turn-off", | |
cond: "is-highlight-on", | |
}, | |
{ | |
target: "turn-on", | |
cond: "areOffersFetched", | |
}, | |
{ | |
target: "fetching", | |
}, | |
], | |
}, | |
}, | |
fetching: { | |
invoke: { | |
src: "fetchOffersData", | |
onDone: { | |
actions: ["assign-offers"], | |
target: "init", | |
}, | |
onError: { | |
actions: ["log-general-error"], | |
target: "failed", | |
}, | |
}, | |
}, | |
"turn-on": { | |
entry: [ | |
"switch-highlight-locations-state", | |
"turn-on-highlight", | |
"highlight-changed", | |
], | |
on: { | |
"": { | |
target: "success", | |
}, | |
}, | |
}, | |
"turn-off": { | |
entry: [ | |
"switch-highlight-locations-state", | |
"turn-off-highlight", | |
"highlight-changed", | |
], | |
on: { | |
"": { | |
target: "success", | |
}, | |
}, | |
}, | |
success: { | |
type: "final", | |
}, | |
failed: { | |
type: "final", | |
}, | |
}, | |
onDone: { | |
target: "idle", | |
}, | |
}, | |
"update-offers-data": { | |
invoke: { | |
src: "fetchOffersData", | |
onDone: { | |
actions: ["assign-offers", "offersInLocationsUpdated"], | |
target: "idle", | |
}, | |
onError: { | |
actions: ["log-general-error", "offersInLocationsUpdated"], | |
target: "idle", | |
}, | |
}, | |
}, | |
"fetching-data-for-ab-tests": { | |
type: "parallel", | |
states: { | |
"fetching-abtests-data": { | |
initial: "fetching", | |
states: { | |
fetching: { | |
invoke: { | |
src: "fetch-abtests-service", | |
onDone: { | |
actions: ["assign-abtest"], | |
target: "success", | |
}, | |
onError: { | |
actions: ["abtests-failed", "log-general-error"], | |
target: "error", | |
}, | |
}, | |
}, | |
success: { | |
type: "final", | |
}, | |
error: { | |
type: "final", | |
}, | |
}, | |
}, | |
"fetch-user-profile": { | |
initial: "fetching", | |
states: { | |
fetching: { | |
invoke: { | |
src: "fetch-user-profile-service", | |
onDone: { | |
actions: ["assign-is-user-profile-fetched"], | |
target: "success", | |
}, | |
onError: { | |
actions: "log-general-error", | |
target: "error", | |
}, | |
}, | |
}, | |
success: { | |
type: "final", | |
}, | |
error: { | |
type: "final", | |
}, | |
}, | |
}, | |
}, | |
onDone: [ | |
{ | |
target: "idle", | |
actions: ["abtests-fetched"], | |
cond: "ifAbTestsAndProfileFetched", | |
}, | |
{ | |
target: "idle", | |
}, | |
], | |
}, | |
}, | |
}, | |
}, | |
on: { | |
"change-env": "env-changing", | |
"show-admin-bar": { | |
actions: "show-admin-bar", | |
}, | |
"show-log": { | |
actions: "show-log", | |
}, | |
"show-exceptions": { | |
actions: "show-exceptions", | |
}, | |
"exception-log.updated": { | |
actions: "exceptionsUpdated", | |
}, | |
}, | |
}, | |
"env-changing": { | |
invoke: { | |
src: "change-env-service", | |
onDone: { | |
actions: "env-changed", | |
target: "initialized", | |
}, | |
onError: { | |
actions: "log-general-error", | |
target: "initialized", | |
}, | |
}, | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment