Changeset - 9ca3d356b950
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 20 months ago 2023-05-29 20:24:01
drewp@bigasterisk.com
attempted rewrite of rerunInners
1 file changed with 11 insertions and 20 deletions:
0 comments (0 inline, 0 general)
light9/web/AutoDependencies.ts
Show inline comments
 
@@ -95,41 +95,32 @@ export class AutoDependencies {
 
    prn(this.handlers, "");
 
  }
 

	
 
  _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) {
 
        // wildcard on subject
 
        return true;
 
      }
 
      if (patchSubjs.has(stmt.subject.value)) {
 
  _handlerIsAffected(child: Handler, patch: Patch): boolean {
 
    // it should be correct but slow to always return true here
 
    for (let pat of child.patterns) {
 
      if (patch.matches(pat)) {
 
        return true;
 
      }
 
    }
 

	
 
    return false;
 
  }
 

	
 
  graphChanged(patch: Patch) {
 
    // SyncedGraph is telling us this patch just got applied to the graph.
 
    const subjs = allPatchSubjs(patch);
 

	
 
    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
 
        const match = this._handlerIsAffected(child, patch);
 

	
 
        if (match) {
 
          log("match", child.label, match);
 
          child.innerHandlers = []; // let all children get called again
 
        this._rerunHandler(child, patch);
 
        } else {
 
        rerunInners(child);
 
      }
 
      }
 
    };
 
    rerunInners(this.handlers);
 
  }
0 comments (0 inline, 0 general)