diff src/ConfiguredSources.ts @ 128:5a1a79f54779

big rewrite
author drewp@bigasterisk.com
date Fri, 05 May 2023 21:26:36 -0700
parents
children 9347277e8311
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ConfiguredSources.ts	Fri May 05 21:26:36 2023 -0700
@@ -0,0 +1,64 @@
+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();
+  }
+}