Skip to content

Instantly share code, notes, and snippets.

@drmikecrowe drmikecrowe/machine.js
Last active Nov 15, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.