Changeset - 0617b6006ec4
[Not reviewed]
default
0 2 0
drewp@bigasterisk.com - 3 years ago 2022-05-29 09:53:46
drewp@bigasterisk.com
ts cleanup
2 files changed with 8 insertions and 8 deletions:
0 comments (0 inline, 0 general)
light9/web/AutoDependencies.ts
Show inline comments
 
@@ -34,34 +34,34 @@ export class AutoDependencies {
 
    this.handlers = new Handler(null, "root");
 
    this.handlerStack = [this.handlers]; // currently running
 
  }
 

	
 
  runHandler(func: HandlerFunc, label: string) {
 
    // what if we have this func already? duplicate is safe?
 
    if (label == null) {
 
      throw new Error("missing label");
 
    }
 

	
 
    const h = new Handler(func, label);
 
    const tailChildren = this.handlerStack[this.handlerStack.length - 1].innerHandlers;
 
    const matchingLabel = filter(tailChildren, (c: { label: any }) => c.label === label).length;
 
    const matchingLabel = filter(tailChildren, (c: Handler) => c.label === label).length;
 
    // ohno, something depends on some handlers getting run twice :(
 
    if (matchingLabel < 2) {
 
      tailChildren.push(h);
 
    }
 
    //console.time("handler #{label}") 
 
    //console.time("handler #{label}")
 
    // todo: this may fire 1-2 times before the
 
    // graph is initially loaded, which is a waste. Try deferring it if we
 
    // haven't gotten the graph yet.
 
    return this._rerunHandler(h, undefined);
 
    this._rerunHandler(h, undefined);
 
  }
 
  //console.timeEnd("handler #{label}")
 
  //@_logHandlerTree()
 
  _rerunHandler(handler: Handler, patch?: Patch) {
 
    handler.patterns = [];
 
    this.handlerStack.push(handler);
 
    try {
 
      if (handler.func === null) {
 
        throw new Error("tried to rerun root");
 
      }
 
      handler.func(patch);
 
    } catch (e) {
 
@@ -73,27 +73,27 @@ export class AutoDependencies {
 
      this.handlerStack.pop();
 
    }
 
  }
 
  // handler might have no watches, in which case we could forget about it
 
  _logHandlerTree() {
 
    log("handler tree:");
 
    var prn = function (h: Handler, depth: number) {
 
      let indent = "";
 
      for (let i = 0; i < depth; i++) {
 
        indent += "  ";
 
      }
 
      log(`${indent} \"${h.label}\" ${h.patterns.length} pats`);
 
      return Array.from(h.innerHandlers).map((c: any) => prn(c, depth + 1));
 
      Array.from(h.innerHandlers).map((c: any) => prn(c, depth + 1));
 
    };
 
    return prn(this.handlers, 0);
 
    prn(this.handlers, 0);
 
  }
 

	
 
  _handlerIsAffected(child: Handler, patchSubjs: Set<string>) {
 
    if (patchSubjs === null) {
 
      return true;
 
    }
 
    if (!child.patterns.length) {
 
      return false;
 
    }
 

	
 
    for (let stmt of Array.from(child.patterns)) {
 
      if (stmt.subject === null) {
 
@@ -114,24 +114,24 @@ export class AutoDependencies {
 

	
 
    var rerunInners = (cur: Handler) => {
 
      const toRun = cur.innerHandlers.slice();
 
      for (let child of Array.from(toRun)) {
 
        //match = @_handlerIsAffected(child, subjs)
 
        //continue if not match
 
        //log('match', child.label, match)
 
        //child.innerHandlers = [] # let all children get called again
 
        this._rerunHandler(child, patch);
 
        rerunInners(child);
 
      }
 
    };
 
    return rerunInners(this.handlers);
 
    rerunInners(this.handlers);
 
  }
 

	
 
  askedFor(s: Quad_Subject | null, p: Quad_Predicate | null, o: Quad_Object | null, g: Quad_Graph | null) {
 
    // SyncedGraph is telling us someone did a query that depended on
 
    // quads in the given pattern.
 
    const current = this.handlerStack[this.handlerStack.length - 1];
 
    if (current != null && current !== this.handlers) {
 
      return current.patterns.push({ subject: s, predicate: p, object: o, graph: g } as QuadPattern);
 
      current.patterns.push({ subject: s, predicate: p, object: o, graph: g } as QuadPattern);
 
    }
 
  }
 
}
light9/web/SyncedGraph.ts
Show inline comments
 
@@ -209,25 +209,25 @@ export class SyncedGraph {
 

	
 
  patchObject(s: N3.NamedNode, p: N3.NamedNode, newObject: N3.Quad_Object, g: N3.NamedNode) {
 
    this.applyAndSendPatch(this.getObjectPatch(s, p, newObject, g));
 
  }
 

	
 
  clearObjects(s: N3.NamedNode, p: N3.NamedNode, g: N3.NamedNode) {
 
    return this.applyAndSendPatch({
 
      dels: this.graph.getQuads(s, p, null, g),
 
      adds: [],
 
    });
 
  }
 

	
 
  runHandler(func: HandlerFunc, label: string) {
 
  public runHandler(func: HandlerFunc, label: string) {
 
    // runs your func once, tracking graph calls. if a future patch
 
    // matches what you queried, we runHandler your func again (and
 
    // forget your queries from the first time).
 

	
 
    // helps with memleak? not sure yet. The point was if two matching
 
    // labels get puushed on, we should run only one. So maybe
 
    // appending a serial number is backwards.
 
    if (!this.serial) {
 
      this.serial = 1;
 
    }
 
    this.serial += 1;
 
    //label = label + @serial
0 comments (0 inline, 0 general)