Created
August 5, 2021 23:48
-
-
Save robertpenner/b1b3054f221b2f300e5b69d3493eb85d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
This file contains hidden or 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
// Copied from: | |
// https://xstate-catalogue.com/machines/debounce | |
const fetchMachine = Machine({ | |
id: 'debounce', | |
initial: 'idle', | |
states: { | |
idle: { | |
on: { | |
GO: { | |
actions: 'assignActionToContext', | |
target: 'debouncing', | |
}, | |
}, | |
}, | |
debouncing: { | |
on: { | |
GO: { | |
actions: 'assignActionToContext', | |
target: 'debouncing', | |
}, | |
}, | |
after: { | |
2000: { | |
target: 'idle', | |
actions: 'performAction', | |
}, | |
}, | |
}, | |
}, | |
}, | |
{ | |
actions: { | |
clearAction: assign({ | |
action: undefined, | |
}), | |
assignActionToContext: assign((context, event) => { | |
return { | |
action: event.action, | |
}; | |
}), | |
performAction: (context) => { | |
return context.action(); | |
}, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment