Skip to content

Instantly share code, notes, and snippets.

@wei-yuuuu
Last active July 20, 2020 05:15
Show Gist options
  • Save wei-yuuuu/d0de030760000c40b2ce2cc3fa169c75 to your computer and use it in GitHub Desktop.
Save wei-yuuuu/d0de030760000c40b2ce2cc3fa169c75 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 fetchStates = {
initial: 'savable',
states: {
savable: {
on: {
SAVE: 'loading',
// actions: {
// target: 'loading',
// save: (context, event) => {
// console.log('mutate to server...');
// },
// }
}
},
loading: {
on: {
RESOLVE: 'success',
REJECT: 'failure'
}
},
success: {
on: {
'': 'savable'
}
},
failure: {
on: {
'': 'savable'
}
},
}
}
const shapeMachine = Machine({
id: 'shape-lifecycle',
initial: 'init', // init, manual, magicwand, model
context: {
retries: 0
},
states: {
init: {
on: {
DRAW: 'shaped',
STOP: 'empty'
}
},
empty: {
on: {
RETRY: 'init'
}
},
shaped: {
on: {
FILL_ATTRIBUTES: 'manual',
AUTOFIT: 'magicwand'
}
},
manual: {
// invoke: {
// id: 'fetch',
// src: fetchMachine
// },
on: {
DRAG_DROP: 'manual',
RESIZE: 'manual',
FILL_ATTRIBUTES: 'manual',
COPY_PREV: 'magicwand',
COPY_PREV_NOT_MODEL: 'magicwand',
COPY_PASTE: 'magicwand',
SMART_COPY_PREV: 'magicwand',
// SAVE: {
// actions: send('FETCH', {
// to: 'fetch'
// })
// }
},
...fetchStates
},
magicwand: {
on: {
DRAG_DROP: 'manual',
RESIZE: 'manual',
FILL_ATTRIBUTES: 'manual',
COPY_PREV: 'magicwand',
COPY_PREV_NOT_MODEL: 'magicwand',
COPY_PASTE: 'magicwand',
SMART_COPY_PREV: 'magicwand',
},
...fetchStates
},
model: {
on: {
DRAG_DROP: 'manual',
RESIZE: 'manual',
FILL_ATTRIBUTES: 'manual',
COPY_PREV: 'magicwand',
COPY_PREV_NOT_MODEL: 'model',
COPY_PASTE: 'magicwand',
SMART_COPY_PREV: 'magicwand',
},
...fetchStates
},
// loading: {
// on: {
// RESOLVE: 'success',
// REJECT: 'failure'
// }
// },
// success: {
// on: {
// '': 'manual'
// }
// },
// failure: {
// on: {
// '': 'manual'
// }
// },
}
},
{
actions: {
mutate: (context, event) => {
console.log('mutate to server...');
},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment