Skip to content

Instantly share code, notes, and snippets.

@James-Byrne
Last active April 21, 2021 11:06
Show Gist options
  • Save James-Byrne/cc5f039d7e3e3179e97f773e9ae6e6f6 to your computer and use it in GitHub Desktop.
Save James-Byrne/cc5f039d7e3e3179e97f773e9ae6e6f6 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 fetchMachine = Machine({
id: 'fetch',
initial: 'idle',
context: {
value: 0
},
activities: ['tick'],
states: {
idle: {}
}
},{
activities: {
tick: c => {
const tick = setInterval(() => c.value += 1, 1000);
return () => clearInterval(tick);
},
print: c => {
const print = setInterval(() => console.log(c.value), 1000);
return () => clearInterval(print);
}
}
});
const m = interpret(fetchMachine);
m.start();
setInterval(() => {
console.log('m', m.machine.context.value);
}, 500)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment