Last active
December 23, 2019 12:44
-
-
Save spiffytech/ab15bb3661c47e84e5d3774236fb2ca2 to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment