// Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const fetchMachine = Machine({ id: 'fetch', initial: 'idle', context: { retries: 0 }, states: { idle: { on: { FETCH: { // actions: ['catchMe'], target: 'loading' }, 'xstate.error': { target: 'internal_error' }, 'error.execution': { target: 'internal_error' } } }, loading: { entry: ['catchMe2'], on: { RESOLVE: 'success', REJECT: 'failure', 'xstate.error': { target: 'internal_error' }, 'error.execution': { target: 'internal_error' } } }, success: { type: 'final' }, failure: { on: { RETRY: { target: 'loading', actions: assign({ retries: (context, event) => context.retries + 1 }) } } }, internal_error: { type: 'final' } } }, { actions: { catchMe: () => { throw new Error('event: catch me if you can xD') }, catchMe2: () => { throw new Error('entry: catch me if you can xD') } } }); // const interpreter = interpret(fetchMachine); // console.log('fetch action', interpreter.send('FETCH')); // console.log('state', interpreter.state); // setTimeout(() => { // console.log('state', interpreter.state); // }, 1000)