-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move filters from context to url
- Loading branch information
Showing
8 changed files
with
115 additions
and
139 deletions.
There are no files selected for viewing
File renamed without changes.
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
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 was deleted.
Oops, something went wrong.
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,31 @@ | ||
type Debounced<T extends (...args: any) => any> = { | ||
/** The debounced function, without any return value */ | ||
(...args: Parameters<T>): void; | ||
/** Cancel the debounced timer and prevent the function being called */ | ||
cancel(): void; | ||
}; | ||
|
||
/** | ||
* Create a function that which is called after some delay. | ||
* The delay timer is reset every time the function is called. | ||
* It's possible to fully cancel the function by using `debounce(...).cancel()`. | ||
*/ | ||
export function debounce<T extends (...args: any) => any>(action: T, delay = 500): Debounced<T> { | ||
let timerId: ReturnType<typeof setTimeout> | null = null; | ||
|
||
function cancel() { | ||
if (timerId) { | ||
clearTimeout(timerId); | ||
timerId = null; | ||
} | ||
} | ||
|
||
const debounced = (...args: any[]) => { | ||
if (timerId) clearTimeout(timerId); | ||
timerId = setTimeout(() => action(...args), delay); | ||
}; | ||
|
||
debounced.cancel = cancel; | ||
|
||
return debounced; | ||
} |