Mercurial > code > home > repos > light9
changeset 2273:4074dbec5c46
logging
author | drewp@bigasterisk.com |
---|---|
date | Mon, 29 May 2023 13:58:04 -0700 |
parents | 9ca3d356b950 |
children | df9a6c457587 |
files | light9/live/Effect.ts light9/live/Light9AttrControl.ts light9/web/SyncedGraph.ts light9/web/patch.ts |
diffstat | 4 files changed, 36 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/live/Effect.ts Mon May 29 13:24:01 2023 -0700 +++ b/light9/live/Effect.ts Mon May 29 13:58:04 2023 -0700 @@ -93,7 +93,7 @@ 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(); }
--- a/light9/live/Light9AttrControl.ts Mon May 29 13:24:01 2023 -0700 +++ b/light9/live/Light9AttrControl.ts Mon May 29 13:58:04 2023 -0700 @@ -93,17 +93,31 @@ 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();
--- a/light9/web/SyncedGraph.ts Mon May 29 13:24:01 2023 -0700 +++ b/light9/web/SyncedGraph.ts Mon May 29 13:58:04 2023 -0700 @@ -153,9 +153,11 @@ 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"); @@ -165,7 +167,7 @@ // 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);
--- a/light9/web/patch.ts Mon May 29 13:24:01 2023 -0700 +++ b/light9/web/patch.ts Mon May 29 13:58:04 2023 -0700 @@ -52,6 +52,7 @@ } isEmpty() { + // sometimes returns bogus false- waiting for port to Immutable return !this.dels.length && !this.adds.length; } @@ -76,17 +77,20 @@ 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"); }