Mercurial > code > home > repos > streamed-graph
comparison src/ConfiguredSources.ts @ 128:5a1a79f54779
big rewrite
author | drewp@bigasterisk.com |
---|---|
date | Fri, 05 May 2023 21:26:36 -0700 |
parents | |
children | 9347277e8311 |
comparison
equal
deleted
inserted
replaced
127:d2580faef057 | 128:5a1a79f54779 |
---|---|
1 import { NamedNode } from "n3"; | |
2 import { SubEvent } from "sub-events"; | |
3 import { MultiStore } from "./MultiStore"; | |
4 import { SourceGraph } from "./SourceGraph"; | |
5 import { ViewConfig } from "./layout/ViewConfig"; | |
6 | |
7 // Connect <streamed-graph>, <sg-source>, <sg-view>, MultiStore, and ViewConfig. | |
8 // Makes the (single) MultiStore and the (updated as needed) ViewConfig. | |
9 | |
10 // This is poorly named since it deals in both the <sg-source> elements that you | |
11 // "configured" plus the set of SourceGraph objs that are actually connected to remote graphs. | |
12 | |
13 // sic private- this is just for documenting the interface more clearly | |
14 interface IConfiguredSources { | |
15 // outputs | |
16 graph: MultiStore; // const- only the graph contents will change | |
17 viewConfig: ViewConfig; | |
18 | |
19 // methods | |
20 newSourceGraph: (s: SourceGraph) => void; | |
21 lostSourceGraph: (s: SourceGraph) => void; | |
22 viewUriChanged: (v: NamedNode) => void; | |
23 | |
24 // events | |
25 viewConfigChanged: SubEvent<ViewConfig>; | |
26 } | |
27 | |
28 export class ConfiguredSources implements IConfiguredSources { | |
29 graph: MultiStore; | |
30 viewConfig: ViewConfig; | |
31 | |
32 viewConfigChanged: SubEvent<ViewConfig> = new SubEvent(); | |
33 | |
34 private viewUri: NamedNode = new NamedNode("empty-view-config"); | |
35 | |
36 constructor() { | |
37 this.graph = new MultiStore(); | |
38 this.graph.graphChanged.subscribe(() => this.viewConfigMaybeChanged()); | |
39 this.viewConfig = new ViewConfig(this.graph, this.viewUri); | |
40 } | |
41 | |
42 private viewConfigMaybeChanged() { | |
43 this.viewConfig = new ViewConfig(this.graph, this.viewUri); | |
44 this.viewConfigChanged.emit(this.viewConfig); | |
45 } | |
46 | |
47 newSourceGraph(s: SourceGraph) { | |
48 this.graph.newStore(s); | |
49 this.viewConfigMaybeChanged(); | |
50 } | |
51 | |
52 lostSourceGraph(s: SourceGraph) { | |
53 throw new Error("notimplemented"); | |
54 this.viewConfigMaybeChanged(); | |
55 } | |
56 | |
57 viewUriChanged(v: NamedNode) { | |
58 if (v && v == this.viewUri) { | |
59 return; | |
60 } | |
61 this.viewUri = v; | |
62 this.viewConfigMaybeChanged(); | |
63 } | |
64 } |