@dxos/app-graph 0.8.4-main.74a063c4e0 → 0.8.4-main.765dc60934
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/README.md +1 -1
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/{browser/chunk-AKBGYELG.mjs → neutral/chunk-WJJ5KEOH.mjs} +48 -174
- package/dist/lib/neutral/chunk-WJJ5KEOH.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/index.mjs +4 -2
- package/dist/lib/{browser → neutral}/index.mjs.map +2 -2
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/lib/neutral/scheduler.mjs +15 -0
- package/dist/lib/neutral/scheduler.mjs.map +7 -0
- package/dist/lib/{browser → neutral}/testing/index.mjs +2 -1
- package/dist/types/src/atoms.d.ts.map +1 -1
- package/dist/types/src/graph-builder.d.ts +1 -1
- package/dist/types/src/graph-builder.d.ts.map +1 -1
- package/dist/types/src/graph.d.ts.map +1 -1
- package/dist/types/src/node-matcher.d.ts +3 -3
- package/dist/types/src/node-matcher.d.ts.map +1 -1
- package/dist/types/src/node.d.ts +2 -2
- package/dist/types/src/node.d.ts.map +1 -1
- package/dist/types/src/scheduler.browser.d.ts +2 -0
- package/dist/types/src/scheduler.browser.d.ts.map +1 -0
- package/dist/types/src/scheduler.d.ts +8 -0
- package/dist/types/src/scheduler.d.ts.map +1 -0
- package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -1
- package/dist/types/src/testing/setup-graph-builder.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +1 -0
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +32 -31
- package/src/graph-builder.test.ts +126 -0
- package/src/graph-builder.ts +20 -1
- package/src/graph.ts +4 -1
- package/src/node-matcher.ts +3 -3
- package/src/scheduler.browser.ts +5 -0
- package/src/scheduler.ts +17 -0
- package/src/stories/EchoGraph.stories.tsx +5 -5
- package/src/util.ts +9 -3
- package/dist/lib/browser/chunk-AKBGYELG.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-HR5S4XYH.mjs +0 -1604
- package/dist/lib/node-esm/chunk-HR5S4XYH.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -39
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -40
- /package/dist/lib/{node-esm → neutral}/testing/index.mjs.map +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/app-graph",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.765dc60934",
|
|
4
4
|
"description": "Constructs knowledge graphs for the purpose of building applications on top of",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -8,45 +8,46 @@
|
|
|
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",
|
|
15
|
+
"imports": {
|
|
16
|
+
"#scheduler": {
|
|
17
|
+
"source": {
|
|
18
|
+
"browser": "./src/scheduler.browser.ts",
|
|
19
|
+
"default": "./src/scheduler.ts"
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/types/src/scheduler.d.ts",
|
|
22
|
+
"default": "./dist/lib/neutral/scheduler.mjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
15
25
|
"exports": {
|
|
16
26
|
".": {
|
|
17
27
|
"source": "./src/index.ts",
|
|
18
28
|
"types": "./dist/types/src/index.d.ts",
|
|
19
|
-
"
|
|
20
|
-
"node": "./dist/lib/node-esm/index.mjs"
|
|
29
|
+
"default": "./dist/lib/neutral/index.mjs"
|
|
21
30
|
},
|
|
22
31
|
"./testing": {
|
|
23
32
|
"source": "./src/testing/index.ts",
|
|
24
33
|
"types": "./dist/types/src/testing/index.d.ts",
|
|
25
|
-
"
|
|
26
|
-
"node": "./dist/lib/node-esm/testing/index.mjs"
|
|
34
|
+
"default": "./dist/lib/neutral/testing/index.mjs"
|
|
27
35
|
}
|
|
28
36
|
},
|
|
29
37
|
"types": "dist/types/src/index.d.ts",
|
|
30
|
-
"typesVersions": {
|
|
31
|
-
"*": {
|
|
32
|
-
"testing": [
|
|
33
|
-
"./dist/types/src/testing/index.d.ts"
|
|
34
|
-
]
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
38
|
"files": [
|
|
38
39
|
"dist",
|
|
39
40
|
"src"
|
|
40
41
|
],
|
|
41
42
|
"dependencies": {
|
|
42
43
|
"main-thread-scheduling": "^14.1.1",
|
|
43
|
-
"@dxos/async": "0.8.4-main.
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/echo-atom": "0.8.4-main.
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
44
|
+
"@dxos/async": "0.8.4-main.765dc60934",
|
|
45
|
+
"@dxos/debug": "0.8.4-main.765dc60934",
|
|
46
|
+
"@dxos/echo-atom": "0.8.4-main.765dc60934",
|
|
47
|
+
"@dxos/invariant": "0.8.4-main.765dc60934",
|
|
48
|
+
"@dxos/echo": "0.8.4-main.765dc60934",
|
|
49
|
+
"@dxos/log": "0.8.4-main.765dc60934",
|
|
50
|
+
"@dxos/util": "0.8.4-main.765dc60934"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@effect-atom/atom-react": "^0.5.0",
|
|
@@ -56,15 +57,15 @@
|
|
|
56
57
|
"effect": "3.20.0",
|
|
57
58
|
"react": "~19.2.3",
|
|
58
59
|
"react-dom": "~19.2.3",
|
|
59
|
-
"vite": "^
|
|
60
|
-
"@dxos/echo-db": "0.8.4-main.
|
|
61
|
-
"@dxos/random": "0.8.4-main.
|
|
62
|
-
"@dxos/react-client": "0.8.4-main.
|
|
63
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
64
|
-
"@dxos/react-ui-
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/
|
|
67
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
60
|
+
"vite": "^8.0.13",
|
|
61
|
+
"@dxos/echo-db": "0.8.4-main.765dc60934",
|
|
62
|
+
"@dxos/random": "0.8.4-main.765dc60934",
|
|
63
|
+
"@dxos/react-client": "0.8.4-main.765dc60934",
|
|
64
|
+
"@dxos/react-ui": "0.8.4-main.765dc60934",
|
|
65
|
+
"@dxos/react-ui-list": "0.8.4-main.765dc60934",
|
|
66
|
+
"@dxos/storybook-utils": "0.8.4-main.765dc60934",
|
|
67
|
+
"@dxos/react-ui-tabs": "0.8.4-main.765dc60934",
|
|
68
|
+
"@dxos/ui-theme": "0.8.4-main.765dc60934"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
71
|
"@effect-atom/atom-react": "^0.5.0",
|
|
@@ -72,8 +73,8 @@
|
|
|
72
73
|
"effect": "3.20.0",
|
|
73
74
|
"react": "~19.2.3",
|
|
74
75
|
"react-dom": "~19.2.3",
|
|
75
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
76
|
-
"@dxos/ui-theme": "0.8.4-main.
|
|
76
|
+
"@dxos/react-ui": "0.8.4-main.765dc60934",
|
|
77
|
+
"@dxos/ui-theme": "0.8.4-main.765dc60934"
|
|
77
78
|
},
|
|
78
79
|
"publishConfig": {
|
|
79
80
|
"access": "public"
|
|
@@ -485,6 +485,132 @@ describe('GraphBuilder', () => {
|
|
|
485
485
|
expect(exists).to.be.true;
|
|
486
486
|
});
|
|
487
487
|
|
|
488
|
+
describe('inline nodes', () => {
|
|
489
|
+
const parent = (child?: Node.NodeArg<any>): Node.NodeArg<any> => ({
|
|
490
|
+
id: 'parent-node',
|
|
491
|
+
type: EXAMPLE_TYPE,
|
|
492
|
+
data: null,
|
|
493
|
+
nodes: child ? [child] : [],
|
|
494
|
+
});
|
|
495
|
+
|
|
496
|
+
const inlineChild = (overrides?: Partial<Node.NodeArg<any>>): Node.NodeArg<any> => ({
|
|
497
|
+
id: 'inline-child',
|
|
498
|
+
type: EXAMPLE_TYPE,
|
|
499
|
+
data: null,
|
|
500
|
+
...overrides,
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
const makeGraph = () => {
|
|
504
|
+
const registry = Registry.make();
|
|
505
|
+
const builder = GraphBuilder.make({ registry });
|
|
506
|
+
const nodesAtom = Atom.make<Node.NodeArg<any>[]>([]);
|
|
507
|
+
GraphBuilder.addExtension(
|
|
508
|
+
builder,
|
|
509
|
+
GraphBuilder.createExtensionRaw({
|
|
510
|
+
id: 'inline-connector',
|
|
511
|
+
connector: () => Atom.make((get) => get(nodesAtom)),
|
|
512
|
+
}),
|
|
513
|
+
);
|
|
514
|
+
const graph = builder.graph;
|
|
515
|
+
Graph.expand(graph, Node.RootId, 'child');
|
|
516
|
+
return { registry, builder, graph, nodesAtom };
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
const getInlineChild = (graph: Graph.ExpandableGraph) =>
|
|
520
|
+
Graph.getNode(graph, 'root/parent-node/inline-child').pipe(Option.getOrNull);
|
|
521
|
+
|
|
522
|
+
test('are removed when connector re-runs with data change', async () => {
|
|
523
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
524
|
+
registry.set(nodesAtom, [parent(inlineChild())]);
|
|
525
|
+
await GraphBuilder.flush(builder);
|
|
526
|
+
|
|
527
|
+
expect(getInlineChild(graph)).to.not.be.null;
|
|
528
|
+
|
|
529
|
+
// Remove inline child while also changing parent data to trigger the update.
|
|
530
|
+
registry.set(nodesAtom, [{ ...parent(), data: 'v2' }]);
|
|
531
|
+
await GraphBuilder.flush(builder);
|
|
532
|
+
|
|
533
|
+
expect(getInlineChild(graph)).to.be.null;
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
test('are removed when only inline children change', async () => {
|
|
537
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
538
|
+
registry.set(nodesAtom, [parent(inlineChild())]);
|
|
539
|
+
await GraphBuilder.flush(builder);
|
|
540
|
+
|
|
541
|
+
expect(getInlineChild(graph)).to.not.be.null;
|
|
542
|
+
|
|
543
|
+
// Remove inline child without touching parent — tests change detection covers inline children.
|
|
544
|
+
registry.set(nodesAtom, [parent()]);
|
|
545
|
+
await GraphBuilder.flush(builder);
|
|
546
|
+
|
|
547
|
+
expect(getInlineChild(graph)).to.be.null;
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
test('are added when connector re-runs', async () => {
|
|
551
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
552
|
+
registry.set(nodesAtom, [parent()]);
|
|
553
|
+
await GraphBuilder.flush(builder);
|
|
554
|
+
|
|
555
|
+
expect(getInlineChild(graph)).to.be.null;
|
|
556
|
+
|
|
557
|
+
registry.set(nodesAtom, [parent(inlineChild())]);
|
|
558
|
+
await GraphBuilder.flush(builder);
|
|
559
|
+
|
|
560
|
+
expect(getInlineChild(graph)).to.not.be.null;
|
|
561
|
+
});
|
|
562
|
+
|
|
563
|
+
test('reactively update data', async ({ expect }) => {
|
|
564
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
565
|
+
registry.set(nodesAtom, [parent(inlineChild({ data: 'v1' }))]);
|
|
566
|
+
await GraphBuilder.flush(builder);
|
|
567
|
+
|
|
568
|
+
expect(getInlineChild(graph)?.data).to.equal('v1');
|
|
569
|
+
|
|
570
|
+
// Change only the inline child's data — parent is unchanged.
|
|
571
|
+
registry.set(nodesAtom, [parent(inlineChild({ data: 'v2' }))]);
|
|
572
|
+
await GraphBuilder.flush(builder);
|
|
573
|
+
|
|
574
|
+
expect(getInlineChild(graph)?.data).to.equal('v2');
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
test('reactively update properties', async ({ expect }) => {
|
|
578
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
579
|
+
registry.set(nodesAtom, [parent(inlineChild({ properties: { label: 'before' } }))]);
|
|
580
|
+
await GraphBuilder.flush(builder);
|
|
581
|
+
|
|
582
|
+
expect(getInlineChild(graph)?.properties.label).to.equal('before');
|
|
583
|
+
|
|
584
|
+
registry.set(nodesAtom, [parent(inlineChild({ properties: { label: 'after' } }))]);
|
|
585
|
+
await GraphBuilder.flush(builder);
|
|
586
|
+
|
|
587
|
+
expect(getInlineChild(graph)?.properties.label).to.equal('after');
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
test('deeply nested inline nodes reactively update', async ({ expect }) => {
|
|
591
|
+
const { registry, builder, graph, nodesAtom } = makeGraph();
|
|
592
|
+
|
|
593
|
+
const withGrandchild = (data: string) =>
|
|
594
|
+
parent({
|
|
595
|
+
id: 'child',
|
|
596
|
+
type: EXAMPLE_TYPE,
|
|
597
|
+
data: null,
|
|
598
|
+
nodes: [{ id: 'grandchild', type: EXAMPLE_TYPE, data }],
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
registry.set(nodesAtom, [withGrandchild('v1')]);
|
|
602
|
+
await GraphBuilder.flush(builder);
|
|
603
|
+
|
|
604
|
+
expect(Graph.getNode(graph, 'root/parent-node/child/grandchild').pipe(Option.getOrNull)?.data).to.equal('v1');
|
|
605
|
+
|
|
606
|
+
// Change only the grandchild's data — all ancestors unchanged.
|
|
607
|
+
registry.set(nodesAtom, [withGrandchild('v2')]);
|
|
608
|
+
await GraphBuilder.flush(builder);
|
|
609
|
+
|
|
610
|
+
expect(Graph.getNode(graph, 'root/parent-node/child/grandchild').pipe(Option.getOrNull)?.data).to.equal('v2');
|
|
611
|
+
});
|
|
612
|
+
});
|
|
613
|
+
|
|
488
614
|
test('sort edges', async () => {
|
|
489
615
|
const registry = Registry.make();
|
|
490
616
|
const builder = GraphBuilder.make({ registry });
|
package/src/graph-builder.ts
CHANGED
|
@@ -11,13 +11,14 @@ import * as Option from 'effect/Option';
|
|
|
11
11
|
import * as Pipeable from 'effect/Pipeable';
|
|
12
12
|
import * as Record from 'effect/Record';
|
|
13
13
|
import type * as Schema from 'effect/Schema';
|
|
14
|
-
import { scheduleTask, yieldOrContinue } from 'main-thread-scheduling';
|
|
15
14
|
|
|
16
15
|
import { type CleanupFn, type Trigger } from '@dxos/async';
|
|
17
16
|
import { type Entity, type Type } from '@dxos/echo';
|
|
18
17
|
import { log } from '@dxos/log';
|
|
19
18
|
import { type MaybePromise, type Position, byPosition, getDebugName, isNonNullable } from '@dxos/util';
|
|
20
19
|
|
|
20
|
+
import { scheduleTask, yieldOrContinue } from '#scheduler';
|
|
21
|
+
|
|
21
22
|
import * as Graph from './graph';
|
|
22
23
|
import * as Node from './node';
|
|
23
24
|
import * as NodeMatcher from './node-matcher';
|
|
@@ -125,6 +126,8 @@ class GraphBuilderImpl implements GraphBuilder {
|
|
|
125
126
|
>();
|
|
126
127
|
/** Last-flushed node IDs per connector key, used for edge removal on update. */
|
|
127
128
|
readonly _connectorPrevious = new Map<string, string[]>();
|
|
129
|
+
/** All inline-descendant IDs per connector key, used to remove stale inline nodes on update. */
|
|
130
|
+
readonly _connectorPreviousInlineIds = new Map<string, string[]>();
|
|
128
131
|
/** Last-flushed node args per connector key, used for change detection. */
|
|
129
132
|
readonly _connectorPreviousArgs = new Map<string, Node.NodeArg<any>[]>();
|
|
130
133
|
/** Whether a dirty-flush task is already scheduled. */
|
|
@@ -178,6 +181,12 @@ class GraphBuilderImpl implements GraphBuilder {
|
|
|
178
181
|
this._connectorPrevious.set(key, ids);
|
|
179
182
|
this._connectorPreviousArgs.set(key, nodes);
|
|
180
183
|
|
|
184
|
+
const currentInlineIds = collectAllInlineIds(nodes);
|
|
185
|
+
const previousInlineIds = this._connectorPreviousInlineIds.get(key) ?? [];
|
|
186
|
+
const staleInlineIds = previousInlineIds.filter((pid) => !currentInlineIds.includes(pid));
|
|
187
|
+
this._connectorPreviousInlineIds.set(key, currentInlineIds);
|
|
188
|
+
|
|
189
|
+
Graph.removeNodes(this._graph, staleInlineIds, true);
|
|
181
190
|
Graph.removeEdges(
|
|
182
191
|
this._graph,
|
|
183
192
|
removed.map((target) => ({ source: id, target, relation })),
|
|
@@ -841,6 +850,16 @@ const qualifyNodeArgs =
|
|
|
841
850
|
};
|
|
842
851
|
});
|
|
843
852
|
|
|
853
|
+
/**
|
|
854
|
+
* Recursively collect all inline-descendant IDs (the `nodes` arrays at every level)
|
|
855
|
+
* from a list of top-level NodeArgs. Top-level IDs are excluded because they are
|
|
856
|
+
* already tracked via `_connectorPrevious`.
|
|
857
|
+
*/
|
|
858
|
+
const collectAllInlineIds = (nodes: Node.NodeArg<any>[]): string[] =>
|
|
859
|
+
nodes.flatMap((node) =>
|
|
860
|
+
node.nodes ? [...node.nodes.map((child) => child.id), ...collectAllInlineIds(node.nodes)] : [],
|
|
861
|
+
);
|
|
862
|
+
|
|
844
863
|
const connectorKey = (id: string, relation: Node.RelationInput): string => primaryKey(id, Graph.relationKey(relation));
|
|
845
864
|
|
|
846
865
|
const relationFromConnectorKey = (key: string): { id: string; relation: Node.Relation } => {
|
package/src/graph.ts
CHANGED
|
@@ -183,7 +183,10 @@ class GraphImpl implements WritableGraph {
|
|
|
183
183
|
// TODO(wittjosiah): Atom feature request, support for something akin to `ComplexMap` to allow for complex arguments.
|
|
184
184
|
readonly _connections = Atom.family<string, Atom.Atom<Node.Node[]>>((key) => {
|
|
185
185
|
return Atom.make((get) => {
|
|
186
|
-
|
|
186
|
+
const parts = key ? primaryParts(key) : [];
|
|
187
|
+
// Empty id (e.g. from `useConnections(graph, undefined, ...)`) yields a key like `\u0001child\u0002outbound`,
|
|
188
|
+
// which has 2 parts but an empty id — treat as no connections rather than throwing.
|
|
189
|
+
if (parts.length < 2 || !parts[0]) {
|
|
187
190
|
return [];
|
|
188
191
|
}
|
|
189
192
|
const { id, relation } = relationFromConnectionKey(key);
|
package/src/node-matcher.ts
CHANGED
|
@@ -127,7 +127,7 @@ export const whenEchoType =
|
|
|
127
127
|
* @example
|
|
128
128
|
* ```ts
|
|
129
129
|
* GraphBuilder.createExtension({
|
|
130
|
-
* id: 'object-
|
|
130
|
+
* id: 'object-properties',
|
|
131
131
|
* match: NodeMatcher.whenEchoObject,
|
|
132
132
|
* connector: (object) => {
|
|
133
133
|
* // `object` is typed as Obj.Unknown
|
|
@@ -201,10 +201,10 @@ export const whenAll: {
|
|
|
201
201
|
*
|
|
202
202
|
* @example
|
|
203
203
|
* ```ts
|
|
204
|
-
* // Match nodes that are either Sequences or
|
|
204
|
+
* // Match nodes that are either Sequences or Routines
|
|
205
205
|
* const whenInvocable = NodeMatcher.whenAny(
|
|
206
206
|
* NodeMatcher.whenEchoTypeMatches(Sequence),
|
|
207
|
-
* NodeMatcher.whenEchoTypeMatches(
|
|
207
|
+
* NodeMatcher.whenEchoTypeMatches(Routine.Routine),
|
|
208
208
|
* );
|
|
209
209
|
* ```
|
|
210
210
|
*/
|
package/src/scheduler.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// CF Workers / Node fallback: there is no main thread to yield to.
|
|
6
|
+
// scheduleTask runs the callback on the next microtask; yieldOrContinue is a microtask hop.
|
|
7
|
+
|
|
8
|
+
type ScheduleOptions = { strategy?: 'smooth' | 'interactive' | 'idle'; signal?: AbortSignal };
|
|
9
|
+
|
|
10
|
+
export const scheduleTask = async <T>(callback: () => T | Promise<T>, _options?: ScheduleOptions): Promise<T> => {
|
|
11
|
+
await Promise.resolve();
|
|
12
|
+
return callback();
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const yieldOrContinue = async (_priority: 'smooth' | 'interactive' | 'idle'): Promise<void> => {
|
|
16
|
+
await Promise.resolve();
|
|
17
|
+
};
|
|
@@ -8,8 +8,8 @@ import * as Function from 'effect/Function';
|
|
|
8
8
|
import * as Option from 'effect/Option';
|
|
9
9
|
import React, { type PropsWithChildren, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import { Obj, Query } from '@dxos/echo';
|
|
11
|
+
import { type Space, SpaceState, isSpace } from '@dxos/client/echo';
|
|
12
|
+
import { Filter, Obj, Query } from '@dxos/echo';
|
|
13
13
|
import { AtomObj, AtomQuery } from '@dxos/echo-atom';
|
|
14
14
|
import { TestSchema } from '@dxos/echo/testing';
|
|
15
15
|
import { random } from '@dxos/random';
|
|
@@ -145,7 +145,7 @@ const runAction = async (client: Client, action: Action) => {
|
|
|
145
145
|
case Action.RENAME_SPACE: {
|
|
146
146
|
const space = getRandomSpace(client);
|
|
147
147
|
if (space) {
|
|
148
|
-
Obj.
|
|
148
|
+
Obj.update(space.properties, (obj) => {
|
|
149
149
|
obj.name = random.commerce.productName();
|
|
150
150
|
});
|
|
151
151
|
}
|
|
@@ -175,8 +175,8 @@ const runAction = async (client: Client, action: Action) => {
|
|
|
175
175
|
if (space) {
|
|
176
176
|
const objects = await space.db.query(Filter.type(TestSchema.Expando, { type: 'test' })).run();
|
|
177
177
|
const object = objects[Math.floor(Math.random() * objects.length)];
|
|
178
|
-
Obj.
|
|
179
|
-
|
|
178
|
+
Obj.update(object, (object) => {
|
|
179
|
+
object.name = random.commerce.productName();
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
182
|
break;
|
package/src/util.ts
CHANGED
|
@@ -37,8 +37,12 @@ export const normalizeRelation = (relation?: Node.RelationInput): Node.Relation
|
|
|
37
37
|
* Shallow-compare two values: same reference, or same own-keys with === values.
|
|
38
38
|
*/
|
|
39
39
|
export const shallowEqual = (a: unknown, b: unknown): boolean => {
|
|
40
|
-
if (a === b)
|
|
41
|
-
|
|
40
|
+
if (a === b) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (a == null || b == null || typeof a !== 'object' || typeof b !== 'object') {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
42
46
|
const keysA = Object.keys(a as Record<string, unknown>);
|
|
43
47
|
const keysB = Object.keys(b as Record<string, unknown>);
|
|
44
48
|
if (keysA.length !== keysB.length) {
|
|
@@ -49,6 +53,7 @@ export const shallowEqual = (a: unknown, b: unknown): boolean => {
|
|
|
49
53
|
|
|
50
54
|
/**
|
|
51
55
|
* Returns true if two NodeArg arrays are semantically identical (same id, type, data, properties per index).
|
|
56
|
+
* Inline child nodes (the `nodes` field) are compared recursively.
|
|
52
57
|
*/
|
|
53
58
|
export const nodeArgsUnchanged = (prev: Node.NodeArg<any>[], next: Node.NodeArg<any>[]): boolean => {
|
|
54
59
|
if (prev.length !== next.length) {
|
|
@@ -61,7 +66,8 @@ export const nodeArgsUnchanged = (prev: Node.NodeArg<any>[], next: Node.NodeArg<
|
|
|
61
66
|
prevNode.id === nextNode.id &&
|
|
62
67
|
prevNode.type === nextNode.type &&
|
|
63
68
|
shallowEqual(prevNode.data, nextNode.data) &&
|
|
64
|
-
shallowEqual(prevNode.properties, nextNode.properties)
|
|
69
|
+
shallowEqual(prevNode.properties, nextNode.properties) &&
|
|
70
|
+
nodeArgsUnchanged(prevNode.nodes ?? [], nextNode.nodes ?? [])
|
|
65
71
|
);
|
|
66
72
|
});
|
|
67
73
|
};
|