forked from mastodon/mastodon
-
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.
Fix too many requests caused by relationship look-ups in web UI (mast…
…odon#32042) Co-authored-by: Claire <[email protected]>
- Loading branch information
1 parent
f1b6a61
commit 7098851
Showing
3 changed files
with
40 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { debounce } from 'lodash'; | ||
|
||
import type { AppDispatch } from 'mastodon/store'; | ||
|
||
export const debounceWithDispatchAndArguments = <T>( | ||
fn: (dispatch: AppDispatch, ...args: T[]) => void, | ||
{ delay = 100 }, | ||
) => { | ||
let argumentBuffer: T[] = []; | ||
let dispatchBuffer: AppDispatch; | ||
|
||
const wrapped = debounce(() => { | ||
const tmpBuffer = argumentBuffer; | ||
argumentBuffer = []; | ||
fn(dispatchBuffer, ...tmpBuffer); | ||
}, delay); | ||
|
||
return (dispatch: AppDispatch, ...args: T[]) => { | ||
dispatchBuffer = dispatch; | ||
argumentBuffer.push(...args); | ||
wrapped(); | ||
}; | ||
}; |