Skip to content

Instantly share code, notes, and snippets.

@stutrek
Last active October 28, 2019 01:42
Show Gist options
  • Save stutrek/16f77632aca93ade9d0b636cb5d21e79 to your computer and use it in GitHub Desktop.
Save stutrek/16f77632aca93ade9d0b636cb5d21e79 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 fetchMachine = Machine({
id: 'editor',
initial: 'loading',
context: {
projectId: undefined,
project: undefined,
zoom: 1,
minZoom: 1,
margin: 1,
contentWidth: 1,
containerHeight: 1000,
sizeCalculated: false,
containerWidth: 1000,
},
states: {
loading: {
invoke: {
id: 'getProject',
src: 'getProject',
onError: {
target: 'error',
},
onDone: {
target: 'edit',
},
},
},
error: {
on: {
RETRY: 'loading',
},
},
edit: {
type: 'parallel',
states: {
zoom: {
initial: 'unknown',
states: {
unknown: {
on: {
'': [
{
target: 'min',
cond: 'isZoomMin',
},
{
target: 'max',
cond: 'isZoomMax',
},
{ target: 'middle' },
],
},
},
min: {
on: {
ZOOM_IN: {
target: 'unknown',
actions: ['zoomIn'],
},
},
},
max: {
on: {
ZOOM_OUT: {
target: 'unknown',
actions: ['zoomOut'],
},
},
},
middle: {
on: {
ZOOM_IN: {
target: 'unknown',
actions: ['zoomIn'],
},
ZOOM_OUT: {
target: 'unknown',
actions: ['zoomOut'],
},
},
},
},
},
nightMode: {
initial: 'off',
states: {
on: {
on: {
NIGHT_MODE_OFF: 'off',
},
},
off: {
on: {
NIGHT_MODE_ON: 'on',
},
},
},
},
labels: {
initial: 'on',
states: {
on: {
on: {
LABELS_OFF: 'off',
},
},
off: {
on: {
LABELS_ON: 'on',
},
},
},
},
eyedropper: {
initial: 'off',
states: {
on: {
on: {
ALT_KEY_UP: 'off',
},
},
off: {
on: {
ALT_KEY_DOWN: 'on',
},
},
},
},
dragging: {
initial: 'off',
states: {
on: {
on: {
DRAG_END: 'off',
},
},
off: {
on: {
DRAG_START: 'on',
},
},
},
},
},
},
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment