Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Andarist
Created October 8, 2020 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andarist/e7aa3fa14e51326967c1e40a3b93095b to your computer and use it in GitHub Desktop.
Save Andarist/e7aa3fa14e51326967c1e40a3b93095b to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
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