Last active
May 18, 2020 22:00
-
-
Save kwiss/8518e8f3dff8b7327c7a703de1e31ef6 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 { 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