@dxos/app-graph 0.8.4-main.fd6878d → 0.8.4-main.fffef41
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/index.mjs +112 -107
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +112 -107
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/graph-builder.d.ts +16 -16
- package/dist/types/src/graph-builder.d.ts.map +1 -1
- package/dist/types/src/graph.d.ts +19 -19
- package/dist/types/src/graph.d.ts.map +1 -1
- package/dist/types/src/stories/EchoGraph.stories.d.ts +8 -10
- package/dist/types/src/stories/EchoGraph.stories.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts +3 -3
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -32
- package/src/graph-builder.test.ts +34 -33
- package/src/graph-builder.ts +50 -45
- package/src/graph.test.ts +3 -3
- package/src/graph.ts +115 -73
- package/src/signals-integration.test.ts +29 -28
- package/src/stories/EchoGraph.stories.tsx +34 -26
- package/src/stories/Tree.tsx +1 -1
- package/src/testing.ts +4 -4
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// src/graph.ts
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { Atom, Registry } from "@effect-atom/atom-react";
|
|
3
|
+
import * as Function from "effect/Function";
|
|
4
|
+
import * as Option from "effect/Option";
|
|
5
|
+
import * as Record from "effect/Record";
|
|
4
6
|
import { Event, Trigger } from "@dxos/async";
|
|
5
7
|
import { todo } from "@dxos/debug";
|
|
6
8
|
import { invariant } from "@dxos/invariant";
|
|
@@ -12,7 +14,7 @@ var getGraph = (node) => {
|
|
|
12
14
|
const graph = node[graphSymbol];
|
|
13
15
|
invariant(graph, "Node is not associated with a graph.", {
|
|
14
16
|
F: __dxlog_file,
|
|
15
|
-
L:
|
|
17
|
+
L: 29,
|
|
16
18
|
S: void 0,
|
|
17
19
|
A: [
|
|
18
20
|
"graph",
|
|
@@ -46,16 +48,16 @@ var Graph = class {
|
|
|
46
48
|
]
|
|
47
49
|
]);
|
|
48
50
|
/** @internal */
|
|
49
|
-
_node =
|
|
51
|
+
_node = Atom.family((id) => {
|
|
50
52
|
const initial = Option.flatten(Record.get(this._initialNodes, id));
|
|
51
|
-
return
|
|
53
|
+
return Atom.make(initial).pipe(Atom.keepAlive, Atom.withLabel(`graph:node:${id}`));
|
|
52
54
|
});
|
|
53
|
-
_nodeOrThrow =
|
|
54
|
-
return
|
|
55
|
-
const node =
|
|
55
|
+
_nodeOrThrow = Atom.family((id) => {
|
|
56
|
+
return Atom.make((get2) => {
|
|
57
|
+
const node = get2(this._node(id));
|
|
56
58
|
invariant(Option.isSome(node), `Node not available: ${id}`, {
|
|
57
59
|
F: __dxlog_file,
|
|
58
|
-
L:
|
|
60
|
+
L: 267,
|
|
59
61
|
S: this,
|
|
60
62
|
A: [
|
|
61
63
|
"Option.isSome(node)",
|
|
@@ -65,33 +67,33 @@ var Graph = class {
|
|
|
65
67
|
return node.value;
|
|
66
68
|
});
|
|
67
69
|
});
|
|
68
|
-
_edges =
|
|
70
|
+
_edges = Atom.family((id) => {
|
|
69
71
|
const initial = Record.get(this._initialEdges, id).pipe(Option.getOrElse(() => ({
|
|
70
72
|
inbound: [],
|
|
71
73
|
outbound: []
|
|
72
74
|
})));
|
|
73
|
-
return
|
|
75
|
+
return Atom.make(initial).pipe(Atom.keepAlive, Atom.withLabel(`graph:edges:${id}`));
|
|
74
76
|
});
|
|
75
|
-
// NOTE: Currently the argument to the family needs to be referentially stable for the
|
|
76
|
-
// TODO(wittjosiah):
|
|
77
|
-
_connections =
|
|
78
|
-
return
|
|
77
|
+
// NOTE: Currently the argument to the family needs to be referentially stable for the atom to be referentially stable.
|
|
78
|
+
// TODO(wittjosiah): Atom feature request, support for something akin to `ComplexMap` to allow for complex arguments.
|
|
79
|
+
_connections = Atom.family((key) => {
|
|
80
|
+
return Atom.make((get2) => {
|
|
79
81
|
const [id, relation] = key.split("$");
|
|
80
|
-
const edges =
|
|
81
|
-
return edges[relation].map((id2) =>
|
|
82
|
-
}).pipe(
|
|
82
|
+
const edges = get2(this._edges(id));
|
|
83
|
+
return edges[relation].map((id2) => get2(this._node(id2))).filter(Option.isSome).map((o) => o.value);
|
|
84
|
+
}).pipe(Atom.withLabel(`graph:connections:${key}`));
|
|
83
85
|
});
|
|
84
|
-
_actions =
|
|
85
|
-
return
|
|
86
|
-
return
|
|
87
|
-
}).pipe(
|
|
86
|
+
_actions = Atom.family((id) => {
|
|
87
|
+
return Atom.make((get2) => {
|
|
88
|
+
return get2(this._connections(`${id}$outbound`)).filter((node) => node.type === ACTION_TYPE || node.type === ACTION_GROUP_TYPE);
|
|
89
|
+
}).pipe(Atom.withLabel(`graph:actions:${id}`));
|
|
88
90
|
});
|
|
89
|
-
_json =
|
|
90
|
-
return
|
|
91
|
+
_json = Atom.family((id) => {
|
|
92
|
+
return Atom.make((get2) => {
|
|
91
93
|
const toJSON = (node, seen = []) => {
|
|
92
|
-
const nodes =
|
|
94
|
+
const nodes = get2(this.connections(node.id));
|
|
93
95
|
const obj = {
|
|
94
|
-
id: node.id
|
|
96
|
+
id: node.id,
|
|
95
97
|
type: node.type
|
|
96
98
|
};
|
|
97
99
|
if (node.properties.label) {
|
|
@@ -108,9 +110,9 @@ var Graph = class {
|
|
|
108
110
|
}
|
|
109
111
|
return obj;
|
|
110
112
|
};
|
|
111
|
-
const root =
|
|
113
|
+
const root = get2(this.nodeOrThrow(id));
|
|
112
114
|
return toJSON(root);
|
|
113
|
-
}).pipe(
|
|
115
|
+
}).pipe(Atom.withLabel(`graph:json:${id}`));
|
|
114
116
|
});
|
|
115
117
|
constructor({ registry, nodes, edges, onInitialize, onExpand, onRemoveNode } = {}) {
|
|
116
118
|
this._registry = registry ?? Registry.make();
|
|
@@ -174,7 +176,7 @@ var Graph = class {
|
|
|
174
176
|
initialized
|
|
175
177
|
}, {
|
|
176
178
|
F: __dxlog_file,
|
|
177
|
-
L:
|
|
179
|
+
L: 399,
|
|
178
180
|
S: this,
|
|
179
181
|
C: (f, a) => f(...a)
|
|
180
182
|
});
|
|
@@ -191,7 +193,7 @@ var Graph = class {
|
|
|
191
193
|
expanded
|
|
192
194
|
}, {
|
|
193
195
|
F: __dxlog_file,
|
|
194
|
-
L:
|
|
196
|
+
L: 409,
|
|
195
197
|
S: this,
|
|
196
198
|
C: (f, a) => f(...a)
|
|
197
199
|
});
|
|
@@ -201,14 +203,14 @@ var Graph = class {
|
|
|
201
203
|
}
|
|
202
204
|
}
|
|
203
205
|
addNodes(nodes) {
|
|
204
|
-
|
|
206
|
+
Atom.batch(() => {
|
|
205
207
|
nodes.map((node) => this.addNode(node));
|
|
206
208
|
});
|
|
207
209
|
}
|
|
208
210
|
addNode({ nodes, edges, ...nodeArg }) {
|
|
209
211
|
const { id, type, data = null, properties = {} } = nodeArg;
|
|
210
|
-
const
|
|
211
|
-
const node = this._registry.get(
|
|
212
|
+
const nodeAtom = this._node(id);
|
|
213
|
+
const node = this._registry.get(nodeAtom);
|
|
212
214
|
Option.match(node, {
|
|
213
215
|
onSome: (node2) => {
|
|
214
216
|
const typeChanged = node2.type !== type;
|
|
@@ -221,7 +223,7 @@ var Graph = class {
|
|
|
221
223
|
propertiesChanged
|
|
222
224
|
}, {
|
|
223
225
|
F: __dxlog_file,
|
|
224
|
-
L:
|
|
226
|
+
L: 431,
|
|
225
227
|
S: this,
|
|
226
228
|
C: (f, a) => f(...a)
|
|
227
229
|
});
|
|
@@ -233,7 +235,7 @@ var Graph = class {
|
|
|
233
235
|
properties
|
|
234
236
|
}, {
|
|
235
237
|
F: __dxlog_file,
|
|
236
|
-
L:
|
|
238
|
+
L: 438,
|
|
237
239
|
S: this,
|
|
238
240
|
C: (f, a) => f(...a)
|
|
239
241
|
});
|
|
@@ -246,7 +248,7 @@ var Graph = class {
|
|
|
246
248
|
...properties
|
|
247
249
|
}
|
|
248
250
|
});
|
|
249
|
-
this._registry.set(
|
|
251
|
+
this._registry.set(nodeAtom, newNode);
|
|
250
252
|
this.onNodeChanged.emit({
|
|
251
253
|
id,
|
|
252
254
|
node: newNode
|
|
@@ -261,7 +263,7 @@ var Graph = class {
|
|
|
261
263
|
properties
|
|
262
264
|
}, {
|
|
263
265
|
F: __dxlog_file,
|
|
264
|
-
L:
|
|
266
|
+
L: 450,
|
|
265
267
|
S: this,
|
|
266
268
|
C: (f, a) => f(...a)
|
|
267
269
|
});
|
|
@@ -271,7 +273,7 @@ var Graph = class {
|
|
|
271
273
|
data,
|
|
272
274
|
properties
|
|
273
275
|
});
|
|
274
|
-
this._registry.set(
|
|
276
|
+
this._registry.set(nodeAtom, newNode);
|
|
275
277
|
this.onNodeChanged.emit({
|
|
276
278
|
id,
|
|
277
279
|
node: newNode
|
|
@@ -291,13 +293,13 @@ var Graph = class {
|
|
|
291
293
|
}
|
|
292
294
|
}
|
|
293
295
|
removeNodes(ids, edges = false) {
|
|
294
|
-
|
|
296
|
+
Atom.batch(() => {
|
|
295
297
|
ids.map((id) => this.removeNode(id, edges));
|
|
296
298
|
});
|
|
297
299
|
}
|
|
298
300
|
removeNode(id, edges = false) {
|
|
299
|
-
const
|
|
300
|
-
this._registry.set(
|
|
301
|
+
const nodeAtom = this._node(id);
|
|
302
|
+
this._registry.set(nodeAtom, Option.none());
|
|
301
303
|
this.onNodeChanged.emit({
|
|
302
304
|
id,
|
|
303
305
|
node: Option.none()
|
|
@@ -319,24 +321,24 @@ var Graph = class {
|
|
|
319
321
|
this._onRemoveNode?.(id);
|
|
320
322
|
}
|
|
321
323
|
addEdges(edges) {
|
|
322
|
-
|
|
324
|
+
Atom.batch(() => {
|
|
323
325
|
edges.map((edge) => this.addEdge(edge));
|
|
324
326
|
});
|
|
325
327
|
}
|
|
326
328
|
addEdge(edgeArg) {
|
|
327
|
-
const
|
|
328
|
-
const source = this._registry.get(
|
|
329
|
+
const sourceAtom = this._edges(edgeArg.source);
|
|
330
|
+
const source = this._registry.get(sourceAtom);
|
|
329
331
|
if (!source.outbound.includes(edgeArg.target)) {
|
|
330
332
|
log("add outbound edge", {
|
|
331
333
|
source: edgeArg.source,
|
|
332
334
|
target: edgeArg.target
|
|
333
335
|
}, {
|
|
334
336
|
F: __dxlog_file,
|
|
335
|
-
L:
|
|
337
|
+
L: 505,
|
|
336
338
|
S: this,
|
|
337
339
|
C: (f, a) => f(...a)
|
|
338
340
|
});
|
|
339
|
-
this._registry.set(
|
|
341
|
+
this._registry.set(sourceAtom, {
|
|
340
342
|
inbound: source.inbound,
|
|
341
343
|
outbound: [
|
|
342
344
|
...source.outbound,
|
|
@@ -344,19 +346,19 @@ var Graph = class {
|
|
|
344
346
|
]
|
|
345
347
|
});
|
|
346
348
|
}
|
|
347
|
-
const
|
|
348
|
-
const target = this._registry.get(
|
|
349
|
+
const targetAtom = this._edges(edgeArg.target);
|
|
350
|
+
const target = this._registry.get(targetAtom);
|
|
349
351
|
if (!target.inbound.includes(edgeArg.source)) {
|
|
350
352
|
log("add inbound edge", {
|
|
351
353
|
source: edgeArg.source,
|
|
352
354
|
target: edgeArg.target
|
|
353
355
|
}, {
|
|
354
356
|
F: __dxlog_file,
|
|
355
|
-
L:
|
|
357
|
+
L: 518,
|
|
356
358
|
S: this,
|
|
357
359
|
C: (f, a) => f(...a)
|
|
358
360
|
});
|
|
359
|
-
this._registry.set(
|
|
361
|
+
this._registry.set(targetAtom, {
|
|
360
362
|
inbound: [
|
|
361
363
|
...target.inbound,
|
|
362
364
|
edgeArg.source
|
|
@@ -366,30 +368,30 @@ var Graph = class {
|
|
|
366
368
|
}
|
|
367
369
|
}
|
|
368
370
|
removeEdges(edges, removeOrphans = false) {
|
|
369
|
-
|
|
371
|
+
Atom.batch(() => {
|
|
370
372
|
edges.map((edge) => this.removeEdge(edge, removeOrphans));
|
|
371
373
|
});
|
|
372
374
|
}
|
|
373
375
|
removeEdge(edgeArg, removeOrphans = false) {
|
|
374
|
-
const
|
|
375
|
-
const source = this._registry.get(
|
|
376
|
+
const sourceAtom = this._edges(edgeArg.source);
|
|
377
|
+
const source = this._registry.get(sourceAtom);
|
|
376
378
|
if (source.outbound.includes(edgeArg.target)) {
|
|
377
|
-
this._registry.set(
|
|
379
|
+
this._registry.set(sourceAtom, {
|
|
378
380
|
inbound: source.inbound,
|
|
379
381
|
outbound: source.outbound.filter((id) => id !== edgeArg.target)
|
|
380
382
|
});
|
|
381
383
|
}
|
|
382
|
-
const
|
|
383
|
-
const target = this._registry.get(
|
|
384
|
+
const targetAtom = this._edges(edgeArg.target);
|
|
385
|
+
const target = this._registry.get(targetAtom);
|
|
384
386
|
if (target.inbound.includes(edgeArg.source)) {
|
|
385
|
-
this._registry.set(
|
|
387
|
+
this._registry.set(targetAtom, {
|
|
386
388
|
inbound: target.inbound.filter((id) => id !== edgeArg.source),
|
|
387
389
|
outbound: target.outbound
|
|
388
390
|
});
|
|
389
391
|
}
|
|
390
392
|
if (removeOrphans) {
|
|
391
|
-
const source2 = this._registry.get(
|
|
392
|
-
const target2 = this._registry.get(
|
|
393
|
+
const source2 = this._registry.get(sourceAtom);
|
|
394
|
+
const target2 = this._registry.get(targetAtom);
|
|
393
395
|
if (source2.outbound.length === 0 && source2.inbound.length === 0 && edgeArg.source !== ROOT_ID) {
|
|
394
396
|
this.removeNodes([
|
|
395
397
|
edgeArg.source
|
|
@@ -403,15 +405,15 @@ var Graph = class {
|
|
|
403
405
|
}
|
|
404
406
|
}
|
|
405
407
|
sortEdges(id, relation, order) {
|
|
406
|
-
const
|
|
407
|
-
const edges = this._registry.get(
|
|
408
|
+
const edgesAtom = this._edges(id);
|
|
409
|
+
const edges = this._registry.get(edgesAtom);
|
|
408
410
|
const unsorted = edges[relation].filter((id2) => !order.includes(id2)) ?? [];
|
|
409
411
|
const sorted = order.filter((id2) => edges[relation].includes(id2)) ?? [];
|
|
410
412
|
edges[relation].splice(0, edges[relation].length, ...[
|
|
411
413
|
...sorted,
|
|
412
414
|
...unsorted
|
|
413
415
|
]);
|
|
414
|
-
this._registry.set(
|
|
416
|
+
this._registry.set(edgesAtom, edges);
|
|
415
417
|
}
|
|
416
418
|
traverse({ visitor, source = ROOT_ID, relation = "outbound" }, path = []) {
|
|
417
419
|
if (path.includes(source)) {
|
|
@@ -435,7 +437,7 @@ var Graph = class {
|
|
|
435
437
|
]));
|
|
436
438
|
}
|
|
437
439
|
getPath({ source = "root", target }) {
|
|
438
|
-
return pipe(this.getNode(source), Option.flatMap((node) => {
|
|
440
|
+
return Function.pipe(this.getNode(source), Option.flatMap((node) => {
|
|
439
441
|
let found = Option.none();
|
|
440
442
|
this.traverse({
|
|
441
443
|
source: node.id,
|
|
@@ -479,9 +481,12 @@ var Graph = class {
|
|
|
479
481
|
};
|
|
480
482
|
|
|
481
483
|
// src/graph-builder.ts
|
|
482
|
-
import {
|
|
484
|
+
import { Atom as Atom2, Registry as Registry2 } from "@effect-atom/atom-react";
|
|
483
485
|
import { effect } from "@preact/signals-core";
|
|
484
|
-
import
|
|
486
|
+
import * as Array from "effect/Array";
|
|
487
|
+
import * as Function2 from "effect/Function";
|
|
488
|
+
import * as Option2 from "effect/Option";
|
|
489
|
+
import * as Record2 from "effect/Record";
|
|
485
490
|
import { log as log2 } from "@dxos/log";
|
|
486
491
|
import { byPosition, getDebugName, isNode, isNonNullable as isNonNullable2 } from "@dxos/util";
|
|
487
492
|
|
|
@@ -497,10 +502,10 @@ var __dxlog_file2 = "/__w/dxos/dxos/packages/sdk/app-graph/src/graph-builder.ts"
|
|
|
497
502
|
var createExtension = (extension) => {
|
|
498
503
|
const { id, position = "static", relation = "outbound", resolver: _resolver, connector: _connector, actions: _actions, actionGroups: _actionGroups } = extension;
|
|
499
504
|
const getId = (key) => `${id}/${key}`;
|
|
500
|
-
const resolver = _resolver &&
|
|
501
|
-
const connector = _connector &&
|
|
502
|
-
const actionGroups = _actionGroups &&
|
|
503
|
-
const actions = _actions &&
|
|
505
|
+
const resolver = _resolver && Atom2.family((id2) => _resolver(id2).pipe(Atom2.withLabel(`graph-builder:_resolver:${id2}`)));
|
|
506
|
+
const connector = _connector && Atom2.family((node) => _connector(node).pipe(Atom2.withLabel(`graph-builder:_connector:${id}`)));
|
|
507
|
+
const actionGroups = _actionGroups && Atom2.family((node) => _actionGroups(node).pipe(Atom2.withLabel(`graph-builder:_actionGroups:${id}`)));
|
|
508
|
+
const actions = _actions && Atom2.family((node) => _actions(node).pipe(Atom2.withLabel(`graph-builder:_actions:${id}`)));
|
|
504
509
|
return [
|
|
505
510
|
resolver ? {
|
|
506
511
|
id: getId("resolver"),
|
|
@@ -511,30 +516,30 @@ var createExtension = (extension) => {
|
|
|
511
516
|
id: getId("connector"),
|
|
512
517
|
position,
|
|
513
518
|
relation,
|
|
514
|
-
connector:
|
|
519
|
+
connector: Atom2.family((node) => Atom2.make((get2) => {
|
|
515
520
|
try {
|
|
516
|
-
return
|
|
521
|
+
return get2(connector(node));
|
|
517
522
|
} catch {
|
|
518
523
|
log2.warn("Error in connector", {
|
|
519
524
|
id: getId("connector"),
|
|
520
525
|
node
|
|
521
526
|
}, {
|
|
522
527
|
F: __dxlog_file2,
|
|
523
|
-
L:
|
|
528
|
+
L: 114,
|
|
524
529
|
S: void 0,
|
|
525
530
|
C: (f, a) => f(...a)
|
|
526
531
|
});
|
|
527
532
|
return [];
|
|
528
533
|
}
|
|
529
|
-
}).pipe(
|
|
534
|
+
}).pipe(Atom2.withLabel(`graph-builder:connector:${id}`)))
|
|
530
535
|
} : void 0,
|
|
531
536
|
actionGroups ? {
|
|
532
537
|
id: getId("actionGroups"),
|
|
533
538
|
position,
|
|
534
539
|
relation: "outbound",
|
|
535
|
-
connector:
|
|
540
|
+
connector: Atom2.family((node) => Atom2.make((get2) => {
|
|
536
541
|
try {
|
|
537
|
-
return
|
|
542
|
+
return get2(actionGroups(node)).map((arg) => ({
|
|
538
543
|
...arg,
|
|
539
544
|
data: actionGroupSymbol,
|
|
540
545
|
type: ACTION_GROUP_TYPE
|
|
@@ -545,21 +550,21 @@ var createExtension = (extension) => {
|
|
|
545
550
|
node
|
|
546
551
|
}, {
|
|
547
552
|
F: __dxlog_file2,
|
|
548
|
-
L:
|
|
553
|
+
L: 135,
|
|
549
554
|
S: void 0,
|
|
550
555
|
C: (f, a) => f(...a)
|
|
551
556
|
});
|
|
552
557
|
return [];
|
|
553
558
|
}
|
|
554
|
-
}).pipe(
|
|
559
|
+
}).pipe(Atom2.withLabel(`graph-builder:connector:actionGroups:${id}`)))
|
|
555
560
|
} : void 0,
|
|
556
561
|
actions ? {
|
|
557
562
|
id: getId("actions"),
|
|
558
563
|
position,
|
|
559
564
|
relation: "outbound",
|
|
560
|
-
connector:
|
|
565
|
+
connector: Atom2.family((node) => Atom2.make((get2) => {
|
|
561
566
|
try {
|
|
562
|
-
return
|
|
567
|
+
return get2(actions(node)).map((arg) => ({
|
|
563
568
|
...arg,
|
|
564
569
|
type: ACTION_TYPE
|
|
565
570
|
}));
|
|
@@ -569,13 +574,13 @@ var createExtension = (extension) => {
|
|
|
569
574
|
node
|
|
570
575
|
}, {
|
|
571
576
|
F: __dxlog_file2,
|
|
572
|
-
L:
|
|
577
|
+
L: 152,
|
|
573
578
|
S: void 0,
|
|
574
579
|
C: (f, a) => f(...a)
|
|
575
580
|
});
|
|
576
581
|
return [];
|
|
577
582
|
}
|
|
578
|
-
}).pipe(
|
|
583
|
+
}).pipe(Atom2.withLabel(`graph-builder:connector:actions:${id}`)))
|
|
579
584
|
} : void 0
|
|
580
585
|
].filter(isNonNullable2);
|
|
581
586
|
};
|
|
@@ -595,7 +600,7 @@ var flattenExtensions = (extension, acc = []) => {
|
|
|
595
600
|
var GraphBuilder = class _GraphBuilder {
|
|
596
601
|
// TODO(wittjosiah): Use Context.
|
|
597
602
|
_subscriptions = /* @__PURE__ */ new Map();
|
|
598
|
-
_extensions =
|
|
603
|
+
_extensions = Atom2.make(Record2.empty()).pipe(Atom2.keepAlive, Atom2.withLabel("graph-builder:extensions"));
|
|
599
604
|
_initialized = {};
|
|
600
605
|
_registry;
|
|
601
606
|
_graph;
|
|
@@ -678,26 +683,26 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
678
683
|
this._subscriptions.forEach((unsubscribe) => unsubscribe());
|
|
679
684
|
this._subscriptions.clear();
|
|
680
685
|
}
|
|
681
|
-
_resolvers =
|
|
682
|
-
return
|
|
683
|
-
return
|
|
686
|
+
_resolvers = Atom2.family((id) => {
|
|
687
|
+
return Atom2.make((get2) => {
|
|
688
|
+
return Function2.pipe(get2(this._extensions), Record2.values, Array.sortBy(byPosition), Array.map(({ resolver }) => resolver), Array.filter(isNonNullable2), Array.map((resolver) => get2(resolver(id))), Array.filter(isNonNullable2), Array.head);
|
|
684
689
|
});
|
|
685
690
|
});
|
|
686
|
-
_connectors =
|
|
687
|
-
return
|
|
691
|
+
_connectors = Atom2.family((key) => {
|
|
692
|
+
return Atom2.make((get2) => {
|
|
688
693
|
const [id, relation] = key.split("+");
|
|
689
694
|
const node = this._graph.node(id);
|
|
690
|
-
return
|
|
691
|
-
|
|
695
|
+
return Function2.pipe(
|
|
696
|
+
get2(this._extensions),
|
|
692
697
|
Record2.values,
|
|
693
698
|
// TODO(wittjosiah): Sort on write rather than read.
|
|
694
699
|
Array.sortBy(byPosition),
|
|
695
700
|
Array.filter(({ relation: _relation = "outbound" }) => _relation === relation),
|
|
696
701
|
Array.map(({ connector }) => connector?.(node)),
|
|
697
702
|
Array.filter(isNonNullable2),
|
|
698
|
-
Array.flatMap((result) =>
|
|
703
|
+
Array.flatMap((result) => get2(result))
|
|
699
704
|
);
|
|
700
|
-
}).pipe(
|
|
705
|
+
}).pipe(Atom2.withLabel(`graph-builder:connectors:${key}`));
|
|
701
706
|
});
|
|
702
707
|
_onExpand(id, relation) {
|
|
703
708
|
log2("onExpand", {
|
|
@@ -706,7 +711,7 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
706
711
|
registry: getDebugName(this._registry)
|
|
707
712
|
}, {
|
|
708
713
|
F: __dxlog_file2,
|
|
709
|
-
L:
|
|
714
|
+
L: 329,
|
|
710
715
|
S: this,
|
|
711
716
|
C: (f, a) => f(...a)
|
|
712
717
|
});
|
|
@@ -723,12 +728,12 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
723
728
|
removed
|
|
724
729
|
}, {
|
|
725
730
|
F: __dxlog_file2,
|
|
726
|
-
L:
|
|
731
|
+
L: 340,
|
|
727
732
|
S: this,
|
|
728
733
|
C: (f, a) => f(...a)
|
|
729
734
|
});
|
|
730
735
|
const update = () => {
|
|
731
|
-
|
|
736
|
+
Atom2.batch(() => {
|
|
732
737
|
this._graph.removeEdges(removed.map((target) => ({
|
|
733
738
|
source: id,
|
|
734
739
|
target
|
|
@@ -760,7 +765,7 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
760
765
|
id
|
|
761
766
|
}, {
|
|
762
767
|
F: __dxlog_file2,
|
|
763
|
-
L:
|
|
768
|
+
L: 377,
|
|
764
769
|
S: this,
|
|
765
770
|
C: (f, a) => f(...a)
|
|
766
771
|
});
|
|
@@ -791,23 +796,23 @@ var GraphBuilder = class _GraphBuilder {
|
|
|
791
796
|
this._subscriptions.delete(id);
|
|
792
797
|
}
|
|
793
798
|
};
|
|
794
|
-
var
|
|
795
|
-
return
|
|
799
|
+
var atomFromSignal = (cb) => {
|
|
800
|
+
return Atom2.make((get2) => {
|
|
796
801
|
const dispose = effect(() => {
|
|
797
|
-
|
|
802
|
+
get2.setSelf(cb());
|
|
798
803
|
});
|
|
799
|
-
|
|
804
|
+
get2.addFinalizer(() => dispose());
|
|
800
805
|
return cb();
|
|
801
806
|
});
|
|
802
807
|
};
|
|
803
|
-
var observableFamily =
|
|
804
|
-
return
|
|
805
|
-
const subscription = observable.subscribe((value) =>
|
|
806
|
-
|
|
808
|
+
var observableFamily = Atom2.family((observable) => {
|
|
809
|
+
return Atom2.make((get2) => {
|
|
810
|
+
const subscription = observable.subscribe((value) => get2.setSelf(value));
|
|
811
|
+
get2.addFinalizer(() => subscription.unsubscribe());
|
|
807
812
|
return observable.get();
|
|
808
813
|
});
|
|
809
814
|
});
|
|
810
|
-
var
|
|
815
|
+
var atomFromObservable = (observable) => {
|
|
811
816
|
return observableFamily(observable);
|
|
812
817
|
};
|
|
813
818
|
export {
|
|
@@ -818,14 +823,14 @@ export {
|
|
|
818
823
|
ROOT_ID,
|
|
819
824
|
ROOT_TYPE,
|
|
820
825
|
actionGroupSymbol,
|
|
826
|
+
atomFromObservable,
|
|
827
|
+
atomFromSignal,
|
|
821
828
|
createExtension,
|
|
822
829
|
flattenExtensions,
|
|
823
830
|
getGraph,
|
|
824
831
|
isAction,
|
|
825
832
|
isActionGroup,
|
|
826
833
|
isActionLike,
|
|
827
|
-
isGraphNode
|
|
828
|
-
rxFromObservable,
|
|
829
|
-
rxFromSignal
|
|
834
|
+
isGraphNode
|
|
830
835
|
};
|
|
831
836
|
//# sourceMappingURL=index.mjs.map
|