@arcote.tech/arc-react 0.0.24 → 0.0.26
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 +36 -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,27 @@ 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";
|
|
142
153
|
var reactModel = (arcContext, databaseName) => {
|
|
143
154
|
const LiveModelContext = createContext(null);
|
|
144
155
|
const LocalModelContext = createContext(null);
|
|
145
|
-
let
|
|
156
|
+
let modelMasterDataStorage = null;
|
|
146
157
|
return [
|
|
147
158
|
function LiveModelProvider(props) {
|
|
148
|
-
const
|
|
149
|
-
|
|
159
|
+
const dataStorage = useMemo(() => {
|
|
160
|
+
const dbAdapterPromise = idbAdapterFactory(databaseName, arcContext.version)(arcContext);
|
|
161
|
+
const dataStorage2 = new MasterDataStorage(dbAdapterPromise, rtcClientFactory, arcContext);
|
|
162
|
+
modelMasterDataStorage = dataStorage2;
|
|
163
|
+
return dataStorage2;
|
|
164
|
+
}, [arcContext, databaseName, arcContext.version]);
|
|
150
165
|
const [syncProgress, setSyncProgress] = useState([]);
|
|
151
166
|
const [syncDone, setSyncDone] = useState(false);
|
|
152
167
|
useEffect(() => {
|
|
@@ -159,7 +174,11 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
159
174
|
sync();
|
|
160
175
|
}, []);
|
|
161
176
|
return /* @__PURE__ */ jsx(LiveModelContext.Provider, {
|
|
162
|
-
value: {
|
|
177
|
+
value: {
|
|
178
|
+
dataStorage,
|
|
179
|
+
client: props.client,
|
|
180
|
+
catchErrorCallback: props.catchErrorCallback
|
|
181
|
+
},
|
|
163
182
|
children: syncDone ? props.children : /* @__PURE__ */ jsx(props.syncView, {
|
|
164
183
|
progress: syncProgress
|
|
165
184
|
}, undefined, false, undefined, this)
|
|
@@ -171,11 +190,14 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
171
190
|
throw new Error("LocalModelProvider must be used within a LiveModelProvider");
|
|
172
191
|
}
|
|
173
192
|
const [localContext] = useState(() => ({
|
|
174
|
-
dbAdapterPromise: parentContext.dbAdapterPromise,
|
|
175
193
|
dataStorage: parentContext.dataStorage.fork()
|
|
176
194
|
}));
|
|
177
195
|
return /* @__PURE__ */ jsx(LocalModelContext.Provider, {
|
|
178
|
-
value:
|
|
196
|
+
value: {
|
|
197
|
+
dataStorage: localContext.dataStorage,
|
|
198
|
+
client: parentContext.client,
|
|
199
|
+
catchErrorCallback: parentContext.catchErrorCallback
|
|
200
|
+
},
|
|
179
201
|
children
|
|
180
202
|
}, undefined, false, undefined, this);
|
|
181
203
|
},
|
|
@@ -188,6 +210,8 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
188
210
|
const [loading, setLoading] = useState(true);
|
|
189
211
|
const queryRef = useRef(null);
|
|
190
212
|
useEffect(() => {
|
|
213
|
+
if (queryRef.current)
|
|
214
|
+
queryRef.current.unsubscribe();
|
|
191
215
|
const queryBuilder = arcContext.queryBuilder();
|
|
192
216
|
const query = queryBuilderFn(queryBuilder).toQuery();
|
|
193
217
|
queryRef.current = query;
|
|
@@ -212,20 +236,20 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
212
236
|
if (!context) {
|
|
213
237
|
throw new Error("useQuery must be used within a ModelProvider");
|
|
214
238
|
}
|
|
215
|
-
return arcContext.commandsClient(context.dataStorage);
|
|
239
|
+
return arcContext.commandsClient(context.client, context.dataStorage, context.catchErrorCallback);
|
|
216
240
|
},
|
|
217
241
|
async function query(queryBuilderFn) {
|
|
218
242
|
const queryBuilder = arcContext.queryBuilder();
|
|
219
243
|
const query = queryBuilderFn(queryBuilder).toQuery();
|
|
220
|
-
if (!
|
|
244
|
+
if (!modelMasterDataStorage)
|
|
221
245
|
throw new Error("dataStorage not found");
|
|
222
|
-
const result = await query.run(
|
|
246
|
+
const result = await query.run(modelMasterDataStorage);
|
|
223
247
|
return result;
|
|
224
248
|
},
|
|
225
249
|
function useLocalDataStorage() {
|
|
226
250
|
const context = useContext(LocalModelContext);
|
|
227
251
|
if (!context) {
|
|
228
|
-
|
|
252
|
+
return null;
|
|
229
253
|
}
|
|
230
254
|
return context.dataStorage;
|
|
231
255
|
}
|
|
@@ -237,4 +261,4 @@ export {
|
|
|
237
261
|
formResolver
|
|
238
262
|
};
|
|
239
263
|
|
|
240
|
-
//# debugId=
|
|
264
|
+
//# debugId=BD5635FAE340904564756E2164756E21
|
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.26",
|
|
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.",
|