@arcote.tech/arc-react 0.0.16 → 0.0.17
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 +15 -38
- package/dist/reactModel.d.ts +3 -3
- package/package.json +7 -5
package/dist/index.js
CHANGED
|
@@ -123,48 +123,29 @@ class IDBAdapter {
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
// reactModel.tsx
|
|
126
|
-
import {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
import {createContext, useContext, useEffect, useRef, useState} from "react";
|
|
130
|
-
import {
|
|
131
|
-
jsx
|
|
132
|
-
} from "react/jsx-runtime";
|
|
133
|
-
var reactModel = (context, dependecies) => {
|
|
126
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
127
|
+
import { jsx } from "react/jsx-runtime";
|
|
128
|
+
var reactModel = (model) => {
|
|
134
129
|
const LiveModelContext = createContext(null);
|
|
135
|
-
let localClient;
|
|
136
130
|
return [
|
|
137
131
|
function LiveModelProvider(props) {
|
|
138
|
-
const [client, setClient] = useState(null);
|
|
139
|
-
const clientRef = useRef(null);
|
|
140
|
-
useEffect(() => {
|
|
141
|
-
console.log("test");
|
|
142
|
-
if (clientRef.current)
|
|
143
|
-
return;
|
|
144
|
-
const client2 = model(context, dependecies);
|
|
145
|
-
clientRef.current = client2;
|
|
146
|
-
setClient(client2);
|
|
147
|
-
localClient = client2;
|
|
148
|
-
}, []);
|
|
149
|
-
if (!client)
|
|
150
|
-
return "Ekran \u0142adowania";
|
|
151
132
|
return /* @__PURE__ */ jsx(LiveModelContext.Provider, {
|
|
152
133
|
value: {
|
|
153
|
-
|
|
134
|
+
model
|
|
154
135
|
},
|
|
155
136
|
children: props.children
|
|
156
137
|
}, undefined, false, undefined, this);
|
|
157
138
|
},
|
|
158
139
|
function useQuery(queryBuilder, dependencies = []) {
|
|
159
|
-
const
|
|
160
|
-
if (!
|
|
140
|
+
const context = useContext(LiveModelContext);
|
|
141
|
+
if (!context)
|
|
161
142
|
throw new Error("useQuery must be used within a LiveModelProvider");
|
|
162
|
-
if (!
|
|
163
|
-
throw new Error("
|
|
143
|
+
if (!context.model)
|
|
144
|
+
throw new Error("model not found");
|
|
164
145
|
const [result, setResult] = useState(null);
|
|
165
146
|
const [loading, setLoading] = useState(true);
|
|
166
147
|
useEffect(() => {
|
|
167
|
-
const query =
|
|
148
|
+
const query = context.model.query(queryBuilder);
|
|
168
149
|
query.result$.subscribe((result2) => {
|
|
169
150
|
setResult(result2);
|
|
170
151
|
setLoading(false);
|
|
@@ -172,22 +153,18 @@ var reactModel = (context, dependecies) => {
|
|
|
172
153
|
return () => {
|
|
173
154
|
query.unsubscribe();
|
|
174
155
|
};
|
|
175
|
-
}, [
|
|
156
|
+
}, [context.model, ...dependencies]);
|
|
176
157
|
return [result, loading];
|
|
177
158
|
},
|
|
178
159
|
function useCommands() {
|
|
179
|
-
const
|
|
180
|
-
if (!
|
|
160
|
+
const context = useContext(LiveModelContext);
|
|
161
|
+
if (!context)
|
|
181
162
|
throw new Error("useCommands must be used within a LiveModelProvider");
|
|
182
|
-
return
|
|
163
|
+
return context.model.commands();
|
|
183
164
|
},
|
|
184
165
|
function query(queryBuilder) {
|
|
185
166
|
return new Promise((resolve, reject) => {
|
|
186
|
-
|
|
187
|
-
reject(new Error("Client is not initialized"));
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
const query = localClient.query(queryBuilder);
|
|
167
|
+
const query = model.query(queryBuilder);
|
|
191
168
|
const subscription = query.result$.subscribe({
|
|
192
169
|
next: (result) => {
|
|
193
170
|
subscription.unsubscribe();
|
|
@@ -207,4 +184,4 @@ export {
|
|
|
207
184
|
formResolver
|
|
208
185
|
};
|
|
209
186
|
|
|
210
|
-
//# debugId=
|
|
187
|
+
//# debugId=BF36AB53518853B964756E2164756E21
|
package/dist/reactModel.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare const reactModel: <
|
|
1
|
+
import { type ArcModelAny, type GetAnyCollectionQueryResult, type QueryFactoryFunction } from "@arcote.tech/arc";
|
|
2
|
+
export declare const reactModel: <Model extends ArcModelAny>(model: Model) => readonly [(props: {
|
|
3
3
|
children: React.ReactNode;
|
|
4
|
-
}) =>
|
|
4
|
+
}) => import("react/jsx-dev-runtime").JSX.Element, <QueryBuilderFn extends QueryFactoryFunction<Model["context"]>>(queryBuilder: QueryBuilderFn, dependencies?: any[]) => [GetAnyCollectionQueryResult<QueryBuilderFn>, false] | [null, true], () => ReturnType<Model["commands"]>, <QueryBuilderFn extends QueryFactoryFunction<Model["context"]>>(queryBuilder: QueryBuilderFn) => Promise<GetAnyCollectionQueryResult<QueryBuilderFn> | null>];
|
package/package.json
CHANGED
|
@@ -4,16 +4,17 @@
|
|
|
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.17",
|
|
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.",
|
|
11
11
|
"scripts": {
|
|
12
|
-
"build": "rm -
|
|
12
|
+
"build": "rm -rf dist && bun run ./build.ts && bun run build:declaration",
|
|
13
13
|
"build:declaration": "tsc --emitDeclarationOnly --project tsconfig.types.json",
|
|
14
14
|
"postbuild": "rimraf tsconfig.types.tsbuildinfo",
|
|
15
15
|
"type-check": "tsc",
|
|
16
|
-
"publish": "bun run build && npm publish --access=public"
|
|
16
|
+
"publish": "bun run build && npm publish --access=public",
|
|
17
|
+
"dev": "nodemon --ignore dist -e ts,tsx --exec 'bun run build'"
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"@arcote.tech/arc": "latest",
|
|
@@ -25,7 +26,8 @@
|
|
|
25
26
|
"@types/react": "^18.3.5",
|
|
26
27
|
"prettier": "^3.0.3",
|
|
27
28
|
"rimraf": "^5.0.5",
|
|
28
|
-
"typescript": "^5.2.2"
|
|
29
|
+
"typescript": "^5.2.2",
|
|
30
|
+
"nodemon": "^2.0.22"
|
|
29
31
|
},
|
|
30
32
|
"peerDependencies": {
|
|
31
33
|
"typescript": "^5.0.0"
|
|
@@ -34,4 +36,4 @@
|
|
|
34
36
|
"dist/**/*.js",
|
|
35
37
|
"dist/**/*.d.ts"
|
|
36
38
|
]
|
|
37
|
-
}
|
|
39
|
+
}
|