@dxos/echo-react 0.8.4-main.d05539e30a → 0.8.4-main.d9fc60f731
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 +17 -21
- 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 +10 -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/useType.ts +49 -0
- package/dist/types/src/useSchema.d.ts +0 -6
- package/dist/types/src/useSchema.d.ts.map +0 -1
- package/src/useSchema.ts +0 -42
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.d9fc60f731",
|
|
4
4
|
"description": "React integration for ECHO.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -25,10 +25,10 @@
|
|
|
25
25
|
"src"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@effect-atom/atom": "^0.5.
|
|
28
|
+
"@effect-atom/atom": "^0.5.3",
|
|
29
29
|
"@effect-atom/atom-react": "^0.5.0",
|
|
30
|
-
"@dxos/echo": "0.8.4-main.
|
|
31
|
-
"@dxos/echo-atom": "0.8.4-main.
|
|
30
|
+
"@dxos/echo": "0.8.4-main.d9fc60f731",
|
|
31
|
+
"@dxos/echo-atom": "0.8.4-main.d9fc60f731"
|
|
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.d9fc60f731"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"react": "~19.2.3"
|
package/src/index.ts
CHANGED
package/src/useType.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo, useSyncExternalStore } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Database, Filter, Query, Scope, Type } from '@dxos/echo';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Subscribe to and retrieve a type by typename from a space.
|
|
11
|
+
*
|
|
12
|
+
* Fans across the owning space db (persisted custom types) and the shared
|
|
13
|
+
* registry (static/runtime plugin types). Persisted types live only in the db,
|
|
14
|
+
* so a registry-only lookup misses them.
|
|
15
|
+
*/
|
|
16
|
+
export const useType = <T extends Type.AnyEntity = Type.AnyEntity>(
|
|
17
|
+
db?: Database.Database,
|
|
18
|
+
typename?: string,
|
|
19
|
+
): T | undefined => {
|
|
20
|
+
const { subscribe, getType } = useMemo(() => {
|
|
21
|
+
if (!typename || !db) {
|
|
22
|
+
return {
|
|
23
|
+
subscribe: () => () => {},
|
|
24
|
+
getType: (): T | undefined => undefined,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const queryResult = db.query(Query.select(Filter.type(Type.Type)).from(Scope.space(), Scope.registry()));
|
|
29
|
+
let subscribed = false;
|
|
30
|
+
const find = (): T | undefined =>
|
|
31
|
+
subscribed
|
|
32
|
+
? (queryResult.results.find((type) => Type.getTypename(type) === typename) as T | undefined)
|
|
33
|
+
: undefined;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
subscribe: (onStoreChange: () => void) => {
|
|
37
|
+
subscribed = true;
|
|
38
|
+
const unsubscribe = queryResult.subscribe(onStoreChange);
|
|
39
|
+
return () => {
|
|
40
|
+
unsubscribe();
|
|
41
|
+
subscribed = false;
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
getType: find,
|
|
45
|
+
};
|
|
46
|
+
}, [typename, db]);
|
|
47
|
+
|
|
48
|
+
return useSyncExternalStore(subscribe, getType);
|
|
49
|
+
};
|
|
@@ -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"}
|
package/src/useSchema.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { useMemo, useSyncExternalStore } from 'react';
|
|
6
|
-
|
|
7
|
-
import { type Database, type Type } from '@dxos/echo';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Subscribe to and retrieve schema changes from a space's schema registry.
|
|
11
|
-
*/
|
|
12
|
-
export const useSchema = <T extends Type.AnyEntity = Type.AnyEntity>(
|
|
13
|
-
db?: Database.Database,
|
|
14
|
-
typename?: string,
|
|
15
|
-
): T | undefined => {
|
|
16
|
-
const { subscribe, getSchema } = useMemo(() => {
|
|
17
|
-
if (!typename || !db) {
|
|
18
|
-
return {
|
|
19
|
-
subscribe: () => () => {},
|
|
20
|
-
getSchema: () => undefined,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const query = db.schemaRegistry.query({ typename, location: ['database', 'runtime'] });
|
|
25
|
-
const initialResult = query.runSync()[0];
|
|
26
|
-
let currentSchema = initialResult;
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
subscribe: (onStoreChange: () => void) => {
|
|
30
|
-
const unsubscribe = query.subscribe(() => {
|
|
31
|
-
currentSchema = query.results[0];
|
|
32
|
-
onStoreChange();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
return unsubscribe;
|
|
36
|
-
},
|
|
37
|
-
getSchema: () => currentSchema,
|
|
38
|
-
};
|
|
39
|
-
}, [typename, db]);
|
|
40
|
-
|
|
41
|
-
return useSyncExternalStore(subscribe, getSchema) as T;
|
|
42
|
-
};
|