Skip to content

Instantly share code, notes, and snippets.

@spiffytech
Last active December 23, 2019 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiffytech/ab15bb3661c47e84e5d3774236fb2ca2 to your computer and use it in GitHub Desktop.
Save spiffytech/ab15bb3661c47e84e5d3774236fb2ca2 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 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