@arcote.tech/arc-react 0.0.22 → 0.0.24
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 +17 -20
- package/dist/reactModel.d.ts +7 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -144,12 +144,25 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
144
144
|
const LocalModelContext = createContext(null);
|
|
145
145
|
let dataStorage = null;
|
|
146
146
|
return [
|
|
147
|
-
function LiveModelProvider(
|
|
147
|
+
function LiveModelProvider(props) {
|
|
148
148
|
const dbAdapterPromise = idbAdapterFactory(databaseName, arcContext.version)(arcContext);
|
|
149
149
|
dataStorage = new MasterDataStorage(dbAdapterPromise, rtcClientFactory, arcContext);
|
|
150
|
+
const [syncProgress, setSyncProgress] = useState([]);
|
|
151
|
+
const [syncDone, setSyncDone] = useState(false);
|
|
152
|
+
useEffect(() => {
|
|
153
|
+
const sync = async () => {
|
|
154
|
+
await dataStorage?.sync(({ store, size }) => {
|
|
155
|
+
setSyncProgress((prev) => [...prev, { store, size }]);
|
|
156
|
+
});
|
|
157
|
+
setSyncDone(true);
|
|
158
|
+
};
|
|
159
|
+
sync();
|
|
160
|
+
}, []);
|
|
150
161
|
return /* @__PURE__ */ jsx(LiveModelContext.Provider, {
|
|
151
162
|
value: { dataStorage, dbAdapterPromise },
|
|
152
|
-
children
|
|
163
|
+
children: syncDone ? props.children : /* @__PURE__ */ jsx(props.syncView, {
|
|
164
|
+
progress: syncProgress
|
|
165
|
+
}, undefined, false, undefined, this)
|
|
153
166
|
}, undefined, false, undefined, this);
|
|
154
167
|
},
|
|
155
168
|
function LocalModelProvider({ children }) {
|
|
@@ -180,7 +193,6 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
180
193
|
queryRef.current = query;
|
|
181
194
|
const runQuery = async () => {
|
|
182
195
|
const result2 = await query.run(context.dataStorage, (newResult) => {
|
|
183
|
-
console.log("newResult", newResult);
|
|
184
196
|
setResult(newResult);
|
|
185
197
|
setLoading(false);
|
|
186
198
|
});
|
|
@@ -200,22 +212,7 @@ var reactModel = (arcContext, databaseName) => {
|
|
|
200
212
|
if (!context) {
|
|
201
213
|
throw new Error("useQuery must be used within a ModelProvider");
|
|
202
214
|
}
|
|
203
|
-
|
|
204
|
-
return new Proxy({}, {
|
|
205
|
-
get: (_, name) => {
|
|
206
|
-
if (name in commands) {
|
|
207
|
-
return async (...args) => {
|
|
208
|
-
const dataStorage2 = context.dataStorage.fork();
|
|
209
|
-
const commandContext = arcContext.commandContext(dataStorage2);
|
|
210
|
-
const result = await commands[name](commandContext, ...args);
|
|
211
|
-
await dataStorage2.merge();
|
|
212
|
-
return result;
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
console.warn(`Command '${name}' not found in the context.`);
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
});
|
|
215
|
+
return arcContext.commandsClient(context.dataStorage);
|
|
219
216
|
},
|
|
220
217
|
async function query(queryBuilderFn) {
|
|
221
218
|
const queryBuilder = arcContext.queryBuilder();
|
|
@@ -240,4 +237,4 @@ export {
|
|
|
240
237
|
formResolver
|
|
241
238
|
};
|
|
242
239
|
|
|
243
|
-
//# debugId=
|
|
240
|
+
//# debugId=75A81147F2E4FEEE64756E2164756E21
|
package/dist/reactModel.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { ForkedDataStorage, type ArcContextAny, type CommandsClient, type QueryBuilderFunctionResult, type QueryFactoryFunction } from "@arcote.tech/arc";
|
|
2
|
-
export declare const reactModel: <C extends ArcContextAny>(arcContext: C, databaseName: string) => readonly [(
|
|
2
|
+
export declare const reactModel: <C extends ArcContextAny>(arcContext: C, databaseName: string) => readonly [(props: {
|
|
3
3
|
children: React.ReactNode;
|
|
4
|
+
syncView: React.ComponentType<{
|
|
5
|
+
progress: {
|
|
6
|
+
store: string;
|
|
7
|
+
size: number;
|
|
8
|
+
}[];
|
|
9
|
+
}>;
|
|
4
10
|
}) => import("react/jsx-dev-runtime").JSX.Element, ({ children }: {
|
|
5
11
|
children: React.ReactNode;
|
|
6
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];
|
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.24",
|
|
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.",
|