// Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const asyncState = (src, onDone, onError = 'err') => { const err = onError === 'err' ? { on: { RETRY: 'await' } } : null; const state = { initial: 'await', states: { await: { invoke: { src, onDone, onError } } } } if (err) { state.states.err = err } return state; } const CRUDMachine = Machine({ id: 'crud', initial: 'init', states: { init: { on: { CREATE: 'asyncCreate' } }, // CREATE asyncCreate: asyncState('create', '#crud.entity'), entity: { on: { READ: 'asyncRead', UPDATE: 'asyncUpdate', DELETE: 'asyncDelete', } }, // READ asyncRead: asyncState('read', '#crud.entity'), // UPDATE asyncUpdate: asyncState('update', '#crud.entity'), // DELETE asyncDelete: asyncState('delete', '#crud.trash'), trash: { type: 'final' } } });