Collection of Signal Patterns #492
oravecz
started this conversation in
Show and tell
Replies: 3 comments
-
Debounce for Signalexport const debounceSignal = <T>(
targetSignal: Signal<T>,
timeoutMs = 0,
): Signal<T> => {
const debounceSignal = signal<T>(targetSignal.value);
effect(() => {
const value = targetSignal.value;
const timeout = setTimeout(() => {
debounceSignal.value = value;
}, timeoutMs);
return () => {
clearTimeout(timeout);
};
});
return debounceSignal;
}; |
Beta Was this translation helpful? Give feedback.
0 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
I think you could achieve this using the existing signal functionality, something like:
It doesn't hold state like you mentioned however does have the advantage over boolean signals, in that there's no need to set the signal back to false once it has been processed. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Probably not the most ideal spot for this, but as Signals explode in popularity across multiple frameworks, I can't seem to find a set of common patterns for using Signals. So, I thought we might use this discussion to collect them.
Beta Was this translation helpful? Give feedback.
All reactions