@dxos/react-client 2.25.0 → 2.25.1-dev.0ff9b5c9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "2.25.0",
3
+ "version": "2.25.1-dev.0ff9b5c9",
4
4
  "description": "React client API",
5
5
  "keywords": [],
6
6
  "license": "AGPL-3.0",
@@ -8,22 +8,22 @@
8
8
  "main": "dist/src/index.js",
9
9
  "types": "dist/src/index.d.ts",
10
10
  "dependencies": {
11
- "@dxos/async": "2.25.0",
12
- "@dxos/bot-factory-client": "2.25.0",
13
- "@dxos/client": "2.25.0",
14
- "@dxos/config": "2.25.0",
15
- "@dxos/credentials": "2.25.0",
16
- "@dxos/crypto": "2.25.0",
17
- "@dxos/debug": "2.25.0",
18
- "@dxos/echo-db": "2.25.0",
19
- "@dxos/util": "2.25.0",
11
+ "@dxos/async": "2.25.1-dev.0ff9b5c9",
12
+ "@dxos/bot-factory-client": "2.25.1-dev.0ff9b5c9",
13
+ "@dxos/client": "2.25.1-dev.0ff9b5c9",
14
+ "@dxos/config": "2.25.1-dev.0ff9b5c9",
15
+ "@dxos/credentials": "2.25.1-dev.0ff9b5c9",
16
+ "@dxos/crypto": "2.25.1-dev.0ff9b5c9",
17
+ "@dxos/debug": "2.25.1-dev.0ff9b5c9",
18
+ "@dxos/echo-db": "2.25.1-dev.0ff9b5c9",
19
+ "@dxos/util": "2.25.1-dev.0ff9b5c9",
20
20
  "assert": "^2.0.0",
21
21
  "debug": "^4.3.3",
22
22
  "react-display-name": "^0.2.5",
23
23
  "use-subscription": "^1.4.1"
24
24
  },
25
25
  "devDependencies": {
26
- "@dxos/esbuild-plugins": "2.25.0",
26
+ "@dxos/esbuild-plugins": "2.25.1-dev.0ff9b5c9",
27
27
  "@dxos/esbuild-server": "~1.7.4",
28
28
  "@dxos/toolchain-node-library": "2.25.0",
29
29
  "@mui/material": "^5.0.1",
@@ -2,12 +2,17 @@
2
2
  // Copyright 2020 DXOS.org
3
3
  //
4
4
 
5
+ import { Party } from '@dxos/client';
6
+
7
+ import { useSelection } from '.';
8
+
5
9
  /**
6
10
  * A Selector used for finding items based on a search pattern.
7
11
  * @param search Searched value.
8
12
  */
9
13
  // TODO(burdon): Create index.
10
- export const searchSelector = (search: any) => (selection: any) => {
14
+ // TODO(dmaretskyi): Why is this in react-client?
15
+ export const useSearchSelection = (party: Party, search: any) => {
11
16
  const match = (pattern: any, text: any) => {
12
17
  if (!pattern) {
13
18
  return true;
@@ -21,15 +26,14 @@ export const searchSelector = (search: any) => (selection: any) => {
21
26
  return text.toLowerCase().indexOf(pattern) !== -1;
22
27
  };
23
28
 
24
- // TODO(burdon): Use selection to filter.
25
- return selection.items.filter((item: any) => {
29
+ return useSelection(party.select().filter(item => {
26
30
  // TODO(burdon): Filter types.
27
- if (item.type.indexOf('example') === -1) {
31
+ if (item.type?.indexOf('example') === -1) {
28
32
  return false;
29
33
  }
30
34
 
31
35
  // TODO(burdon): Generalize.
32
36
  const text = item.model.getProperty('name');
33
37
  return match(search, text);
34
- });
38
+ }), [search]);
35
39
  };
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { useEffect, useState } from 'react';
6
6
 
7
- import { SelectionResult } from '@dxos/client';
7
+ import { Entity, Selection } from '@dxos/client';
8
8
  import { Falsy } from '@dxos/util';
9
9
 
10
10
  /**
@@ -15,27 +15,32 @@ import { Falsy } from '@dxos/util';
15
15
  * apart from changes in ECHO database itself, must be passed to deps array
16
16
  * for updates to work correctly.
17
17
  *
18
- * @param selectionResult Selection from which to query data. Can be falsy - in that case the hook will return undefined.
18
+ * @param selection Selection from which to query data. Can be falsy - in that case the hook will return undefined.
19
19
  * @param deps Array of values that trigger the selector when changed.
20
20
  */
21
- export function useSelection<T> (
22
- selectionResult: SelectionResult<T> | Falsy,
21
+ export function useSelection<T extends Entity<any>> (
22
+ selection: Selection<T> | Falsy,
23
23
  deps: readonly any[] = []
24
- ): T | undefined {
25
- const [data, setData] = useState(() => selectionResult ? selectionResult.getValue() : undefined);
24
+ ): T[] | undefined {
25
+ const [result, setResult] = useState(() => selection ? selection.query() : undefined);
26
+ const [data, setData] = useState(() => result ? result.result : undefined);
26
27
 
27
- // Update data when deps change.
28
+ // Update selection when the query or customs deps change.
28
29
  useEffect(() => {
29
- if (selectionResult) {
30
- const unsub = selectionResult.update.on(() => {
31
- setData(selectionResult.getValue());
30
+ const newResult = selection ? selection.query() : undefined;
31
+ const newData = newResult ? newResult.result : undefined;
32
+ setResult(newResult);
33
+ setData(newData);
34
+ }, [!!selection, !!selection && selection.root, ...deps]);
35
+
36
+ // Update data when database updates.
37
+ useEffect(() => {
38
+ if (result) {
39
+ return result.update.on(newData => {
40
+ setData(newData);
32
41
  });
33
- setData(selectionResult.getValue());
34
- return unsub;
35
- } else {
36
- setData(undefined);
37
42
  }
38
- }, deps);
43
+ }, [result]);
39
44
 
40
45
  return data;
41
46
  }