tsdf 12.5.0 → 12.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.cjs +49 -6
- package/dist/main.d.cts +3 -1
- package/dist/main.d.ts +3 -1
- package/dist/main.js +49 -6
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -313,6 +313,14 @@ function useDeepCompareMemoize(value, equalityFn = import_t_state.deepEqual) {
|
|
|
313
313
|
function useDeepMemo(callback, deeps) {
|
|
314
314
|
return (0, import_react.useMemo)(callback, useDeepCompareMemoize(deeps));
|
|
315
315
|
}
|
|
316
|
+
function useLatestValue(value) {
|
|
317
|
+
const ref = (0, import_react.useRef)({ insideEffect: value, insideMemo: value });
|
|
318
|
+
ref.current.insideMemo = value;
|
|
319
|
+
(0, import_react.useLayoutEffect)(() => {
|
|
320
|
+
ref.current.insideEffect = value;
|
|
321
|
+
});
|
|
322
|
+
return ref.current;
|
|
323
|
+
}
|
|
316
324
|
function usePrevious(value, initial) {
|
|
317
325
|
const ref = (0, import_react.useRef)(initial);
|
|
318
326
|
(0, import_react.useEffect)(() => {
|
|
@@ -2197,17 +2205,43 @@ function useTimeout(ms) {
|
|
|
2197
2205
|
function useListItemIsLoading({
|
|
2198
2206
|
isLoading,
|
|
2199
2207
|
isRefetching,
|
|
2200
|
-
isNotFound
|
|
2208
|
+
isNotFound,
|
|
2209
|
+
loadItemFallback,
|
|
2210
|
+
itemId
|
|
2201
2211
|
}) {
|
|
2202
2212
|
const [willBeRefetched, setWillBeRefetched] = (0, import_react11.useState)(isNotFound);
|
|
2203
|
-
const
|
|
2213
|
+
const resetWillBeRefechedTimeout = useTimeout(1e3);
|
|
2214
|
+
const callFallbackLoadItemTimeout = useTimeout(100);
|
|
2204
2215
|
const ignoreSetWillBeRefetched = (0, import_react11.useRef)(false);
|
|
2205
|
-
|
|
2216
|
+
const itemWasRefetched = useConst(() => /* @__PURE__ */ new Set());
|
|
2217
|
+
if (isNotFound && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && !itemWasRefetched.has(itemId)) {
|
|
2206
2218
|
setWillBeRefetched(true);
|
|
2207
2219
|
}
|
|
2220
|
+
const latestIsLoadingOrRefetching = useLatestValue(isLoading || isRefetching);
|
|
2221
|
+
const latestLoadItemFallback = useLatestValue(loadItemFallback);
|
|
2222
|
+
(0, import_react11.useEffect)(() => {
|
|
2223
|
+
if (isRefetching) {
|
|
2224
|
+
itemWasRefetched.add(itemId);
|
|
2225
|
+
resetWillBeRefechedTimeout.clear();
|
|
2226
|
+
callFallbackLoadItemTimeout.clear();
|
|
2227
|
+
setWillBeRefetched(false);
|
|
2228
|
+
}
|
|
2229
|
+
}, [
|
|
2230
|
+
callFallbackLoadItemTimeout,
|
|
2231
|
+
isRefetching,
|
|
2232
|
+
itemId,
|
|
2233
|
+
itemWasRefetched,
|
|
2234
|
+
resetWillBeRefechedTimeout
|
|
2235
|
+
]);
|
|
2208
2236
|
(0, import_react11.useEffect)(() => {
|
|
2209
2237
|
if (willBeRefetched) {
|
|
2210
|
-
|
|
2238
|
+
callFallbackLoadItemTimeout.call(() => {
|
|
2239
|
+
if (!latestIsLoadingOrRefetching.insideEffect) {
|
|
2240
|
+
latestLoadItemFallback.insideEffect();
|
|
2241
|
+
return;
|
|
2242
|
+
}
|
|
2243
|
+
});
|
|
2244
|
+
resetWillBeRefechedTimeout.call(() => {
|
|
2211
2245
|
ignoreSetWillBeRefetched.current = true;
|
|
2212
2246
|
setWillBeRefetched(false);
|
|
2213
2247
|
setTimeout(() => {
|
|
@@ -2215,8 +2249,17 @@ function useListItemIsLoading({
|
|
|
2215
2249
|
}, 20);
|
|
2216
2250
|
});
|
|
2217
2251
|
}
|
|
2218
|
-
return () =>
|
|
2219
|
-
|
|
2252
|
+
return () => {
|
|
2253
|
+
resetWillBeRefechedTimeout.clear();
|
|
2254
|
+
callFallbackLoadItemTimeout.clear();
|
|
2255
|
+
};
|
|
2256
|
+
}, [
|
|
2257
|
+
resetWillBeRefechedTimeout,
|
|
2258
|
+
willBeRefetched,
|
|
2259
|
+
latestIsLoadingOrRefetching,
|
|
2260
|
+
latestLoadItemFallback,
|
|
2261
|
+
callFallbackLoadItemTimeout
|
|
2262
|
+
]);
|
|
2220
2263
|
return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
|
|
2221
2264
|
}
|
|
2222
2265
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/main.d.cts
CHANGED
|
@@ -335,10 +335,12 @@ type TSFDListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload
|
|
|
335
335
|
|
|
336
336
|
/** Use to detect if a item of a list may be loading in cases which there is no
|
|
337
337
|
* clear indication of the status of individual items, ex: an item in a document collection that is loaded on demand */
|
|
338
|
-
declare function useListItemIsLoading({ isLoading, isRefetching, isNotFound, }: {
|
|
338
|
+
declare function useListItemIsLoading({ isLoading, isRefetching, isNotFound, loadItemFallback, itemId, }: {
|
|
339
|
+
itemId: string;
|
|
339
340
|
isRefetching: boolean;
|
|
340
341
|
isLoading: boolean;
|
|
341
342
|
isNotFound: boolean;
|
|
343
|
+
loadItemFallback: () => void;
|
|
342
344
|
}): boolean;
|
|
343
345
|
|
|
344
346
|
export { CollectionInitialStateItem, FetchListFnReturn, FetchListFnReturnItem, ListQueryStoreInitialData, OnCollectionItemInvalidate, OnDocumentInvalidate, OnListQueryInvalidate, OnListQueryItemInvalidate, TSDFCollectionStore, TSDFDocumentStore, TSDFDocumentStoreState, TSDFItemQuery, TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, TSFDListQuery, TSFDListQueryState, TSFDListQueryStore, TSFDUseCollectionItemReturn, TSFDUseListItemReturn, TSFDUseListQueryReturn, ValidPayload, ValidStoreState, newTSDFCollectionStore, newTSDFDocumentStore, newTSDFListQueryStore, useListItemIsLoading };
|
package/dist/main.d.ts
CHANGED
|
@@ -335,10 +335,12 @@ type TSFDListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload
|
|
|
335
335
|
|
|
336
336
|
/** Use to detect if a item of a list may be loading in cases which there is no
|
|
337
337
|
* clear indication of the status of individual items, ex: an item in a document collection that is loaded on demand */
|
|
338
|
-
declare function useListItemIsLoading({ isLoading, isRefetching, isNotFound, }: {
|
|
338
|
+
declare function useListItemIsLoading({ isLoading, isRefetching, isNotFound, loadItemFallback, itemId, }: {
|
|
339
|
+
itemId: string;
|
|
339
340
|
isRefetching: boolean;
|
|
340
341
|
isLoading: boolean;
|
|
341
342
|
isNotFound: boolean;
|
|
343
|
+
loadItemFallback: () => void;
|
|
342
344
|
}): boolean;
|
|
343
345
|
|
|
344
346
|
export { CollectionInitialStateItem, FetchListFnReturn, FetchListFnReturnItem, ListQueryStoreInitialData, OnCollectionItemInvalidate, OnDocumentInvalidate, OnListQueryInvalidate, OnListQueryItemInvalidate, TSDFCollectionStore, TSDFDocumentStore, TSDFDocumentStoreState, TSDFItemQuery, TSDFStatus, TSDFUseDocumentReturn, TSFDCollectionItem, TSFDCollectionState, TSFDListQuery, TSFDListQueryState, TSFDListQueryStore, TSFDUseCollectionItemReturn, TSFDUseListItemReturn, TSFDUseListQueryReturn, ValidPayload, ValidStoreState, newTSDFCollectionStore, newTSDFDocumentStore, newTSDFListQueryStore, useListItemIsLoading };
|
package/dist/main.js
CHANGED
|
@@ -284,6 +284,14 @@ function useDeepCompareMemoize(value, equalityFn = deepEqual) {
|
|
|
284
284
|
function useDeepMemo(callback, deeps) {
|
|
285
285
|
return useMemo(callback, useDeepCompareMemoize(deeps));
|
|
286
286
|
}
|
|
287
|
+
function useLatestValue(value) {
|
|
288
|
+
const ref = useRef({ insideEffect: value, insideMemo: value });
|
|
289
|
+
ref.current.insideMemo = value;
|
|
290
|
+
useLayoutEffect(() => {
|
|
291
|
+
ref.current.insideEffect = value;
|
|
292
|
+
});
|
|
293
|
+
return ref.current;
|
|
294
|
+
}
|
|
287
295
|
function usePrevious(value, initial) {
|
|
288
296
|
const ref = useRef(initial);
|
|
289
297
|
useEffect(() => {
|
|
@@ -2168,17 +2176,43 @@ function useTimeout(ms) {
|
|
|
2168
2176
|
function useListItemIsLoading({
|
|
2169
2177
|
isLoading,
|
|
2170
2178
|
isRefetching,
|
|
2171
|
-
isNotFound
|
|
2179
|
+
isNotFound,
|
|
2180
|
+
loadItemFallback,
|
|
2181
|
+
itemId
|
|
2172
2182
|
}) {
|
|
2173
2183
|
const [willBeRefetched, setWillBeRefetched] = useState2(isNotFound);
|
|
2174
|
-
const
|
|
2184
|
+
const resetWillBeRefechedTimeout = useTimeout(1e3);
|
|
2185
|
+
const callFallbackLoadItemTimeout = useTimeout(100);
|
|
2175
2186
|
const ignoreSetWillBeRefetched = useRef2(false);
|
|
2176
|
-
|
|
2187
|
+
const itemWasRefetched = useConst(() => /* @__PURE__ */ new Set());
|
|
2188
|
+
if (isNotFound && !isRefetching && !willBeRefetched && !ignoreSetWillBeRefetched.current && !itemWasRefetched.has(itemId)) {
|
|
2177
2189
|
setWillBeRefetched(true);
|
|
2178
2190
|
}
|
|
2191
|
+
const latestIsLoadingOrRefetching = useLatestValue(isLoading || isRefetching);
|
|
2192
|
+
const latestLoadItemFallback = useLatestValue(loadItemFallback);
|
|
2193
|
+
useEffect6(() => {
|
|
2194
|
+
if (isRefetching) {
|
|
2195
|
+
itemWasRefetched.add(itemId);
|
|
2196
|
+
resetWillBeRefechedTimeout.clear();
|
|
2197
|
+
callFallbackLoadItemTimeout.clear();
|
|
2198
|
+
setWillBeRefetched(false);
|
|
2199
|
+
}
|
|
2200
|
+
}, [
|
|
2201
|
+
callFallbackLoadItemTimeout,
|
|
2202
|
+
isRefetching,
|
|
2203
|
+
itemId,
|
|
2204
|
+
itemWasRefetched,
|
|
2205
|
+
resetWillBeRefechedTimeout
|
|
2206
|
+
]);
|
|
2179
2207
|
useEffect6(() => {
|
|
2180
2208
|
if (willBeRefetched) {
|
|
2181
|
-
|
|
2209
|
+
callFallbackLoadItemTimeout.call(() => {
|
|
2210
|
+
if (!latestIsLoadingOrRefetching.insideEffect) {
|
|
2211
|
+
latestLoadItemFallback.insideEffect();
|
|
2212
|
+
return;
|
|
2213
|
+
}
|
|
2214
|
+
});
|
|
2215
|
+
resetWillBeRefechedTimeout.call(() => {
|
|
2182
2216
|
ignoreSetWillBeRefetched.current = true;
|
|
2183
2217
|
setWillBeRefetched(false);
|
|
2184
2218
|
setTimeout(() => {
|
|
@@ -2186,8 +2220,17 @@ function useListItemIsLoading({
|
|
|
2186
2220
|
}, 20);
|
|
2187
2221
|
});
|
|
2188
2222
|
}
|
|
2189
|
-
return () =>
|
|
2190
|
-
|
|
2223
|
+
return () => {
|
|
2224
|
+
resetWillBeRefechedTimeout.clear();
|
|
2225
|
+
callFallbackLoadItemTimeout.clear();
|
|
2226
|
+
};
|
|
2227
|
+
}, [
|
|
2228
|
+
resetWillBeRefechedTimeout,
|
|
2229
|
+
willBeRefetched,
|
|
2230
|
+
latestIsLoadingOrRefetching,
|
|
2231
|
+
latestLoadItemFallback,
|
|
2232
|
+
callFallbackLoadItemTimeout
|
|
2233
|
+
]);
|
|
2191
2234
|
return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
|
|
2192
2235
|
}
|
|
2193
2236
|
export {
|