Skip to content

Instantly share code, notes, and snippets.

@robertpenner
Created August 5, 2021 23:48
Show Gist options
  • Save robertpenner/b1b3054f221b2f300e5b69d3493eb85d to your computer and use it in GitHub Desktop.
Save robertpenner/b1b3054f221b2f300e5b69d3493eb85d to your computer and use it in GitHub Desktop.
Generated by XState Viz: https://xstate.js.org/viz
// 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