I have been experimenting with svelte derived stores. If you look at the console log in the following example, after incrementing store 1 and store 2, then hitting reset, the derived store emits 2 updates.
How would you make this atomic or perhaps debounce it? For example, lets say the scenario were that the derived store issued a new network request based on the combined values of store 1 and 2, if they both changed together you wouldn't want to fire 2 network requsts?
https://svelte.dev/repl/a67c9d37aee348d988e8c30f60a139d9?version=3.28.0
EDIT: Actually, just added a 'reactive' console log and this appears to debounce (tick?) the output.
I think I have answered my own question?
The derived store's callback 2nd argument is
set
, which allows setting the derived value asynchronously.API reference for
derived()
For your case, you could call a debounce function that will eventually call
set
:Svelte REPL