Last active
May 13, 2020 08:06
-
-
Save johnkazer/7326b9ad748a6d835521dd2f60af8994 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains 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 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