tsdf 12.5.0 → 12.6.1
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 +50 -6
- package/dist/main.d.cts +3 -1
- package/dist/main.d.ts +3 -1
- package/dist/main.js +50 -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,44 @@ 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 && itemId && !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
|
+
if (itemId)
|
|
2225
|
+
itemWasRefetched.add(itemId);
|
|
2226
|
+
resetWillBeRefechedTimeout.clear();
|
|
2227
|
+
callFallbackLoadItemTimeout.clear();
|
|
2228
|
+
setWillBeRefetched(false);
|
|
2229
|
+
}
|
|
2230
|
+
}, [
|
|
2231
|
+
callFallbackLoadItemTimeout,
|
|
2232
|
+
isRefetching,
|
|
2233
|
+
itemId,
|
|
2234
|
+
itemWasRefetched,
|
|
2235
|
+
resetWillBeRefechedTimeout
|
|
2236
|
+
]);
|
|
2208
2237
|
(0, import_react11.useEffect)(() => {
|
|
2209
2238
|
if (willBeRefetched) {
|
|
2210
|
-
|
|
2239
|
+
callFallbackLoadItemTimeout.call(() => {
|
|
2240
|
+
if (!latestIsLoadingOrRefetching.insideEffect) {
|
|
2241
|
+
latestLoadItemFallback.insideEffect();
|
|
2242
|
+
return;
|
|
2243
|
+
}
|
|
2244
|
+
});
|
|
2245
|
+
resetWillBeRefechedTimeout.call(() => {
|
|
2211
2246
|
ignoreSetWillBeRefetched.current = true;
|
|
2212
2247
|
setWillBeRefetched(false);
|
|
2213
2248
|
setTimeout(() => {
|
|
@@ -2215,8 +2250,17 @@ function useListItemIsLoading({
|
|
|
2215
2250
|
}, 20);
|
|
2216
2251
|
});
|
|
2217
2252
|
}
|
|
2218
|
-
return () =>
|
|
2219
|
-
|
|
2253
|
+
return () => {
|
|
2254
|
+
resetWillBeRefechedTimeout.clear();
|
|
2255
|
+
callFallbackLoadItemTimeout.clear();
|
|
2256
|
+
};
|
|
2257
|
+
}, [
|
|
2258
|
+
resetWillBeRefechedTimeout,
|
|
2259
|
+
willBeRefetched,
|
|
2260
|
+
latestIsLoadingOrRefetching,
|
|
2261
|
+
latestLoadItemFallback,
|
|
2262
|
+
callFallbackLoadItemTimeout
|
|
2263
|
+
]);
|
|
2220
2264
|
return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
|
|
2221
2265
|
}
|
|
2222
2266
|
// 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 | null | false;
|
|
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 | null | false;
|
|
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,44 @@ 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 && itemId && !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
|
+
if (itemId)
|
|
2196
|
+
itemWasRefetched.add(itemId);
|
|
2197
|
+
resetWillBeRefechedTimeout.clear();
|
|
2198
|
+
callFallbackLoadItemTimeout.clear();
|
|
2199
|
+
setWillBeRefetched(false);
|
|
2200
|
+
}
|
|
2201
|
+
}, [
|
|
2202
|
+
callFallbackLoadItemTimeout,
|
|
2203
|
+
isRefetching,
|
|
2204
|
+
itemId,
|
|
2205
|
+
itemWasRefetched,
|
|
2206
|
+
resetWillBeRefechedTimeout
|
|
2207
|
+
]);
|
|
2179
2208
|
useEffect6(() => {
|
|
2180
2209
|
if (willBeRefetched) {
|
|
2181
|
-
|
|
2210
|
+
callFallbackLoadItemTimeout.call(() => {
|
|
2211
|
+
if (!latestIsLoadingOrRefetching.insideEffect) {
|
|
2212
|
+
latestLoadItemFallback.insideEffect();
|
|
2213
|
+
return;
|
|
2214
|
+
}
|
|
2215
|
+
});
|
|
2216
|
+
resetWillBeRefechedTimeout.call(() => {
|
|
2182
2217
|
ignoreSetWillBeRefetched.current = true;
|
|
2183
2218
|
setWillBeRefetched(false);
|
|
2184
2219
|
setTimeout(() => {
|
|
@@ -2186,8 +2221,17 @@ function useListItemIsLoading({
|
|
|
2186
2221
|
}, 20);
|
|
2187
2222
|
});
|
|
2188
2223
|
}
|
|
2189
|
-
return () =>
|
|
2190
|
-
|
|
2224
|
+
return () => {
|
|
2225
|
+
resetWillBeRefechedTimeout.clear();
|
|
2226
|
+
callFallbackLoadItemTimeout.clear();
|
|
2227
|
+
};
|
|
2228
|
+
}, [
|
|
2229
|
+
resetWillBeRefechedTimeout,
|
|
2230
|
+
willBeRefetched,
|
|
2231
|
+
latestIsLoadingOrRefetching,
|
|
2232
|
+
latestLoadItemFallback,
|
|
2233
|
+
callFallbackLoadItemTimeout
|
|
2234
|
+
]);
|
|
2191
2235
|
return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
|
|
2192
2236
|
}
|
|
2193
2237
|
export {
|