how to add debounce to any signal setter ?

I have use case where my my signal is getting called multiple times which is fine as per the implementation. But what I want is to debounce that seignal setter so that it is call in deferred manner and its fine if few calls are missed.
4 Replies
nzdeep
nzdeep2y ago
pretty easy with debounce lib (https://github.com/solidjs-community/solid-primitives/tree/main/packages/scheduled#debounce) const [signal, rawSetSignal] = createSignal(1); const setSignal = debounce(rawSetSignal, 250); // use setSignal
GitHub
solid-primitives/packages/scheduled at main · solidjs-community/sol...
A library of high-quality primitives that extend SolidJS reactivity. - solid-primitives/packages/scheduled at main · solidjs-community/solid-primitives
nzdeep
nzdeep2y ago
However.. I would not recommend this set signal is meant to be fully sync and you'll potentially run into many problems a better approach is debounce the expensive parts of an effects or memo of a signal (not the effect / memo itself) e.g. like a search text autocomplete ajax call
Abrinzer
AbrinzerOP2y ago
@nzdeep thanks for the input. I tried wrapping effect in debounce but it didn't realy work
nzdeep
nzdeep2y ago
sorry I mean what the effect calls yeah ignore the "better approach" that's also bad.. edited what the expensive opereation you need to debounce
Want results from more Discord servers?
Add your server