changeset 2259:7d26fa1ed4e7

renames and comments (mostly)
author drewp@bigasterisk.com
date Mon, 29 May 2023 11:44:22 -0700
parents d3ecee9bfab5
children 4b04bf5c4a85
files light9/live/Effect.ts light9/live/Light9DeviceSettings.ts light9/web/AutoDependencies.ts light9/web/SyncedGraph.ts
diffstat 4 files changed, 37 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/light9/live/Effect.ts	Mon May 29 11:41:11 2023 -0700
+++ b/light9/live/Effect.ts	Mon May 29 11:44:22 2023 -0700
@@ -145,7 +145,7 @@
     return value != null && value !== 0 && value !== "#000000";
   }
 
-  _addEffectSetting(device: NamedNode, deviceAttr: NamedNode, value: ControlValue): Patch {
+  private addEffectSetting(device: NamedNode, deviceAttr: NamedNode, value: ControlValue): Patch {
     log("  _addEffectSetting", deviceAttr.value, value);
     const U = (x: string) => this.graph.Uri(x);
     const quad = (s: Quad_Subject, p: Quad_Predicate, o: Quad_Object) => this.graph.Quad(s, p, o, this.ctxForEffect);
@@ -171,12 +171,12 @@
     return this.graph.getObjectPatch(
       effectSetting, //
       valuePred(this.graph, deviceAttr),
-      this._nodeForValue(value),
+      this.nodeForValue(value),
       this.ctxForEffect
     );
   }
 
-  _removeEffectSetting(effectSetting: NamedNode): Patch {
+  private removeEffectSetting(effectSetting: NamedNode): Patch {
     const U = (x: string) => this.graph.Uri(x);
     log("  _removeEffectSetting", effectSetting.value);
     const toDel = [this.graph.Quad(this.uri, U(":setting"), effectSetting, this.ctxForEffect)];
@@ -186,7 +186,7 @@
     return new Patch(toDel, []);
   }
 
-  _nodeForValue(value: ControlValue): NamedNode | Literal {
+  private nodeForValue(value: ControlValue): NamedNode | Literal {
     if (value === null) {
       throw new Error("no value");
     }
--- a/light9/live/Light9DeviceSettings.ts	Mon May 29 11:41:11 2023 -0700
+++ b/light9/live/Light9DeviceSettings.ts	Mon May 29 11:44:22 2023 -0700
@@ -73,7 +73,7 @@
 
     getTopGraph().then((g) => {
       this.graph = g;
-      this.graph.runHandler(this.findDevices.bind(this), "findDevices");
+      this.graph.runHandler(this.compile.bind(this), "findDevices");
       this.setEffectFromUrl();
     });
   }
@@ -98,7 +98,7 @@
 
   // Note that this doesn't fetch setting values, so it only should get rerun
   // upon (rarer) changes to the devices etc. todo: make that be true
-  findDevices(patch?: Patch) {
+  private compile(patch?: Patch) {
     const U = this.graph.U();
     // if (patch && !patchContainsPreds(patch, [U("rdf:type")])) {
     //   return;
--- a/light9/web/AutoDependencies.ts	Mon May 29 11:41:11 2023 -0700
+++ b/light9/web/AutoDependencies.ts	Mon May 29 11:44:22 2023 -0700
@@ -74,7 +74,7 @@
     }
   }
   // handler might have no watches, in which case we could forget about it
-  _logHandlerTree() {
+  logHandlerTree() {
     log("handler tree:");
     var prn = function (h: Handler, depth: number) {
       let indent = "";
--- a/light9/web/SyncedGraph.ts	Mon May 29 11:41:11 2023 -0700
+++ b/light9/web/SyncedGraph.ts	Mon May 29 11:44:22 2023 -0700
@@ -5,19 +5,20 @@
 import { AutoDependencies, HandlerFunc } from "./AutoDependencies";
 import { Patch, patchToDeleteEntireGraph } from "./patch";
 import { RdfDbClient } from "./rdfdbclient";
+
 const log = debug("graph");
 
 const RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
 
 export class SyncedGraph {
-  private _autoDeps: AutoDependencies;
-  private _client: RdfDbClient;
+  private autoDeps: AutoDependencies;
+  private client: RdfDbClient;
   private graph: N3.Store;
-  cachedFloatValues: any;
-  cachedUriValues: any;
+  private cachedFloatValues: Map<string, number> = new Map();
+  private cachedUriValues: Map<string, N3.NamedNode> = new Map();
   private prefixFuncs: (prefix: string) => N3.PrefixedToIri;
-  serial: any;
-  _nextNumber: any;
+  private serial: any;
+  private nextNumber: any;
   // Main graph object for a browser to use. Consider using RdfdbSyncedGraph element to create & own
   // one of these. Syncs both ways with rdfdb. Meant to hide the choice of RDF lib, so we can change it
   // later.
@@ -26,23 +27,24 @@
   // it can fire subscriptions.
 
   constructor(
-    // url is the /syncedGraph path of an rdfdb server.
-    public url: any,
+    // The /syncedGraph path of an rdfdb server.
+    patchSenderUrl: string,
     // prefixes can be used in Uri(curie) calls. This mapping may grow during loadTrig calls.
     public prefixes: Map<string, string>,
-    private setStatus: any,
     // called if we clear the graph
     private clearCb: any
+    private setStatus: (status: string) => void
   ) {
     this.prefixFuncs = this.rebuildPrefixFuncs(prefixes);
     this.graph = new N3.Store();
-    this._autoDeps = new AutoDependencies();
+    this.autoDeps = new AutoDependencies(this);
     this.clearGraph();
 
-    this._client = new RdfDbClient(this.url, this._clearGraphOnNewConnection.bind(this), this._applyPatch.bind(this), this.setStatus);
+    this.client = new RdfDbClient(patchSenderUrl, this._clearGraphOnNewConnection.bind(this), this._applyPatch.bind(this), this.setStatus);
   }
 
   clearGraph() {
+    // must not try send a patch to the server!
     // just deletes the statements; watchers are unaffected.
     this.cachedFloatValues = new Map(); // s + '|' + p -> number
     this.cachedUriValues = new Map(); // s + '|' + p -> Uri
@@ -54,7 +56,8 @@
   }
 
   _clearGraphOnNewConnection() {
-    // must not send a patch to the server!
+    // must not try send a patch to the server
+
     log("clearGraphOnNewConnection");
     this.clearGraph();
     log("clearGraphOnNewConnection done");
@@ -140,14 +143,14 @@
 
   applyAndSendPatch(patch: Patch) {
     console.time("applyAndSendPatch");
-    if (!this._client) {
+    if (!this.client) {
       log("not connected-- dropping patch");
       return;
     }
 
     this._applyPatch(patch);
-    if (this._client) {
-      this._client.sendPatch(patch);
+    if (this.client) {
+      this.client.sendPatch(patch);
     }
     console.timeEnd("applyAndSendPatch");
   }
@@ -193,11 +196,11 @@
     this.serial += 1;
     //label = label + @serial
 
-    this._autoDeps.runHandler(func, label);
+    this.autoDeps.runHandler(func, label);
   }
 
   _singleValue(s: Quad_Subject, p: Quad_Predicate) {
-    this._autoDeps.askedFor(s, p, null, null);
+    this.autoDeps.askedFor(s, p, null, null);
     const quads = this.graph.getQuads(s, p, null, null);
     const objs = new Set(Array.from(quads).map((q: Quad) => q.object));
 
@@ -260,19 +263,19 @@
   }
 
   objects(s: any, p: any): Quad_Object[] {
-    this._autoDeps.askedFor(s, p, null, null);
+    this.autoDeps.askedFor(s, p, null, null);
     const quads = this.graph.getQuads(s, p, null, null);
     return Array.from(quads).map((q: { object: any }) => q.object);
   }
 
   subjects(p: any, o: any): Quad_Subject[] {
-    this._autoDeps.askedFor(null, p, o, null);
+    this.autoDeps.askedFor(null, p, o, null);
     const quads = this.graph.getQuads(null, p, o, null);
     return Array.from(quads).map((q: { subject: any }) => q.subject);
   }
 
   subjectStatements(s: Quad_Subject): Quad[] {
-    this._autoDeps.askedFor(s, null, null, null);
+    this.autoDeps.askedFor(s, null, null, null);
     const quads = this.graph.getQuads(s, null, null, null);
     return quads;
   }
@@ -285,7 +288,7 @@
         break;
       }
 
-      this._autoDeps.askedFor(current, null, null, null); // a little loose
+      this.autoDeps.askedFor(current, null, null, null); // a little loose
 
       const firsts = this.graph.getQuads(current, RDF + "first", null, null);
       const rests = this.graph.getQuads(current, RDF + "rest", null, null);
@@ -304,7 +307,7 @@
   }
 
   contains(s: any, p: any, o: any): boolean {
-    this._autoDeps.askedFor(s, p, o, null);
+    this.autoDeps.askedFor(s, p, o, null);
     // Sure this is a nice warning to remind me to rewrite, but the graph.size call itself was taking 80% of the time in here
     // log("contains calling getQuads when graph has ", this.graph.size);
     return this.graph.getQuads(s, p, o, null).length > 0;
@@ -320,10 +323,10 @@
     const results = [];
 
     // @contains is really slow.
-    if (this._nextNumber == null) {
-      this._nextNumber = new Map();
+    if (this.nextNumber == null) {
+      this.nextNumber = new Map();
     }
-    let start = this._nextNumber.get(base);
+    let start = this.nextNumber.get(base);
     if (start === undefined) {
       start = 0;
     }
@@ -333,7 +336,7 @@
       if (!this.contains(uri, null, null)) {
         results.push(uri);
         log("nextNumberedResources", `picked ${uri}`);
-        this._nextNumber.set(base, serial + 1);
+        this.nextNumber.set(base, serial + 1);
         if (results.length >= howMany) {
           return results;
         }
@@ -347,7 +350,7 @@
   }
 
   contextsWithPattern(s: any, p: any, o: any) {
-    this._autoDeps.askedFor(s, p, o, null);
+    this.autoDeps.askedFor(s, p, o, null);
     const ctxs = [];
     for (let q of Array.from(this.graph.getQuads(s, p, o, null))) {
       ctxs.push(q.graph);