Created
October 8, 2020 09:21
-
-
Save Andarist/e7aa3fa14e51326967c1e40a3b93095b 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
Machine( | |
{ | |
context: { | |
networkQuality: "good", | |
}, | |
on: { | |
REPORT_NETWORK_QUALITY: { | |
actions: [ | |
assign({ | |
networkQuality: (_, ev) => ev.networkQuality, | |
}), | |
raise("NETWORK_QUALITY_REPORTED"), | |
], | |
}, | |
DISMISS_NETWORK_QUALITY_WARNING: ".permanently_hidden", | |
}, | |
initial: "hidden", | |
states: { | |
hidden: { | |
entry: ["hide"], | |
on: { | |
NETWORK_QUALITY_REPORTED: { | |
cond: "isQualityBad", | |
target: "shown", | |
}, | |
}, | |
}, | |
shown: { | |
entry: ["show"], | |
initial: "stabilising", | |
states: { | |
stabilising: { | |
after: { | |
2000: "stabilised", | |
}, | |
}, | |
stabilised: { | |
on: { | |
"": { | |
cond: "isQualityGood", | |
target: "final", | |
}, | |
NETWORK_QUALITY_REPORTED: { | |
cond: "isQualityGood", | |
target: "final", | |
}, | |
}, | |
}, | |
final: { | |
type: "final", | |
}, | |
}, | |
onDone: "hidden", | |
}, | |
permanently_hidden: {}, | |
}, | |
}, | |
{ | |
guards: { | |
isQualityBad: (ctx) => ctx.networkQuality === "bad", | |
isQualityGood: (ctx) => ctx.networkQuality === "good", | |
}, | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment