tsdf 12.4.0 → 12.5.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 +58 -2
- package/dist/main.d.cts +9 -1
- package/dist/main.d.ts +9 -1
- package/dist/main.js +56 -1
- package/package.json +22 -22
package/dist/main.cjs
CHANGED
|
@@ -22,7 +22,8 @@ var main_exports = {};
|
|
|
22
22
|
__export(main_exports, {
|
|
23
23
|
newTSDFCollectionStore: () => newTSDFCollectionStore,
|
|
24
24
|
newTSDFDocumentStore: () => newTSDFDocumentStore,
|
|
25
|
-
newTSDFListQueryStore: () => newTSDFListQueryStore
|
|
25
|
+
newTSDFListQueryStore: () => newTSDFListQueryStore,
|
|
26
|
+
useListItemIsLoading: () => useListItemIsLoading
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(main_exports);
|
|
28
29
|
|
|
@@ -2164,9 +2165,64 @@ function newTSDFListQueryStore({
|
|
|
2164
2165
|
useFindItem
|
|
2165
2166
|
};
|
|
2166
2167
|
}
|
|
2168
|
+
|
|
2169
|
+
// src/useListItemIsLoading.ts
|
|
2170
|
+
var import_react11 = require("react");
|
|
2171
|
+
|
|
2172
|
+
// src/utils/useTimeout.ts
|
|
2173
|
+
var import_react10 = require("react");
|
|
2174
|
+
function useTimeout(ms) {
|
|
2175
|
+
const timeoutsRef = useConst(() => /* @__PURE__ */ new Set());
|
|
2176
|
+
const callback = (0, import_react10.useCallback)(
|
|
2177
|
+
(cb, overrideMs = ms) => {
|
|
2178
|
+
timeoutsRef.add(window.setTimeout(cb, overrideMs));
|
|
2179
|
+
},
|
|
2180
|
+
[ms, timeoutsRef]
|
|
2181
|
+
);
|
|
2182
|
+
const clear = (0, import_react10.useCallback)(() => {
|
|
2183
|
+
for (const timeout of timeoutsRef) {
|
|
2184
|
+
clearTimeout(timeout);
|
|
2185
|
+
}
|
|
2186
|
+
}, [timeoutsRef]);
|
|
2187
|
+
(0, import_react10.useEffect)(() => clear, [clear]);
|
|
2188
|
+
return (0, import_react10.useMemo)(() => {
|
|
2189
|
+
return {
|
|
2190
|
+
call: callback,
|
|
2191
|
+
clear
|
|
2192
|
+
};
|
|
2193
|
+
}, [callback, clear]);
|
|
2194
|
+
}
|
|
2195
|
+
|
|
2196
|
+
// src/useListItemIsLoading.ts
|
|
2197
|
+
function useListItemIsLoading({
|
|
2198
|
+
isLoading,
|
|
2199
|
+
isRefetching,
|
|
2200
|
+
isNotFound
|
|
2201
|
+
}) {
|
|
2202
|
+
const [willBeRefetched, setWillBeRefetched] = (0, import_react11.useState)(isNotFound);
|
|
2203
|
+
const timeout = useTimeout(1e3);
|
|
2204
|
+
const ignoreSetWillBeRefetched = (0, import_react11.useRef)(false);
|
|
2205
|
+
if (isNotFound && !willBeRefetched && !ignoreSetWillBeRefetched.current) {
|
|
2206
|
+
setWillBeRefetched(true);
|
|
2207
|
+
}
|
|
2208
|
+
(0, import_react11.useEffect)(() => {
|
|
2209
|
+
if (willBeRefetched) {
|
|
2210
|
+
timeout.call(() => {
|
|
2211
|
+
ignoreSetWillBeRefetched.current = true;
|
|
2212
|
+
setWillBeRefetched(false);
|
|
2213
|
+
setTimeout(() => {
|
|
2214
|
+
ignoreSetWillBeRefetched.current = false;
|
|
2215
|
+
}, 20);
|
|
2216
|
+
});
|
|
2217
|
+
}
|
|
2218
|
+
return () => timeout.clear();
|
|
2219
|
+
}, [timeout, willBeRefetched]);
|
|
2220
|
+
return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
|
|
2221
|
+
}
|
|
2167
2222
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2168
2223
|
0 && (module.exports = {
|
|
2169
2224
|
newTSDFCollectionStore,
|
|
2170
2225
|
newTSDFDocumentStore,
|
|
2171
|
-
newTSDFListQueryStore
|
|
2226
|
+
newTSDFListQueryStore,
|
|
2227
|
+
useListItemIsLoading
|
|
2172
2228
|
});
|
package/dist/main.d.cts
CHANGED
|
@@ -333,4 +333,12 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
333
333
|
};
|
|
334
334
|
type TSFDListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = ReturnType<typeof newTSDFListQueryStore<ItemState, NError, QueryPayload, ItemPayload>>;
|
|
335
335
|
|
|
336
|
-
|
|
336
|
+
/** Use to detect if a item of a list may be loading in cases which there is no
|
|
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, }: {
|
|
339
|
+
isRefetching: boolean;
|
|
340
|
+
isLoading: boolean;
|
|
341
|
+
isNotFound: boolean;
|
|
342
|
+
}): boolean;
|
|
343
|
+
|
|
344
|
+
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
|
@@ -333,4 +333,12 @@ declare function newTSDFListQueryStore<ItemState extends ValidStoreState, NError
|
|
|
333
333
|
};
|
|
334
334
|
type TSFDListQueryStore<ItemState extends ValidStoreState, NError, QueryPayload extends ValidPayload, ItemPayload extends ValidPayload> = ReturnType<typeof newTSDFListQueryStore<ItemState, NError, QueryPayload, ItemPayload>>;
|
|
335
335
|
|
|
336
|
-
|
|
336
|
+
/** Use to detect if a item of a list may be loading in cases which there is no
|
|
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, }: {
|
|
339
|
+
isRefetching: boolean;
|
|
340
|
+
isLoading: boolean;
|
|
341
|
+
isNotFound: boolean;
|
|
342
|
+
}): boolean;
|
|
343
|
+
|
|
344
|
+
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
|
@@ -2136,8 +2136,63 @@ function newTSDFListQueryStore({
|
|
|
2136
2136
|
useFindItem
|
|
2137
2137
|
};
|
|
2138
2138
|
}
|
|
2139
|
+
|
|
2140
|
+
// src/useListItemIsLoading.ts
|
|
2141
|
+
import { useEffect as useEffect6, useRef as useRef2, useState as useState2 } from "react";
|
|
2142
|
+
|
|
2143
|
+
// src/utils/useTimeout.ts
|
|
2144
|
+
import { useCallback as useCallback4, useEffect as useEffect5, useMemo as useMemo5 } from "react";
|
|
2145
|
+
function useTimeout(ms) {
|
|
2146
|
+
const timeoutsRef = useConst(() => /* @__PURE__ */ new Set());
|
|
2147
|
+
const callback = useCallback4(
|
|
2148
|
+
(cb, overrideMs = ms) => {
|
|
2149
|
+
timeoutsRef.add(window.setTimeout(cb, overrideMs));
|
|
2150
|
+
},
|
|
2151
|
+
[ms, timeoutsRef]
|
|
2152
|
+
);
|
|
2153
|
+
const clear = useCallback4(() => {
|
|
2154
|
+
for (const timeout of timeoutsRef) {
|
|
2155
|
+
clearTimeout(timeout);
|
|
2156
|
+
}
|
|
2157
|
+
}, [timeoutsRef]);
|
|
2158
|
+
useEffect5(() => clear, [clear]);
|
|
2159
|
+
return useMemo5(() => {
|
|
2160
|
+
return {
|
|
2161
|
+
call: callback,
|
|
2162
|
+
clear
|
|
2163
|
+
};
|
|
2164
|
+
}, [callback, clear]);
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
// src/useListItemIsLoading.ts
|
|
2168
|
+
function useListItemIsLoading({
|
|
2169
|
+
isLoading,
|
|
2170
|
+
isRefetching,
|
|
2171
|
+
isNotFound
|
|
2172
|
+
}) {
|
|
2173
|
+
const [willBeRefetched, setWillBeRefetched] = useState2(isNotFound);
|
|
2174
|
+
const timeout = useTimeout(1e3);
|
|
2175
|
+
const ignoreSetWillBeRefetched = useRef2(false);
|
|
2176
|
+
if (isNotFound && !willBeRefetched && !ignoreSetWillBeRefetched.current) {
|
|
2177
|
+
setWillBeRefetched(true);
|
|
2178
|
+
}
|
|
2179
|
+
useEffect6(() => {
|
|
2180
|
+
if (willBeRefetched) {
|
|
2181
|
+
timeout.call(() => {
|
|
2182
|
+
ignoreSetWillBeRefetched.current = true;
|
|
2183
|
+
setWillBeRefetched(false);
|
|
2184
|
+
setTimeout(() => {
|
|
2185
|
+
ignoreSetWillBeRefetched.current = false;
|
|
2186
|
+
}, 20);
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
return () => timeout.clear();
|
|
2190
|
+
}, [timeout, willBeRefetched]);
|
|
2191
|
+
return isLoading || isNotFound && (isRefetching || !!willBeRefetched);
|
|
2192
|
+
}
|
|
2139
2193
|
export {
|
|
2140
2194
|
newTSDFCollectionStore,
|
|
2141
2195
|
newTSDFDocumentStore,
|
|
2142
|
-
newTSDFListQueryStore
|
|
2196
|
+
newTSDFListQueryStore,
|
|
2197
|
+
useListItemIsLoading
|
|
2143
2198
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tsdf",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.5.0",
|
|
4
4
|
"description": "A data fetching solution based on t-state",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Lucas Santos",
|
|
@@ -23,38 +23,38 @@
|
|
|
23
23
|
"node": ">=16.0.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@lucasols/eslint-plugin-extended-lint": "^
|
|
27
|
-
"@testing-library/jest-dom": "^
|
|
26
|
+
"@lucasols/eslint-plugin-extended-lint": "^1.4.0",
|
|
27
|
+
"@testing-library/jest-dom": "^6.1.3",
|
|
28
28
|
"@testing-library/react": "^14.0.0",
|
|
29
|
-
"@types/node": "^20.4
|
|
30
|
-
"@types/react": "^18.
|
|
31
|
-
"@types/react-dom": "^18.
|
|
32
|
-
"@types/testing-library__jest-dom": "^
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
34
|
-
"@typescript-eslint/parser": "^6.
|
|
35
|
-
"@vitest/ui": "0.
|
|
36
|
-
"eslint": "^8.
|
|
37
|
-
"eslint-plugin-local-rules": "^
|
|
29
|
+
"@types/node": "^20.8.4",
|
|
30
|
+
"@types/react": "^18.2.28",
|
|
31
|
+
"@types/react-dom": "^18.2.13",
|
|
32
|
+
"@types/testing-library__jest-dom": "^6.0.0",
|
|
33
|
+
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
34
|
+
"@typescript-eslint/parser": "^6.7.5",
|
|
35
|
+
"@vitest/ui": "1.0.0-beta.1",
|
|
36
|
+
"eslint": "^8.51.0",
|
|
37
|
+
"eslint-plugin-local-rules": "^2.0.0",
|
|
38
38
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
39
|
-
"eslint-plugin-vitest": "^0.2
|
|
40
|
-
"happy-dom": "^
|
|
39
|
+
"eslint-plugin-vitest": "^0.3.2",
|
|
40
|
+
"happy-dom": "^12.9.1",
|
|
41
41
|
"jsdom": "^22.1.0",
|
|
42
|
-
"prettier": "^3.0.
|
|
43
|
-
"pretty-format": "^29.
|
|
42
|
+
"prettier": "^3.0.3",
|
|
43
|
+
"pretty-format": "^29.7.0",
|
|
44
44
|
"react": "^18.2.0",
|
|
45
45
|
"react-dom": "^18.2.0",
|
|
46
46
|
"tiny-glob": "^0.2.9",
|
|
47
47
|
"tsm": "^2.3.0",
|
|
48
|
-
"tsup": "^7.
|
|
49
|
-
"typescript": "^5.
|
|
50
|
-
"vite": "^4.4.
|
|
51
|
-
"vitest": "
|
|
48
|
+
"tsup": "^7.2.0",
|
|
49
|
+
"typescript": "^5.2.2",
|
|
50
|
+
"vite": "^4.4.11",
|
|
51
|
+
"vitest": "1.0.0-beta.1"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"evtmitter": "^0.3.3",
|
|
55
|
-
"immer": "^10.0.
|
|
55
|
+
"immer": "^10.0.3",
|
|
56
56
|
"klona": "^2.0.6",
|
|
57
|
-
"t-state": "^8.
|
|
57
|
+
"t-state": "^8.10.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"react": "^18.0.0",
|