Changeset - 4074dbec5c46
[Not reviewed]
default
0 4 0
drewp@bigasterisk.com - 20 months ago 2023-05-29 20:58:04
drewp@bigasterisk.com
logging
4 files changed with 36 insertions and 16 deletions:
0 comments (0 inline, 0 general)
light9/live/Effect.ts
Show inline comments
 
@@ -90,13 +90,13 @@ export class Effect {
 
      }
 
      //   log(`change: graph contains ${deviceAttr.value} ${value}`);
 

	
 
      newSettings.push({ device, deviceAttr, setting, value });
 
    }
 
    this.settings = newSettings;
 
    log(`rebuild to ${this.settings.length}`);
 
    log(`settings is rebuilt to length ${this.settings.length}`);
 
    this.settingsChanged.emit(); // maybe one emitter per dev+attr?
 
    // this.onValuesChanged();
 
  }
 

	
 
  currentValue(device: NamedNode, deviceAttr: NamedNode): ControlValue | null {
 
    for (let s of this.settings) {
light9/live/Light9AttrControl.ts
Show inline comments
 
@@ -90,23 +90,37 @@ export class Light9AttrControl extends L
 
      this.onValueProperty();
 
    }
 
  }
 

	
 
  private onValueProperty() {
 
    if (this.deviceAttrRow === null) throw new Error();
 
    if (this.effect !== null && this.graph !== undefined) {
 
      const p = this.effect.edit(this.deviceAttrRow.device, this.deviceAttrRow.uri, this.value);
 
      if (p.adds.length || p.dels.length) {
 
        log("Effect told us to graph.patch", p, "to", this.graph);
 
    if (!this.graph) {
 
      log('ignoring value change- no graph yet')
 
      return;
 
    }
 
    if (this.effect === null) {
 
      this.value = null;
 
    } else {
 
      const p = this.effect.edit(
 
        //
 
        this.deviceAttrRow.device,
 
        this.deviceAttrRow.uri,
 
        this.value
 
      );
 
      if (!p.isEmpty()) {
 
        log("Effect told us to graph.patch this:\n", p.dump());
 
        this.graph.applyAndSendPatch(p);
 
      }
 
    }
 
  }
 

	
 
  private onEffectProperty() {
 
    if (this.effect === null) throw new Error();
 
    if (this.effect === null) {
 
      log('no effect obj yet')
 
      return;
 
    }
 
    // effect will read graph changes on its own, but emit an event when it does
 
    this.effect.settingsChanged.subscribe(() => {
 
      this.effectSettingsChanged();
 
    });
 
    this.effectSettingsChanged();
 
  }
light9/web/SyncedGraph.ts
Show inline comments
 
@@ -150,25 +150,27 @@ export class SyncedGraph {
 
  applyAndSendPatch(patch: Patch) {
 
    console.time("applyAndSendPatch");
 
    if (!this.client) {
 
      log("not connected-- dropping patch");
 
      return;
 
    }
 
    if (patch.isEmpty()) throw 'should not get to this point with empty patch'
 

	
 
    this._applyPatch(patch);
 
    if (this.client) {
 
      log("sending patch:\n", patch.dump())
 
      this.client.sendPatch(patch);
 
    }
 
    console.timeEnd("applyAndSendPatch");
 
  }
 

	
 
  _applyPatch(patch: Patch) {
 
    // In most cases you want applyAndSendPatch.
 
    //
 
    // This is the only method that writes to this.graph!
 
    log("patch from server [1]");
 
    log("_applyPatch [1]\n", patch.dump());
 
    this.cachedFloatValues.clear();
 
    this.cachedUriValues.clear();
 
    patch.applyToGraph(this.graph);
 
    log("applied patch locally", patch.summary());
 
    log('dump:\n'+patch.dump());
 
    this.autoDeps.graphChanged(patch);
light9/web/patch.ts
Show inline comments
 
@@ -49,12 +49,13 @@ export class Patch {
 
        (pat.graph === null || pat.graph.equals(quad.graph))
 
      );
 
    });
 
  }
 

	
 
  isEmpty() {
 
    // sometimes returns bogus false- waiting for port to Immutable
 
    return !this.dels.length && !this.adds.length;
 
  }
 

	
 
  applyToGraph(g: N3.Store) {
 
    for (let quad of Array.from(this.dels)) {
 
      g.removeQuad(quad);
 
@@ -73,23 +74,26 @@ export class Patch {
 
    return "-" + this.dels.length + " +" + this.adds.length;
 
  }
 

	
 
  dump(): string {
 
    const lines: string[] = [];
 
    const s = (term: N3.Term): string => {
 
      if (term.termType=='Literal') return term.value;
 
      if (term.termType=='NamedNode') return term.value
 
        .replace("http://light9.bigasterisk.com/effect/","effect:")
 
        .replace("http://light9.bigasterisk.com/",":")
 
        .replace("http://www.w3.org/2000/01/rdf-schema#","rdfs:")
 
        .replace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:")
 
      if (term.termType=='BlankNode') return '_:'+term.value;
 
      if (term.termType == "Literal") return term.value;
 
      if (term.termType == "NamedNode")
 
        return term.value
 
          .replace("http://light9.bigasterisk.com/effect/", "effect:")
 
          .replace("http://light9.bigasterisk.com/", ":")
 
          .replace("http://www.w3.org/2000/01/rdf-schema#", "rdfs:")
 
          .replace("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf:");
 
      if (term.termType == "BlankNode") return "_:" + term.value;
 
      return term.id;
 
    };
 
    this.dels.forEach((d) => lines.push("- " + s(d.subject) + " " + s(d.predicate) + " " + s(d.object)));
 
    this.adds.forEach((d) => lines.push("+ " + s(d.subject) + " " + s(d.predicate) + " " + s(d.object)));
 
    const delPrefix = "- ",
 
      addPrefix = "\u200B+ "; // dels to sort before adds
 
    this.dels.forEach((d) => lines.push(delPrefix + s(d.subject) + " " + s(d.predicate) + " " + s(d.object)));
 
    this.adds.forEach((d) => lines.push(addPrefix + s(d.subject) + " " + s(d.predicate) + " " + s(d.object)));
 
    lines.sort();
 
    return lines.join("\n");
 
  }
 

	
 
  async toJsonPatch(): Promise<string> {
 
    return new Promise((res, rej) => {
0 comments (0 inline, 0 general)