// Available variables: // - Machine // - interpret // - assign // - send // - sendParent // - spawn // - raise // - actions // - XState (all XState exports) const machine = Machine({ initial: 'loading', context: { value: 0 }, invoke: { src: 'onload', onError: { target: 'error', internal: true, actions: assign((context, event) => ({...context, error: event.data})) } }, on: { loaded: { target: 'loaded', internal: true, actions: assign((context) => ({value: context.value + 1})) } }, states: { loading: {}, loaded: {}, error: {} } }, { services: { onload: () => (fireEvent) => { throw new Error("An error"); } } }); const service = interpret(machine); service.start();