Skip to content

Instantly share code, notes, and snippets.

@drmikecrowe
Last active November 15, 2019 21:57
Show Gist options
  • Save drmikecrowe/fb82badc5713e481420b0f8c40f254a3 to your computer and use it in GitHub Desktop.
Save drmikecrowe/fb82badc5713e481420b0f8c40f254a3 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
// - XState (all XState exports)
const playerStates = {
id: "Player",
initial: "waiting",
states: {
waiting: {
on: {
UPDATE: {
actions: send("UPDATE_NOW"),
target: "#Root.run.running.updater",
},
}
},
playing: {
},
},
};
const updaterStates = {
id: "Updater",
initial: "checkForUpdates",
states: {
checkForUpdates: {
on: {
CHECK_UPDATE_COMPLETE: "waitForUpdates",
},
},
waitForUpdates: {
on: {
UPDATE_NOW: "checkForUpdates",
},
after: {
[4*60*60*1000]: {
target: "checkForUpdates",
},
},
},
},
};
const runningStates = {
id: "Running",
type: "parallel",
initial: "waiting",
states: {
player: {
...playerStates,
},
updater: {
...updaterStates,
},
},
};
const masterMachine = Machine(
{
id: "Root",
initial: "init",
context: {
},
states: {
init: {
on: {
START: 'run',
}
},
run: {
id: "running",
initial: "running",
states: {
running: {
...runningStates,
},
}
}
},
},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment