@dxos/echo-react 0.8.4-main.e00bdcdb52 → 0.8.4-main.effb148878
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/LICENSE +102 -5
- package/dist/lib/neutral/index.mjs +9 -10
- package/dist/lib/neutral/index.mjs.map +4 -4
- package/dist/lib/neutral/meta.json +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/useType.d.ts +6 -0
- package/dist/types/src/useType.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/index.ts +1 -1
- package/src/useQuery.__test.tsx +1 -2
- package/src/{useSchema.ts → useType.ts} +8 -9
- package/dist/types/src/useSchema.d.ts +0 -6
- package/dist/types/src/useSchema.d.ts.map +0 -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.effb148878",
|
|
4
4
|
"description": "React integration for ECHO.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "https://github.com/dxos/dxos"
|
|
10
10
|
},
|
|
11
|
-
"license": "
|
|
11
|
+
"license": "FSL-1.1-Apache-2.0",
|
|
12
12
|
"author": "DXOS.org",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"type": "module",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@effect-atom/atom": "^0.5.1",
|
|
29
29
|
"@effect-atom/atom-react": "^0.5.0",
|
|
30
|
-
"@dxos/echo": "0.8.4-main.
|
|
31
|
-
"@dxos/echo
|
|
30
|
+
"@dxos/echo-atom": "0.8.4-main.effb148878",
|
|
31
|
+
"@dxos/echo": "0.8.4-main.effb148878"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@testing-library/react": "^16.3.0",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/react-dom": "~19.2.3",
|
|
37
37
|
"react": "~19.2.3",
|
|
38
38
|
"react-dom": "~19.2.3",
|
|
39
|
-
"@dxos/echo-db": "0.8.4-main.
|
|
39
|
+
"@dxos/echo-db": "0.8.4-main.effb148878"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "~19.2.3"
|
package/src/index.ts
CHANGED
package/src/useQuery.__test.tsx
CHANGED
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
import { renderHook } from '@testing-library/react';
|
|
9
9
|
import { describe, expect, test } from 'vitest';
|
|
10
10
|
|
|
11
|
-
import { Filter } from '@dxos/
|
|
12
|
-
import { Obj, Type } from '@dxos/echo';
|
|
11
|
+
import { Filter, Obj, Type } from '@dxos/echo';
|
|
13
12
|
import { TestSchema } from '@dxos/echo/testing';
|
|
14
13
|
|
|
15
14
|
import { createClient, createClientContextProvider } from '../testing/util';
|
|
@@ -7,36 +7,35 @@ import { useMemo, useSyncExternalStore } from 'react';
|
|
|
7
7
|
import { type Database, type Type } from '@dxos/echo';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Subscribe to and retrieve
|
|
10
|
+
* Subscribe to and retrieve type changes from a space's schema registry.
|
|
11
11
|
*/
|
|
12
|
-
export const
|
|
12
|
+
export const useType = <T extends Type.AnyEntity = Type.AnyEntity>(
|
|
13
13
|
db?: Database.Database,
|
|
14
14
|
typename?: string,
|
|
15
15
|
): T | undefined => {
|
|
16
|
-
const { subscribe,
|
|
16
|
+
const { subscribe, getType } = useMemo(() => {
|
|
17
17
|
if (!typename || !db) {
|
|
18
18
|
return {
|
|
19
19
|
subscribe: () => () => {},
|
|
20
|
-
|
|
20
|
+
getType: (): T | undefined => undefined,
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const query = db.schemaRegistry.query({ typename, location: ['database', 'runtime'] });
|
|
25
|
-
|
|
26
|
-
let currentSchema = initialResult;
|
|
25
|
+
let currentType = query.runSync()[0] as T | undefined;
|
|
27
26
|
|
|
28
27
|
return {
|
|
29
28
|
subscribe: (onStoreChange: () => void) => {
|
|
30
29
|
const unsubscribe = query.subscribe(() => {
|
|
31
|
-
|
|
30
|
+
currentType = query.results[0] as T | undefined;
|
|
32
31
|
onStoreChange();
|
|
33
32
|
});
|
|
34
33
|
|
|
35
34
|
return unsubscribe;
|
|
36
35
|
},
|
|
37
|
-
|
|
36
|
+
getType: (): T | undefined => currentType,
|
|
38
37
|
};
|
|
39
38
|
}, [typename, db]);
|
|
40
39
|
|
|
41
|
-
return useSyncExternalStore(subscribe,
|
|
40
|
+
return useSyncExternalStore(subscribe, getType);
|
|
42
41
|
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type Database, type Type } from '@dxos/echo';
|
|
2
|
-
/**
|
|
3
|
-
* Subscribe to and retrieve schema changes from a space's schema registry.
|
|
4
|
-
*/
|
|
5
|
-
export declare const useSchema: <T extends Type.AnyEntity = Type.AnyEntity>(db?: Database.Database, typename?: string) => T | undefined;
|
|
6
|
-
//# sourceMappingURL=useSchema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useSchema.d.ts","sourceRoot":"","sources":["../../../src/useSchema.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAEtD;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,SAAS,OAC5D,QAAQ,CAAC,QAAQ,aACX,MAAM,KAChB,CAAC,GAAG,SA2BN,CAAC"}
|