Skip to content

Instantly share code, notes, and snippets.

@kwiss
Last active May 18, 2020 22:00
Show Gist options
  • Save kwiss/8518e8f3dff8b7327c7a703de1e31ef6 to your computer and use it in GitHub Desktop.
Save kwiss/8518e8f3dff8b7327c7a703de1e31ef6 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 { cancel } = actions;
const sendIncrementAfter10Second = send('TIMER', {
delay: 10000,
id: 'incrementTimer', // give the event a unique ID
});
const cancelTimer = cancel('incrementTimer');
const connectedMachine = Machine({
id: 'fetch',
initial: 'idle',
states: {
idle: {
on: {
START: {
target: 'connected',
},
},
},
connected: {
entry: sendIncrementAfter10Second,
on: {
TIMER: {
target: 'disconnected',
},
PING_FROM_CLIENT: {
target: 'connected',
actions: [
cancelTimer
],
},
}
},
disconnected: {},
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment