Skip to content

Instantly share code, notes, and snippets.

@johnkazer
Last active May 13, 2020 08:06
Show Gist options
  • Save johnkazer/7326b9ad748a6d835521dd2f60af8994 to your computer and use it in GitHub Desktop.
Save johnkazer/7326b9ad748a6d835521dd2f60af8994 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 drawLine = Machine({
id: 'lineMachine',
initial: 'idle',
context: {
from: '',
to: ''
},
states: {
idle: {
on: {
keypress: [
{
target: 'pending'
}
]
}
},
pending: {
on: {
click: {
target: 'lineStart',
actions: ['from']
}
}
},
lineStart: {
on: {
click: {
target: 'lineEnd',
actions: ['to']
}
}
},
lineEnd: {
on: {
'': {
target: 'idle'
}
}
}
}
},
{
guards: {
key_l: (context, event) => { return event.key === 'l' }
},
actions: {
from: assign({ from: (context, event) => event.target.id }),
to: assign({ to: (context, event) => event.target.id })
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment