Last active
November 15, 2019 21:57
-
-
Save drmikecrowe/fb82badc5713e481420b0f8c40f254a3 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
// 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