personal web client for Bluesky
typescript solidjs bluesky atcute

refactor: wrap resetInfiniteData in batch

mary.my.id 138a91f4 10d4de3d

verified
Changed files
+14 -10
src
api
utils
+14 -10
src/api/utils/query.ts
··· 1 + import { batch } from 'solid-js'; 2 + 1 3 import { 2 4 type InfiniteData, 3 5 type QueryClient, ··· 6 8 } from '@mary/solid-query'; 7 9 8 10 export const resetInfiniteData = (client: QueryClient, queryKey: QueryKey) => { 9 - client.setQueriesData<InfiniteData<unknown>>({ queryKey }, (data) => { 10 - if (data && data.pages.length > 1) { 11 - return { 12 - pages: data.pages.slice(0, 1), 13 - pageParams: data.pageParams.slice(0, 1), 14 - }; 15 - } 11 + batch(() => { 12 + client.setQueriesData<InfiniteData<unknown>>({ queryKey }, (data) => { 13 + if (data && data.pages.length > 1) { 14 + return { 15 + pages: data.pages.slice(0, 1), 16 + pageParams: data.pageParams.slice(0, 1), 17 + }; 18 + } 16 19 17 - return data; 18 - }); 20 + return data; 21 + }); 19 22 20 - client.invalidateQueries({ queryKey }); 23 + client.invalidateQueries({ queryKey }); 24 + }); 21 25 }; 22 26 23 27 const errorMap = new WeakMap<WeakKey, { pageParam: any; direction: 'forward' | 'backward' }>();