-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ validate the nickname when the user stops typing (#230) (#235)
* ✨ feat: validate nickname when the user stops typing after some delay * ✨ feat(utils): added stops typing svelte action * ✨ feat(utils): added debounce helper
- Loading branch information
Showing
4 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Debounce function | ||
* | ||
* @param fn Function to debounce | ||
* @param waitFor Time to wait before executing the function | ||
* | ||
* @example | ||
* const fn = () => console.log('Debounced!'); | ||
* const debounced = debounce(fn, 1000); | ||
*/ | ||
export const debounce = <Params extends unknown[]>( | ||
fn: (...args: Params) => void, | ||
waitFor = 800 | ||
) => { | ||
let timer: NodeJS.Timeout; | ||
|
||
return (...args: Params) => { | ||
clearTimeout(timer); | ||
timer = setTimeout(() => fn(...args), waitFor); | ||
}; | ||
}; |