@dxos/echo-react 0.8.4-main.c85a9c8dae → 0.8.4-main.e00bdcdb52
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/lib/neutral/index.mjs +10 -9
- package/dist/lib/neutral/index.mjs.map +3 -3
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/useObject.d.ts.map +1 -1
- package/dist/types/src/useQuery.d.ts +2 -0
- package/dist/types/src/useQuery.d.ts.map +1 -1
- package/dist/types/src/useSchema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -7
- package/src/useObject.test.tsx +11 -23
- package/src/useObject.ts +7 -6
- package/src/useQuery.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-react",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.e00bdcdb52",
|
|
4
4
|
"description": "React integration for ECHO.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -20,9 +20,6 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"types": "dist/types/src/index.d.ts",
|
|
23
|
-
"typesVersions": {
|
|
24
|
-
"*": {}
|
|
25
|
-
},
|
|
26
23
|
"files": [
|
|
27
24
|
"dist",
|
|
28
25
|
"src"
|
|
@@ -30,8 +27,8 @@
|
|
|
30
27
|
"dependencies": {
|
|
31
28
|
"@effect-atom/atom": "^0.5.1",
|
|
32
29
|
"@effect-atom/atom-react": "^0.5.0",
|
|
33
|
-
"@dxos/echo": "0.8.4-main.
|
|
34
|
-
"@dxos/echo-atom": "0.8.4-main.
|
|
30
|
+
"@dxos/echo": "0.8.4-main.e00bdcdb52",
|
|
31
|
+
"@dxos/echo-atom": "0.8.4-main.e00bdcdb52"
|
|
35
32
|
},
|
|
36
33
|
"devDependencies": {
|
|
37
34
|
"@testing-library/react": "^16.3.0",
|
|
@@ -39,7 +36,7 @@
|
|
|
39
36
|
"@types/react-dom": "~19.2.3",
|
|
40
37
|
"react": "~19.2.3",
|
|
41
38
|
"react-dom": "~19.2.3",
|
|
42
|
-
"@dxos/echo-db": "0.8.4-main.
|
|
39
|
+
"@dxos/echo-db": "0.8.4-main.e00bdcdb52"
|
|
43
40
|
},
|
|
44
41
|
"peerDependencies": {
|
|
45
42
|
"react": "~19.2.3"
|
package/src/useObject.test.tsx
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import * as Registry from '@effect-atom/atom/Registry';
|
|
6
5
|
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Registry from '@effect-atom/atom/Registry';
|
|
7
7
|
import { renderHook, waitFor } from '@testing-library/react';
|
|
8
8
|
import React, { type PropsWithChildren } from 'react';
|
|
9
9
|
import { describe, expect, test } from 'vitest';
|
|
10
10
|
|
|
11
11
|
import { Obj, Ref } from '@dxos/echo';
|
|
12
|
-
import { TestSchema } from '@dxos/echo/testing';
|
|
13
12
|
import { createObject } from '@dxos/echo-db';
|
|
13
|
+
import { TestSchema } from '@dxos/echo/testing';
|
|
14
14
|
|
|
15
15
|
import { useObject } from './useObject';
|
|
16
16
|
|
|
@@ -46,7 +46,6 @@ describe('useObject', () => {
|
|
|
46
46
|
const wrapper = createWrapper(registry);
|
|
47
47
|
|
|
48
48
|
const { result } = renderHook(() => useObject(obj, 'name'), { wrapper });
|
|
49
|
-
|
|
50
49
|
const [value] = result.current;
|
|
51
50
|
expect(value).toBe('Test');
|
|
52
51
|
});
|
|
@@ -59,12 +58,11 @@ describe('useObject', () => {
|
|
|
59
58
|
const wrapper = createWrapper(registry);
|
|
60
59
|
|
|
61
60
|
const { result } = renderHook(() => useObject(obj, 'name'), { wrapper });
|
|
62
|
-
|
|
63
61
|
expect(result.current[0]).toBe('Test');
|
|
64
62
|
|
|
65
|
-
// Update the property via Obj.
|
|
66
|
-
Obj.
|
|
67
|
-
|
|
63
|
+
// Update the property via Obj.update
|
|
64
|
+
Obj.update(obj, (obj) => {
|
|
65
|
+
obj.name = 'Updated';
|
|
68
66
|
});
|
|
69
67
|
|
|
70
68
|
// Wait for reactivity to update
|
|
@@ -81,12 +79,11 @@ describe('useObject', () => {
|
|
|
81
79
|
const wrapper = createWrapper(registry);
|
|
82
80
|
|
|
83
81
|
const { result } = renderHook(() => useObject(obj), { wrapper });
|
|
84
|
-
|
|
85
82
|
expect(result.current[0].name).toBe('Test');
|
|
86
83
|
|
|
87
|
-
// Update a property via Obj.
|
|
88
|
-
Obj.
|
|
89
|
-
|
|
84
|
+
// Update a property via Obj.update
|
|
85
|
+
Obj.update(obj, (obj) => {
|
|
86
|
+
obj.name = 'Updated';
|
|
90
87
|
});
|
|
91
88
|
|
|
92
89
|
// Wait for reactivity to update
|
|
@@ -103,12 +100,11 @@ describe('useObject', () => {
|
|
|
103
100
|
const wrapper = createWrapper(registry);
|
|
104
101
|
|
|
105
102
|
const { result } = renderHook(() => useObject(obj, 'name'), { wrapper });
|
|
106
|
-
|
|
107
103
|
expect(result.current[0]).toBe('Test');
|
|
108
104
|
|
|
109
|
-
// Update a different property via Obj.
|
|
110
|
-
Obj.
|
|
111
|
-
|
|
105
|
+
// Update a different property via Obj.update
|
|
106
|
+
Obj.update(obj, (obj) => {
|
|
107
|
+
obj.email = 'newemail@example.com';
|
|
112
108
|
});
|
|
113
109
|
|
|
114
110
|
// Wait a bit to ensure no update happens
|
|
@@ -142,7 +138,6 @@ describe('useObject', () => {
|
|
|
142
138
|
const wrapper = createWrapper(registry);
|
|
143
139
|
|
|
144
140
|
const { result } = renderHook(() => useObject(obj), { wrapper });
|
|
145
|
-
|
|
146
141
|
const [value, updateCallback] = result.current;
|
|
147
142
|
expect(value.name).toBe('Test');
|
|
148
143
|
|
|
@@ -165,7 +160,6 @@ describe('useObject', () => {
|
|
|
165
160
|
const wrapper = createWrapper(registry);
|
|
166
161
|
|
|
167
162
|
const { result } = renderHook(() => useObject(obj, 'name'), { wrapper });
|
|
168
|
-
|
|
169
163
|
const [value, updateCallback] = result.current;
|
|
170
164
|
expect(value).toBe('Test');
|
|
171
165
|
|
|
@@ -186,7 +180,6 @@ describe('useObject', () => {
|
|
|
186
180
|
const wrapper = createWrapper(registry);
|
|
187
181
|
|
|
188
182
|
const { result } = renderHook(() => useObject(obj, 'name'), { wrapper });
|
|
189
|
-
|
|
190
183
|
const [value, updateCallback] = result.current;
|
|
191
184
|
expect(value).toBe('Test');
|
|
192
185
|
|
|
@@ -207,7 +200,6 @@ describe('useObject', () => {
|
|
|
207
200
|
const wrapper = createWrapper(registry);
|
|
208
201
|
|
|
209
202
|
const { result, rerender } = renderHook(() => useObject(obj, 'name'), { wrapper });
|
|
210
|
-
|
|
211
203
|
const [, firstUpdateCallback] = result.current;
|
|
212
204
|
|
|
213
205
|
rerender();
|
|
@@ -233,7 +225,6 @@ describe('useObject', () => {
|
|
|
233
225
|
const wrapper = createWrapper(registry);
|
|
234
226
|
|
|
235
227
|
const { result } = renderHook(() => useObject(undefined as TestSchema.Person | undefined, 'name'), { wrapper });
|
|
236
|
-
|
|
237
228
|
const [value] = result.current;
|
|
238
229
|
expect(value).toBeUndefined();
|
|
239
230
|
});
|
|
@@ -243,7 +234,6 @@ describe('useObject', () => {
|
|
|
243
234
|
const wrapper = createWrapper(registry);
|
|
244
235
|
|
|
245
236
|
const { result } = renderHook(() => useObject(undefined as TestSchema.Person | undefined), { wrapper });
|
|
246
|
-
|
|
247
237
|
const [, updateCallback] = result.current;
|
|
248
238
|
|
|
249
239
|
// Should not throw when calling update on undefined object.
|
|
@@ -262,7 +252,6 @@ describe('useObject', () => {
|
|
|
262
252
|
const wrapper = createWrapper(registry);
|
|
263
253
|
|
|
264
254
|
const { result, rerender } = renderHook(() => useObject(obj), { wrapper });
|
|
265
|
-
|
|
266
255
|
const [firstSnapshot] = result.current;
|
|
267
256
|
expect(firstSnapshot).toBeDefined();
|
|
268
257
|
|
|
@@ -286,7 +275,6 @@ describe('useObject', () => {
|
|
|
286
275
|
const wrapper = createWrapper(registry);
|
|
287
276
|
|
|
288
277
|
const { result, rerender } = renderHook(() => useObject(person.employer!), { wrapper });
|
|
289
|
-
|
|
290
278
|
const [firstSnapshot] = result.current;
|
|
291
279
|
expect(firstSnapshot).toBeDefined();
|
|
292
280
|
|
package/src/useObject.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import * as Atom from '@effect-atom/atom/Atom';
|
|
6
5
|
import { useAtomValue } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Atom from '@effect-atom/atom/Atom';
|
|
7
7
|
import { useCallback, useMemo } from 'react';
|
|
8
8
|
|
|
9
9
|
import { Obj, Ref } from '@dxos/echo';
|
|
@@ -123,20 +123,20 @@ export const useObject: {
|
|
|
123
123
|
if (obj === undefined) {
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
|
-
Obj.
|
|
126
|
+
Obj.update(obj, (obj: any) => {
|
|
127
127
|
if (typeof updateOrValue === 'function') {
|
|
128
|
-
const returnValue = updateOrValue(property !== undefined ?
|
|
128
|
+
const returnValue = updateOrValue(property !== undefined ? obj[property] : obj);
|
|
129
129
|
if (returnValue !== undefined) {
|
|
130
130
|
if (property === undefined) {
|
|
131
131
|
throw new Error('Cannot re-assign the entire object');
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
obj[property] = returnValue;
|
|
134
134
|
}
|
|
135
135
|
} else {
|
|
136
136
|
if (property === undefined) {
|
|
137
137
|
throw new Error('Cannot re-assign the entire object');
|
|
138
138
|
}
|
|
139
|
-
|
|
139
|
+
obj[property] = updateOrValue;
|
|
140
140
|
}
|
|
141
141
|
});
|
|
142
142
|
},
|
|
@@ -148,8 +148,9 @@ export const useObject: {
|
|
|
148
148
|
// TODO(dxos): Property subscriptions on refs may not update correctly until the ref loads.
|
|
149
149
|
useObjectValue(objOrRef);
|
|
150
150
|
return [useObjectProperty(liveObj, property as any), callback];
|
|
151
|
+
} else {
|
|
152
|
+
return [useObjectValue(objOrRef), callback];
|
|
151
153
|
}
|
|
152
|
-
return [useObjectValue(objOrRef), callback];
|
|
153
154
|
}) as any;
|
|
154
155
|
|
|
155
156
|
/**
|
package/src/useQuery.ts
CHANGED
|
@@ -24,6 +24,8 @@ interface UseQueryFn {
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Create subscription.
|
|
27
|
+
*
|
|
28
|
+
* @param queryOrFilter - The query or filter to apply. Query is memoized based on the AST. No need to call useMemo.
|
|
27
29
|
*/
|
|
28
30
|
export const useQuery: UseQueryFn = (
|
|
29
31
|
resource: Database.Queryable | undefined,
|