@arcote.tech/arc-react 0.1.7 → 0.1.9
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/index.js +21 -6
- package/dist/reactModel.d.ts +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -349,6 +349,8 @@ var reactModel = (arcContext, options) => {
|
|
|
349
349
|
const [result, setResult] = useState3(null);
|
|
350
350
|
const [revalidationTrigger, setRevalidationTrigger] = useState3(0);
|
|
351
351
|
const unsubscribeRef = useRef(null);
|
|
352
|
+
const queryPromiseRef = useRef(null);
|
|
353
|
+
const resolvePromiseRef = useRef(null);
|
|
352
354
|
useEffect2(() => {
|
|
353
355
|
if (cacheKey) {
|
|
354
356
|
if (!model.__cacheRegistry) {
|
|
@@ -357,8 +359,13 @@ var reactModel = (arcContext, options) => {
|
|
|
357
359
|
if (!model.__cacheRegistry.has(cacheKey)) {
|
|
358
360
|
model.__cacheRegistry.set(cacheKey, new Set);
|
|
359
361
|
}
|
|
360
|
-
const revalidateFn = () => {
|
|
362
|
+
const revalidateFn = async () => {
|
|
363
|
+
const promise = new Promise((resolve) => {
|
|
364
|
+
resolvePromiseRef.current = resolve;
|
|
365
|
+
});
|
|
366
|
+
queryPromiseRef.current = promise;
|
|
361
367
|
setRevalidationTrigger((prev) => prev + 1);
|
|
368
|
+
return promise;
|
|
362
369
|
};
|
|
363
370
|
model.__cacheRegistry.get(cacheKey).add(revalidateFn);
|
|
364
371
|
return () => {
|
|
@@ -380,6 +387,10 @@ var reactModel = (arcContext, options) => {
|
|
|
380
387
|
const { unsubscribe, result: result2 } = model.subscribe(queryBuilderFn, (newResult) => {
|
|
381
388
|
setResult(newResult);
|
|
382
389
|
setLoading(false);
|
|
390
|
+
if (resolvePromiseRef.current) {
|
|
391
|
+
resolvePromiseRef.current();
|
|
392
|
+
resolvePromiseRef.current = null;
|
|
393
|
+
}
|
|
383
394
|
}, defaultAuthContext);
|
|
384
395
|
unsubscribeRef.current = unsubscribe;
|
|
385
396
|
return () => {
|
|
@@ -396,13 +407,17 @@ var reactModel = (arcContext, options) => {
|
|
|
396
407
|
if (!model) {
|
|
397
408
|
throw new Error("useRevalidate must be used within a ModelProvider");
|
|
398
409
|
}
|
|
399
|
-
return useCallback4((cacheKey) => {
|
|
410
|
+
return useCallback4(async (cacheKey) => {
|
|
400
411
|
const registry = model.__cacheRegistry;
|
|
401
412
|
if (registry && registry.has(cacheKey)) {
|
|
402
413
|
const revalidators = registry.get(cacheKey);
|
|
403
|
-
revalidators
|
|
404
|
-
|
|
405
|
-
|
|
414
|
+
if (revalidators) {
|
|
415
|
+
const promises = [];
|
|
416
|
+
revalidators.forEach((revalidateFn) => {
|
|
417
|
+
promises.push(revalidateFn());
|
|
418
|
+
});
|
|
419
|
+
await Promise.all(promises);
|
|
420
|
+
}
|
|
406
421
|
}
|
|
407
422
|
}, [model]);
|
|
408
423
|
},
|
|
@@ -452,4 +467,4 @@ export {
|
|
|
452
467
|
Form
|
|
453
468
|
};
|
|
454
469
|
|
|
455
|
-
//# debugId=
|
|
470
|
+
//# debugId=64B909B4D47850D764756E2164756E21
|
package/dist/reactModel.d.ts
CHANGED
|
@@ -17,5 +17,5 @@ export declare const reactModel: <C extends ArcContextAny>(arcContext: C, option
|
|
|
17
17
|
catchErrorCallback: (error: any) => void;
|
|
18
18
|
}) => import("react/jsx-dev-runtime").JSX.Element | null, ({ children }: {
|
|
19
19
|
children: React.ReactNode;
|
|
20
|
-
}) => import("react/jsx-dev-runtime").JSX.Element, <Q extends IArcQueryBuilder>(queryBuilderFn: UnaryFunction<ReturnType<C["queryBuilder"]>, Q>, dependencies?: any[], cacheKey?: string) => [objectUtil.simplify<ReturnType<Q["toQuery"]>["lastResult"]>, false] | [undefined, true], () => (cacheKey: string) => void
|
|
20
|
+
}) => import("react/jsx-dev-runtime").JSX.Element, <Q extends IArcQueryBuilder>(queryBuilderFn: UnaryFunction<ReturnType<C["queryBuilder"]>, Q>, dependencies?: any[], cacheKey?: string) => [objectUtil.simplify<ReturnType<Q["toQuery"]>["lastResult"]>, false] | [undefined, true], () => (cacheKey: string) => Promise<void>, () => ArcContextElementMethodReturnType<C["elements"], "commandClient">, <QueryBuilderFn extends QueryFactoryFunction<C>>(queryBuilderFn: QueryBuilderFn, model?: ModelBase<C> | null) => Promise<QueryBuilderFunctionResult<QueryBuilderFn>>, () => Model<C> | null, (token: string) => ModelBase<C>];
|
|
21
21
|
//# sourceMappingURL=reactModel.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcote.tech/arc-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.9",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Przemysław Krasiński [arcote.tech]",
|
|
7
7
|
"description": "React client for the Arc framework, providing utilities for querying data and executing commands, enhancing the development of reactive and efficient user interfaces.",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"dev": "nodemon --ignore dist -e ts,tsx --exec 'bun run build'"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@arcote.tech/arc": "latest",
|
|
27
26
|
"react": "^18.3.1",
|
|
28
27
|
"react-dom": "^18.3.1"
|
|
29
28
|
},
|
|
@@ -37,6 +36,7 @@
|
|
|
37
36
|
"typescript": "^5.2.2"
|
|
38
37
|
},
|
|
39
38
|
"peerDependencies": {
|
|
39
|
+
"@arcote.tech/arc": "latest",
|
|
40
40
|
"typescript": "^5.0.0"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|