Last active
December 23, 2019 12:31
-
-
Save spiffytech/97d864cfa40eb2f600bef6f1b4925e3e 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' | |
}, | |
on: { | |
loaded: { | |
target: 'loaded', | |
internal: true, | |
actions: assign((context) => ({value: context.value + 1})) | |
} | |
}, | |
states: { | |
loading: {}, | |
loaded: {} | |
} | |
}, { | |
services: { | |
onload: () => (fireEvent) => { | |
setTimeout(() => fireEvent('loaded'), 1000) | |
} | |
} | |
}); | |
const service = interpret(machine); | |
service.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment