@arcote.tech/arc-react 0.0.24 → 0.0.25
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 +37 -12
- package/dist/reactModel.d.ts +3 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -54,6 +54,10 @@ class IDBReadTransaction {
|
|
|
54
54
|
}
|
|
55
55
|
async findById(store, id) {
|
|
56
56
|
return new Promise((resolve) => {
|
|
57
|
+
if (!id) {
|
|
58
|
+
resolve(undefined);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
57
61
|
const result = this.transaction.objectStore(store).get(id);
|
|
58
62
|
result.onsuccess = (e) => {
|
|
59
63
|
resolve(e.target.result);
|
|
@@ -137,16 +141,28 @@ import {
|
|
|
137
141
|
MasterDataStorage,
|
|
138
142
|
rtcClientFactory
|
|
139
143
|
} from "@arcote.tech/arc";
|
|
140
|
-
import {
|
|
144
|
+
import {
|
|
145
|
+
createContext,
|
|
146
|
+
useContext,
|
|
147
|
+
useEffect,
|
|
148
|
+
useMemo,
|
|
149
|
+
useRef,
|
|
150
|
+
useState
|
|
151
|
+
} from "react";
|
|
141
152
|
import { jsx } from "react/jsx-runtime";
|
|
153
|
+
"use client";
|
|
142
154
|
var reactModel = (arcContext, databaseName) => {
|
|
143
155
|
const LiveModelContext = createContext(null);
|
|
144
156
|
const LocalModelContext = createContext(null);
|
|
145
|
-
let
|
|
157
|
+
let modelMasterDataStorage = null;
|
|
146
158
|
return [
|
|
147
159
|
function LiveModelProvider(props) {
|
|
148
|
-
const
|
|
149
|
-
|
|
160
|
+
const dataStorage = useMemo(() => {
|
|
161
|
+
const dbAdapterPromise = idbAdapterFactory(databaseName, arcContext.version)(arcContext);
|
|
162
|
+
const dataStorage2 = new MasterDataStorage(dbAdapterPromise, rtcClientFactory, arcContext);
|
|
163
|
+
modelMasterDataStorage = dataStorage2;
|
|
164
|
+
return dataStorage2;
|
|
165
|
+
}, [arcContext, databaseName, arcContext.version]);
|
|
150
166
|
const [syncProgress, setSyncProgress] = useState([]);
|
|
151
167
|
const [syncDone, setSyncDone] = useState(false);
|
|
152
168
|
useEffect(() => {
|
|
@@ -159,7 +175,11 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
159
175
|
sync();
|
|
160
176
|
}, []);
|
|
161
177
|
return /* @__PURE__ */ jsx(LiveModelContext.Provider, {
|
|
162
|
-
value: {
|
|
178
|
+
value: {
|
|
179
|
+
dataStorage,
|
|
180
|
+
client: props.client,
|
|
181
|
+
catchErrorCallback: props.catchErrorCallback
|
|
182
|
+
},
|
|
163
183
|
children: syncDone ? props.children : /* @__PURE__ */ jsx(props.syncView, {
|
|
164
184
|
progress: syncProgress
|
|
165
185
|
}, undefined, false, undefined, this)
|
|
@@ -171,11 +191,14 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
171
191
|
throw new Error("LocalModelProvider must be used within a LiveModelProvider");
|
|
172
192
|
}
|
|
173
193
|
const [localContext] = useState(() => ({
|
|
174
|
-
dbAdapterPromise: parentContext.dbAdapterPromise,
|
|
175
194
|
dataStorage: parentContext.dataStorage.fork()
|
|
176
195
|
}));
|
|
177
196
|
return /* @__PURE__ */ jsx(LocalModelContext.Provider, {
|
|
178
|
-
value:
|
|
197
|
+
value: {
|
|
198
|
+
dataStorage: localContext.dataStorage,
|
|
199
|
+
client: parentContext.client,
|
|
200
|
+
catchErrorCallback: parentContext.catchErrorCallback
|
|
201
|
+
},
|
|
179
202
|
children
|
|
180
203
|
}, undefined, false, undefined, this);
|
|
181
204
|
},
|
|
@@ -188,6 +211,8 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
188
211
|
const [loading, setLoading] = useState(true);
|
|
189
212
|
const queryRef = useRef(null);
|
|
190
213
|
useEffect(() => {
|
|
214
|
+
if (queryRef.current)
|
|
215
|
+
queryRef.current.unsubscribe();
|
|
191
216
|
const queryBuilder = arcContext.queryBuilder();
|
|
192
217
|
const query = queryBuilderFn(queryBuilder).toQuery();
|
|
193
218
|
queryRef.current = query;
|
|
@@ -212,20 +237,20 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
212
237
|
if (!context) {
|
|
213
238
|
throw new Error("useQuery must be used within a ModelProvider");
|
|
214
239
|
}
|
|
215
|
-
return arcContext.commandsClient(context.dataStorage);
|
|
240
|
+
return arcContext.commandsClient(context.client, context.dataStorage, context.catchErrorCallback);
|
|
216
241
|
},
|
|
217
242
|
async function query(queryBuilderFn) {
|
|
218
243
|
const queryBuilder = arcContext.queryBuilder();
|
|
219
244
|
const query = queryBuilderFn(queryBuilder).toQuery();
|
|
220
|
-
if (!
|
|
245
|
+
if (!modelMasterDataStorage)
|
|
221
246
|
throw new Error("dataStorage not found");
|
|
222
|
-
const result = await query.run(
|
|
247
|
+
const result = await query.run(modelMasterDataStorage);
|
|
223
248
|
return result;
|
|
224
249
|
},
|
|
225
250
|
function useLocalDataStorage() {
|
|
226
251
|
const context = useContext(LocalModelContext);
|
|
227
252
|
if (!context) {
|
|
228
|
-
|
|
253
|
+
return null;
|
|
229
254
|
}
|
|
230
255
|
return context.dataStorage;
|
|
231
256
|
}
|
|
@@ -237,4 +262,4 @@ export {
|
|
|
237
262
|
formResolver
|
|
238
263
|
};
|
|
239
264
|
|
|
240
|
-
//# debugId=
|
|
265
|
+
//# debugId=1A90F216CD67D17164756E2164756E21
|
package/dist/reactModel.d.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { ForkedDataStorage, type ArcContextAny, type CommandsClient, type QueryBuilderFunctionResult, type QueryFactoryFunction } from "@arcote.tech/arc";
|
|
2
2
|
export declare const reactModel: <C extends ArcContextAny>(arcContext: C, databaseName: string) => readonly [(props: {
|
|
3
3
|
children: React.ReactNode;
|
|
4
|
+
client: string;
|
|
4
5
|
syncView: React.ComponentType<{
|
|
5
6
|
progress: {
|
|
6
7
|
store: string;
|
|
7
8
|
size: number;
|
|
8
9
|
}[];
|
|
9
10
|
}>;
|
|
11
|
+
catchErrorCallback: (error: any) => void;
|
|
10
12
|
}) => import("react/jsx-dev-runtime").JSX.Element, ({ children }: {
|
|
11
13
|
children: React.ReactNode;
|
|
12
|
-
}) => import("react/jsx-dev-runtime").JSX.Element, <QueryBuilderFn extends QueryFactoryFunction<C>>(queryBuilderFn: QueryBuilderFn, dependencies?: any[]) => [QueryBuilderFunctionResult<QueryBuilderFn>, boolean], () => CommandsClient<C["commands"]>, <QueryBuilderFn extends QueryFactoryFunction<C>>(queryBuilderFn: QueryBuilderFn) => Promise<QueryBuilderFunctionResult<QueryBuilderFn>>, () => ForkedDataStorage];
|
|
14
|
+
}) => import("react/jsx-dev-runtime").JSX.Element, <QueryBuilderFn extends QueryFactoryFunction<C>>(queryBuilderFn: QueryBuilderFn, dependencies?: any[]) => [QueryBuilderFunctionResult<QueryBuilderFn>, boolean], () => CommandsClient<C["commands"]>, <QueryBuilderFn extends QueryFactoryFunction<C>>(queryBuilderFn: QueryBuilderFn) => Promise<QueryBuilderFunctionResult<QueryBuilderFn>>, () => ForkedDataStorage | null];
|
|
13
15
|
//# sourceMappingURL=reactModel.d.ts.map
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.0.
|
|
7
|
+
"version": "0.0.25",
|
|
8
8
|
"private": false,
|
|
9
9
|
"author": "Przemysław Krasiński [arcote.tech]",
|
|
10
10
|
"description": "React client for the Arc framework, providing utilities for querying data and executing commands, enhancing the development of reactive and efficient user interfaces.",
|