Merge remote-tracking branch 'parent/main' into upstream-20240926
This commit is contained in:
commit
c905714459
517 changed files with 4284 additions and 3891 deletions
23
app/javascript/mastodon/utils/debounce.ts
Normal file
23
app/javascript/mastodon/utils/debounce.ts
Normal file
|
@ -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();
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue