@dxos/echo-react 0.8.4-main.ef1bc66f44 → 0.8.4-main.fcfe5033a5
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 +5 -5
- package/dist/lib/neutral/index.mjs.map +3 -3
- package/dist/lib/neutral/meta.json +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 +1 -1
- package/dist/types/src/useSchema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/useObject.test.tsx +8 -8
- package/src/useObject.ts +5 -5
- package/src/useQuery.ts +2 -0
- package/src/useSchema.ts +1 -1
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.fcfe5033a5",
|
|
4
4
|
"description": "React integration for ECHO.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@effect-atom/atom": "^0.5.1",
|
|
32
32
|
"@effect-atom/atom-react": "^0.5.0",
|
|
33
|
-
"@dxos/echo
|
|
34
|
-
"@dxos/echo": "0.8.4-main.
|
|
33
|
+
"@dxos/echo": "0.8.4-main.fcfe5033a5",
|
|
34
|
+
"@dxos/echo-atom": "0.8.4-main.fcfe5033a5"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@testing-library/react": "^16.3.0",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"@types/react-dom": "~19.2.3",
|
|
40
40
|
"react": "~19.2.3",
|
|
41
41
|
"react-dom": "~19.2.3",
|
|
42
|
-
"@dxos/echo-db": "0.8.4-main.
|
|
42
|
+
"@dxos/echo-db": "0.8.4-main.fcfe5033a5"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"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
|
|
|
@@ -63,8 +63,8 @@ describe('useObject', () => {
|
|
|
63
63
|
expect(result.current[0]).toBe('Test');
|
|
64
64
|
|
|
65
65
|
// Update the property via Obj.change
|
|
66
|
-
Obj.change(obj, (
|
|
67
|
-
|
|
66
|
+
Obj.change(obj, (obj) => {
|
|
67
|
+
obj.name = 'Updated';
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
// Wait for reactivity to update
|
|
@@ -85,8 +85,8 @@ describe('useObject', () => {
|
|
|
85
85
|
expect(result.current[0].name).toBe('Test');
|
|
86
86
|
|
|
87
87
|
// Update a property via Obj.change
|
|
88
|
-
Obj.change(obj, (
|
|
89
|
-
|
|
88
|
+
Obj.change(obj, (obj) => {
|
|
89
|
+
obj.name = 'Updated';
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
// Wait for reactivity to update
|
|
@@ -107,8 +107,8 @@ describe('useObject', () => {
|
|
|
107
107
|
expect(result.current[0]).toBe('Test');
|
|
108
108
|
|
|
109
109
|
// Update a different property via Obj.change
|
|
110
|
-
Obj.change(obj, (
|
|
111
|
-
|
|
110
|
+
Obj.change(obj, (obj) => {
|
|
111
|
+
obj.email = 'newemail@example.com';
|
|
112
112
|
});
|
|
113
113
|
|
|
114
114
|
// Wait a bit to ensure no update happens
|
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.change(obj, (
|
|
126
|
+
Obj.change(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
|
},
|
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,
|
package/src/useSchema.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { type Database, type Type } from '@dxos/echo';
|
|
|
9
9
|
/**
|
|
10
10
|
* Subscribe to and retrieve schema changes from a space's schema registry.
|
|
11
11
|
*/
|
|
12
|
-
export const useSchema = <T extends Type.
|
|
12
|
+
export const useSchema = <T extends Type.AnyEntity = Type.AnyEntity>(
|
|
13
13
|
db?: Database.Database,
|
|
14
14
|
typename?: string,
|
|
15
15
|
): T | undefined => {
|