@dxos/react-client 0.4.10-main.6f3f81d → 0.4.10-main.6fbe602
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/browser/echo/index.mjs +15 -13
- package/dist/lib/browser/echo/index.mjs.map +3 -3
- package/dist/lib/browser/halo/index.mjs +10 -22
- package/dist/lib/browser/halo/index.mjs.map +3 -3
- package/dist/lib/browser/mesh/index.mjs +2 -6
- package/dist/lib/browser/mesh/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node/echo/index.cjs +16 -14
- package/dist/lib/node/echo/index.cjs.map +3 -3
- package/dist/lib/node/halo/index.cjs +11 -24
- package/dist/lib/node/halo/index.cjs.map +3 -3
- package/dist/lib/node/mesh/index.cjs +2 -6
- package/dist/lib/node/mesh/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/types/src/echo/useQuery.d.ts +2 -2
- package/dist/types/src/echo/useQuery.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaceInvitations.d.ts +2 -1
- package/dist/types/src/echo/useSpaceInvitations.d.ts.map +1 -1
- package/dist/types/src/halo/index.d.ts +1 -1
- package/dist/types/src/halo/index.d.ts.map +1 -1
- package/dist/types/src/halo/useContacts.d.ts.map +1 -1
- package/dist/types/src/halo/useDevices.d.ts.map +1 -1
- package/dist/types/src/halo/useHaloInvitations.d.ts +2 -1
- package/dist/types/src/halo/useHaloInvitations.d.ts.map +1 -1
- package/dist/types/src/mesh/useNetworkStatus.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/echo/useQuery.ts +22 -13
- package/src/echo/useSpaceInvitations.ts +6 -18
- package/src/halo/index.ts +1 -10
- package/src/halo/useContacts.ts +2 -11
- package/src/halo/useDevices.ts +2 -11
- package/src/halo/useHaloInvitations.ts +6 -13
- package/src/mesh/useNetworkStatus.ts +2 -11
- package/src/testing/ClientRepeater.tsx +2 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "0.4.10-main.
|
|
3
|
+
"version": "0.4.10-main.6fbe602",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -83,17 +83,17 @@
|
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@dxos/
|
|
87
|
-
"@dxos/
|
|
88
|
-
"@dxos/
|
|
89
|
-
"@dxos/codec-protobuf": "0.4.10-main.
|
|
90
|
-
"@dxos/debug": "0.4.10-main.
|
|
91
|
-
"@dxos/echo-signals": "0.4.10-main.
|
|
92
|
-
"@dxos/node-std": "0.4.10-main.
|
|
93
|
-
"@dxos/
|
|
94
|
-
"@dxos/react-async": "0.4.10-main.
|
|
95
|
-
"@dxos/
|
|
96
|
-
"@dxos/util": "0.4.10-main.
|
|
86
|
+
"@dxos/async": "0.4.10-main.6fbe602",
|
|
87
|
+
"@dxos/config": "0.4.10-main.6fbe602",
|
|
88
|
+
"@dxos/client": "0.4.10-main.6fbe602",
|
|
89
|
+
"@dxos/codec-protobuf": "0.4.10-main.6fbe602",
|
|
90
|
+
"@dxos/debug": "0.4.10-main.6fbe602",
|
|
91
|
+
"@dxos/echo-signals": "0.4.10-main.6fbe602",
|
|
92
|
+
"@dxos/node-std": "0.4.10-main.6fbe602",
|
|
93
|
+
"@dxos/invariant": "0.4.10-main.6fbe602",
|
|
94
|
+
"@dxos/react-async": "0.4.10-main.6fbe602",
|
|
95
|
+
"@dxos/log": "0.4.10-main.6fbe602",
|
|
96
|
+
"@dxos/util": "0.4.10-main.6fbe602"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@testing-library/dom": "^8.17.1",
|
|
@@ -104,10 +104,10 @@
|
|
|
104
104
|
"react": "^18.2.0",
|
|
105
105
|
"react-dom": "^18.2.0",
|
|
106
106
|
"yjs": "^13.6.10",
|
|
107
|
-
"@dxos/random": "0.4.10-main.
|
|
108
|
-
"@dxos/react-ui": "0.4.10-main.
|
|
109
|
-
"@dxos/react-ui-theme": "0.4.10-main.
|
|
110
|
-
"@dxos/storybook-utils": "0.4.10-main.
|
|
107
|
+
"@dxos/random": "0.4.10-main.6fbe602",
|
|
108
|
+
"@dxos/react-ui": "0.4.10-main.6fbe602",
|
|
109
|
+
"@dxos/react-ui-theme": "0.4.10-main.6fbe602",
|
|
110
|
+
"@dxos/storybook-utils": "0.4.10-main.6fbe602"
|
|
111
111
|
},
|
|
112
112
|
"peerDependencies": {
|
|
113
113
|
"react": "*",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
},
|
|
116
116
|
"optionalDependencies": {
|
|
117
117
|
"yjs": "^13.6.10",
|
|
118
|
-
"@dxos/random": "0.4.10-main.
|
|
118
|
+
"@dxos/random": "0.4.10-main.6fbe602"
|
|
119
119
|
},
|
|
120
120
|
"publishConfig": {
|
|
121
121
|
"access": "public"
|
package/src/echo/useQuery.ts
CHANGED
|
@@ -4,34 +4,39 @@
|
|
|
4
4
|
|
|
5
5
|
import { useMemo, useSyncExternalStore } from 'react';
|
|
6
6
|
|
|
7
|
-
import type { QueryOptions,
|
|
7
|
+
import type { QueryOptions, Query, FilterSource, Space, EchoReactiveObject } from '@dxos/client/echo';
|
|
8
8
|
|
|
9
9
|
type UseQuery = {
|
|
10
|
-
<T extends
|
|
10
|
+
<T extends EchoReactiveObject<any>>(
|
|
11
|
+
space?: Space,
|
|
12
|
+
filter?: FilterSource<T>,
|
|
13
|
+
options?: QueryOptions,
|
|
14
|
+
deps?: any[],
|
|
15
|
+
): T[];
|
|
11
16
|
};
|
|
12
17
|
|
|
13
18
|
/**
|
|
14
19
|
* Create subscription.
|
|
15
20
|
*/
|
|
16
21
|
// TODO(burdon): Support typed operator filters (e.g., Note.filter(note => ...)).
|
|
17
|
-
export const useQuery: UseQuery = <T extends
|
|
22
|
+
export const useQuery: UseQuery = <T extends EchoReactiveObject<any>>(
|
|
18
23
|
space?: Space,
|
|
19
24
|
filter?: FilterSource<T>,
|
|
20
25
|
options?: QueryOptions,
|
|
21
26
|
deps?: any[],
|
|
22
27
|
) => {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
const { subscribe, getObjects } = useMemo(() => {
|
|
29
|
+
const query = space?.db.query(filter, options) as Query<T> | undefined;
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
subscribe: (cb: () => void) => query?.subscribe(cb) ?? noop,
|
|
33
|
+
getObjects: () => query?.objects ?? EMPTY_ARRAY,
|
|
34
|
+
};
|
|
35
|
+
}, [space?.db, ...(typeof filter === 'function' ? [] : filterToDepsArray(filter)), ...(deps ?? [])]);
|
|
27
36
|
|
|
28
37
|
// https://beta.reactjs.org/reference/react/useSyncExternalStore
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
(cb) => query?.subscribe?.(cb) ?? cb,
|
|
32
|
-
() => query?.objects,
|
|
33
|
-
) ?? []
|
|
34
|
-
);
|
|
38
|
+
// NOTE: This hook will resubscribe whenever the callback passed to the first argument changes -- make sure it is stable.
|
|
39
|
+
return useSyncExternalStore<T[] | undefined>(subscribe, getObjects) ?? [];
|
|
35
40
|
};
|
|
36
41
|
|
|
37
42
|
// TODO(dmaretskyi): Serialize the filter here instead.
|
|
@@ -39,3 +44,7 @@ const filterToDepsArray = (filter?: FilterSource<any>) =>
|
|
|
39
44
|
Object.entries(filter ?? {})
|
|
40
45
|
.flat(10)
|
|
41
46
|
.map((x) => (typeof x === 'function' || typeof x === 'object' ? null : x));
|
|
47
|
+
|
|
48
|
+
const noop = () => {};
|
|
49
|
+
|
|
50
|
+
const EMPTY_ARRAY: never[] = [];
|
|
@@ -2,30 +2,18 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useMemo
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
6
|
|
|
7
|
+
import { MulticastObservable } from '@dxos/async';
|
|
7
8
|
import { type PublicKey } from '@dxos/client';
|
|
8
|
-
import {
|
|
9
|
+
import { useMulticastObservable } from '@dxos/react-async';
|
|
9
10
|
|
|
10
11
|
import { useSpace } from './useSpaces';
|
|
11
|
-
import { useInvitationStatus } from '../invitations';
|
|
12
|
+
import { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';
|
|
12
13
|
|
|
13
|
-
export const useSpaceInvitations = (spaceKey?: PublicKey) => {
|
|
14
|
+
export const useSpaceInvitations = (spaceKey?: PublicKey): CancellableInvitationObservable[] => {
|
|
14
15
|
const space = useSpace(spaceKey);
|
|
15
|
-
|
|
16
|
-
useSyncExternalStore(
|
|
17
|
-
(listener) => {
|
|
18
|
-
if (!(space instanceof SpaceProxy)) {
|
|
19
|
-
return () => {};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const subscription = space.invitations.subscribe(() => listener());
|
|
23
|
-
return () => subscription.unsubscribe();
|
|
24
|
-
},
|
|
25
|
-
() => space?.invitations.get(),
|
|
26
|
-
) ?? [];
|
|
27
|
-
|
|
28
|
-
return invitations;
|
|
16
|
+
return useMulticastObservable(space?.invitations ?? MulticastObservable.empty()) ?? [];
|
|
29
17
|
};
|
|
30
18
|
|
|
31
19
|
export const useSpaceInvitation = (spaceKey?: PublicKey, invitationId?: string) => {
|
package/src/halo/index.ts
CHANGED
|
@@ -3,16 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// NOTE: Export * fails here.
|
|
6
|
-
export {
|
|
7
|
-
type Contact,
|
|
8
|
-
Device,
|
|
9
|
-
DeviceKind,
|
|
10
|
-
DeviceType,
|
|
11
|
-
type Identity,
|
|
12
|
-
// generateSeedPhrase,
|
|
13
|
-
type Halo,
|
|
14
|
-
HaloProxy,
|
|
15
|
-
} from '@dxos/client/halo';
|
|
6
|
+
export { type Contact, type Identity, type Halo, Device, DeviceKind, DeviceType } from '@dxos/client/halo';
|
|
16
7
|
|
|
17
8
|
export * from './useContacts';
|
|
18
9
|
export * from './useDevices';
|
package/src/halo/useContacts.ts
CHANGED
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useSyncExternalStore } from 'react';
|
|
6
|
-
|
|
7
5
|
import type { Contact } from '@dxos/client/halo';
|
|
6
|
+
import { useMulticastObservable } from '@dxos/react-async';
|
|
8
7
|
|
|
9
8
|
import { useClient } from '../client';
|
|
10
9
|
|
|
@@ -15,13 +14,5 @@ import { useClient } from '../client';
|
|
|
15
14
|
*/
|
|
16
15
|
export const useContacts = (): Contact[] => {
|
|
17
16
|
const client = useClient();
|
|
18
|
-
|
|
19
|
-
(listener) => {
|
|
20
|
-
const subscription = client.halo.contacts.subscribe(listener);
|
|
21
|
-
return () => subscription.unsubscribe();
|
|
22
|
-
},
|
|
23
|
-
() => client.halo.contacts.get(),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
return contacts;
|
|
17
|
+
return useMulticastObservable(client.halo.contacts);
|
|
27
18
|
};
|
package/src/halo/useDevices.ts
CHANGED
|
@@ -2,21 +2,12 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useSyncExternalStore } from 'react';
|
|
6
|
-
|
|
7
5
|
import type { Device } from '@dxos/client/halo';
|
|
6
|
+
import { useMulticastObservable } from '@dxos/react-async';
|
|
8
7
|
|
|
9
8
|
import { useClient } from '../client';
|
|
10
9
|
|
|
11
10
|
export const useDevices = (): Device[] => {
|
|
12
11
|
const client = useClient();
|
|
13
|
-
|
|
14
|
-
(listener) => {
|
|
15
|
-
const subscription = client.halo.devices.subscribe(listener);
|
|
16
|
-
return () => subscription.unsubscribe();
|
|
17
|
-
},
|
|
18
|
-
() => client.halo.devices.get(),
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
return devices;
|
|
12
|
+
return useMulticastObservable(client.halo.devices);
|
|
22
13
|
};
|
|
@@ -2,23 +2,16 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useMemo
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useMulticastObservable } from '@dxos/react-async';
|
|
6
8
|
|
|
7
9
|
import { useClient } from '../client';
|
|
8
|
-
import { useInvitationStatus } from '../invitations';
|
|
10
|
+
import { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';
|
|
9
11
|
|
|
10
|
-
export const useHaloInvitations = () => {
|
|
12
|
+
export const useHaloInvitations = (): CancellableInvitationObservable[] => {
|
|
11
13
|
const client = useClient();
|
|
12
|
-
|
|
13
|
-
useSyncExternalStore(
|
|
14
|
-
(listener) => {
|
|
15
|
-
const subscription = client.halo.invitations.subscribe(() => listener());
|
|
16
|
-
return () => subscription.unsubscribe();
|
|
17
|
-
},
|
|
18
|
-
() => (client.halo.opened ? client.halo.invitations.get() : []),
|
|
19
|
-
) ?? [];
|
|
20
|
-
|
|
21
|
-
return invitations;
|
|
14
|
+
return useMulticastObservable(client.halo.invitations);
|
|
22
15
|
};
|
|
23
16
|
|
|
24
17
|
export const useHaloInvitation = (invitationId?: string) => {
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// Copyright 2020 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useSyncExternalStore } from 'react';
|
|
6
|
-
|
|
7
5
|
import { type NetworkStatus } from '@dxos/client/mesh';
|
|
6
|
+
import { useMulticastObservable } from '@dxos/react-async';
|
|
8
7
|
|
|
9
8
|
import { useClient } from '../client';
|
|
10
9
|
|
|
@@ -13,13 +12,5 @@ import { useClient } from '../client';
|
|
|
13
12
|
*/
|
|
14
13
|
export const useNetworkStatus = (): NetworkStatus => {
|
|
15
14
|
const client = useClient();
|
|
16
|
-
|
|
17
|
-
(listener) => {
|
|
18
|
-
const subscription = client.mesh.networkStatus.subscribe(listener);
|
|
19
|
-
return () => subscription.unsubscribe();
|
|
20
|
-
},
|
|
21
|
-
() => client.mesh.networkStatus.get(),
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
return networkStatus;
|
|
15
|
+
return useMulticastObservable(client.mesh.networkStatus);
|
|
25
16
|
};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React, { useState, type FC, useEffect } from 'react';
|
|
6
6
|
|
|
7
7
|
import { Client, type PublicKey } from '@dxos/client';
|
|
8
|
-
import { type
|
|
8
|
+
import { type Space } from '@dxos/client/echo';
|
|
9
9
|
import { TestBuilder, performInvitation } from '@dxos/client/testing';
|
|
10
10
|
import { registerSignalFactory } from '@dxos/echo-signals/react';
|
|
11
11
|
import { faker } from '@dxos/random';
|
|
@@ -72,9 +72,7 @@ export const ClientRepeater = <P extends RepeatedComponentProps>(props: ClientRe
|
|
|
72
72
|
const space = await clients[0].spaces.create({ name: faker.commerce.productName() });
|
|
73
73
|
setSpaceKey(space.key);
|
|
74
74
|
await onCreateSpace?.(space);
|
|
75
|
-
await Promise.all(
|
|
76
|
-
clients.slice(1).map((client) => performInvitation({ host: space as SpaceProxy, guest: client.spaces })),
|
|
77
|
-
);
|
|
75
|
+
await Promise.all(clients.slice(1).map((client) => performInvitation({ host: space, guest: client.spaces })));
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
setClients(clients);
|