Last active
July 20, 2022 19:11
-
-
Save hnordt/523bb2a941e1b9eb6f6eb444e9c5ba07 to your computer and use it in GitHub Desktop.
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
// Copy and paste into https://statecharts.github.io/xstate-viz/ | |
const paginationMachine = Machine( | |
{ | |
id: "pagination", | |
initial: "idle", | |
states: { | |
idle: {}, | |
debouncing: { | |
onEntry: ["setParams", "resetPage", "resetResults"], | |
after: { | |
1000: "pending" | |
} | |
}, | |
pending: { | |
onEntry: "incrementPage", | |
invoke: { | |
src: "loadResults", | |
onDone: "fulfilled", | |
onError: "rejected" | |
} | |
}, | |
fulfilled: { | |
onEntry: "appendResults", | |
on: { | |
END_REACHED: "noMoreResults" | |
} | |
}, | |
noMoreResults: { | |
on: { | |
"": { | |
target: "pending", | |
cond: "hasMoreResults" | |
} | |
} | |
}, | |
rejected: { | |
onEntry: ["decrementPage", "setError"], | |
onExit: "resetError", | |
on: { | |
RETRY: "pending" | |
} | |
} | |
}, | |
on: { | |
UPDATE_PARAMS: "debouncing" | |
} | |
}, | |
{ | |
guards: { | |
hasMoreResults: () => true | |
}, | |
services: { | |
loadResults: () => | |
new Promise(r => setTimeout(r, 500)) | |
} | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment