Mercurial > code > home > repos > streamed-graph
view src/ConfiguredSources.ts @ 129:f47661b9ed34
merge
author | drewp@bigasterisk.com |
---|---|
date | Fri, 05 May 2023 21:27:24 -0700 |
parents | 5a1a79f54779 |
children | 9347277e8311 |
line wrap: on
line source
import { NamedNode } from "n3"; import { SubEvent } from "sub-events"; import { MultiStore } from "./MultiStore"; import { SourceGraph } from "./SourceGraph"; import { ViewConfig } from "./layout/ViewConfig"; // Connect <streamed-graph>, <sg-source>, <sg-view>, MultiStore, and ViewConfig. // Makes the (single) MultiStore and the (updated as needed) ViewConfig. // This is poorly named since it deals in both the <sg-source> elements that you // "configured" plus the set of SourceGraph objs that are actually connected to remote graphs. // sic private- this is just for documenting the interface more clearly interface IConfiguredSources { // outputs graph: MultiStore; // const- only the graph contents will change viewConfig: ViewConfig; // methods newSourceGraph: (s: SourceGraph) => void; lostSourceGraph: (s: SourceGraph) => void; viewUriChanged: (v: NamedNode) => void; // events viewConfigChanged: SubEvent<ViewConfig>; } export class ConfiguredSources implements IConfiguredSources { graph: MultiStore; viewConfig: ViewConfig; viewConfigChanged: SubEvent<ViewConfig> = new SubEvent(); private viewUri: NamedNode = new NamedNode("empty-view-config"); constructor() { this.graph = new MultiStore(); this.graph.graphChanged.subscribe(() => this.viewConfigMaybeChanged()); this.viewConfig = new ViewConfig(this.graph, this.viewUri); } private viewConfigMaybeChanged() { this.viewConfig = new ViewConfig(this.graph, this.viewUri); this.viewConfigChanged.emit(this.viewConfig); } newSourceGraph(s: SourceGraph) { this.graph.newStore(s); this.viewConfigMaybeChanged(); } lostSourceGraph(s: SourceGraph) { throw new Error("notimplemented"); this.viewConfigMaybeChanged(); } viewUriChanged(v: NamedNode) { if (v && v == this.viewUri) { return; } this.viewUri = v; this.viewConfigMaybeChanged(); } }