Skip to content

Instantly share code, notes, and snippets.

@sea-witch
Created August 24, 2020 13:04
Show Gist options
  • Save sea-witch/5daad07ba52afe19f2786f37b3069260 to your computer and use it in GitHub Desktop.
Save sea-witch/5daad07ba52afe19f2786f37b3069260 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 controlsStates = {
id: 'controlsStates',
initial: 'paused',
states: {
paused: {
on: {
press_play: 'playing',
keydown: {
target: 'playing',
cond: 'isSpacebar'
}
}
},
playing: {
on: {
press_pause: 'paused',
keydown: {
target: 'paused',
cond: 'isSpacebar'
}
}
},
}
}
const uiMachine = Machine({
id: "ui",
type: "parallel",
states: {
controlsVisibility: {
id: "controlsVisibility",
initial: "hidden",
states: {
visible: {
after: {
3000: "hidden"
}
},
hidden: {
on: {
mousemove: "visible"
}
}
}
},
controls: controlsStates
}
},
{
guards: {
isSpacebar: (ctx, event) => event.code === "Space"
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment