changeset 2102:9c2e1b5c16e9

speed: don't redo uri string replace all the time
author drewp@bigasterisk.com
date Tue, 31 May 2022 23:39:58 -0700
parents 4248f40ddcae
children 1ef921880e37
files light9/web/live/Effect.ts
diffstat 1 files changed, 6 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/light9/web/live/Effect.ts	Tue May 31 23:38:40 2022 -0700
+++ b/light9/web/live/Effect.ts	Tue May 31 23:39:58 2022 -0700
@@ -26,24 +26,20 @@
 // effect settings data; r/w sync with the graph
 export class Effect {
   private settings: Array<{ device: NamedNode; deviceAttr: NamedNode; setting: NamedNode; value: ControlValue }> = [];
-
+  private ctxForEffect: NamedNode
   constructor(
     public graph: SyncedGraph,
     public uri: NamedNode,
     // called if the graph changes our values and not when the caller uses edit()
     private onValuesChanged: (values: void) => void
   ) {
+    this.ctxForEffect = this.graph.Uri(this.uri.value.replace("light9.bigasterisk.com/effect", "light9.bigasterisk.com/show/dance2019/effect"));
     graph.runHandler(this.rebuildSettingsFromGraph.bind(this), `effect sync ${uri.value}`);
   }
 
-  private ctxForEffect(): NamedNode {
-    return this.graph.Uri(this.uri.value.replace("light9.bigasterisk.com/effect", "light9.bigasterisk.com/show/dance2019/effect"));
-  }
-
   addNewEffectToGraph() {
     const U = this.graph.U();
-    const ctx = this.ctxForEffect();
-    const quad = (s: Quad_Subject, p: Quad_Predicate, o: Quad_Object) => this.graph.Quad(s, p, o, ctx);
+    const quad = (s: Quad_Subject, p: Quad_Predicate, o: Quad_Object) => this.graph.Quad(s, p, o, this.ctxForEffect);
 
     const addQuads = [
       quad(this.uri, U("rdf:type"), U(":Effect")),
@@ -149,8 +145,7 @@
   _addEffectSetting(device: NamedNode, deviceAttr: NamedNode, value: ControlValue): Patch {
     log("  _addEffectSetting", deviceAttr.value, value);
     const U = (x: string) => this.graph.Uri(x);
-    const ctx = this.ctxForEffect();
-    const quad = (s: Quad_Subject, p: Quad_Predicate, o: Quad_Object) => this.graph.Quad(s, p, o, ctx);
+    const quad = (s: Quad_Subject, p: Quad_Predicate, o: Quad_Object) => this.graph.Quad(s, p, o, this.ctxForEffect);
     if (!this.uri) throw new Error("effect unset");
     const setting = this.graph.nextNumberedResource(this.uri.value + "_set");
 
@@ -172,14 +167,14 @@
       effectSetting, //
       valuePred(this.graph, deviceAttr),
       this._nodeForValue(value),
-      this.ctxForEffect()
+      this.ctxForEffect
     );
   }
 
   _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())];
+    const toDel = [this.graph.Quad(this.uri, U(":setting"), effectSetting, this.ctxForEffect)];
     for (let q of this.graph.subjectStatements(effectSetting)) {
       toDel.push(q);
     }