Use react-redux's batch instead of react's

This commit is contained in:
Fedor Indutny 2021-11-01 16:38:08 -07:00 committed by GitHub
parent 3190f95fac
commit 663cd77eac
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 123 additions and 66 deletions

View file

@ -31,6 +31,7 @@ export type BatcherOptionsType<ItemType> = {
export type BatcherType<ItemType> = {
add: (item: ItemType) => void;
removeAll: (needle: ItemType) => void;
anyPending: () => boolean;
onIdle: () => Promise<void>;
flushAndWait: () => Promise<void>;
@ -70,6 +71,10 @@ export function createBatcher<ItemType>(
}
}
function removeAll(needle: ItemType) {
items = items.filter(item => item !== needle);
}
function anyPending(): boolean {
return queue.size > 0 || queue.pending > 0 || items.length > 0;
}
@ -108,6 +113,7 @@ export function createBatcher<ItemType>(
batcher = {
add,
removeAll,
anyPending,
onIdle,
flushAndWait,