Changeset - 9c5e62615a63
[Not reviewed]
default
0 1 0
Drew Perttula - 8 years ago 2017-06-10 09:14:01
drewp@bigasterisk.com
don't let handlers pile up (workaround)
Ignore-this: c99eb0cce187fe7a49ba163431503680
1 file changed with 16 insertions and 3 deletions:
0 comments (0 inline, 0 general)
light9/web/graph.coffee
Show inline comments
 
@@ -72,13 +72,17 @@ class AutoDependencies
 
    # what if we have this func already? duplicate is safe?
 

	
 
    if not label?
 
      throw new Error("missing label")
 

	
 
    h = new Handler(func, label)
 
    @handlerStack[@handlerStack.length - 1].innerHandlers.push(h)
 
    tailChildren = @handlerStack[@handlerStack.length - 1].innerHandlers
 
    matchingLabel = _.filter(tailChildren, ((c) -> c.label == label)).length
 
    # ohno, something depends on some handlers getting run twice :(
 
    if matchingLabel < 2
 
      tailChildren.push(h)
 
    console.time("handler #{label}")
 
    @_rerunHandler(h, null)
 
    console.timeEnd("handler #{label}")
 
    
 
  _rerunHandler: (handler, patch) ->
 
    handler.patterns = []
 
@@ -90,16 +94,26 @@ class AutoDependencies
 
      # assuming here it didn't get to do all its queries, we could
 
      # add a *,*,*,* handler to call for sure the next time?
 
    finally
 
      #log('done. got: ', handler.patterns)
 
      @handlerStack.pop()
 
    # handler might have no watches, in which case we could forget about it
 

	
 
  _logHandlerTree: ->
 
    log('handler tree:')
 
    prn = (h, depth) ->
 
      indent = ''
 
      for i in [0...depth]
 
        indent += '  '
 
      log(indent + h.label)
 
      for c in h.innerHandlers
 
        prn(c, depth + 1)
 
    prn(@handlers, 0)
 
    
 
  graphChanged: (patch) ->
 
    # SyncedGraph is telling us this patch just got applied to the graph.
 

	
 
    rerunInners = (cur) =>
 
      toRun = cur.innerHandlers.slice()
 
      for child in toRun
 

	
 
        #child.innerHandlers = [] # let all children get called again
 
        @_rerunHandler(child, patch)
 
@@ -185,13 +199,12 @@ class window.SyncedGraph
 

	
 
    for qs in [patch.addQuads, patch.delQuads]
 
      for q in qs
 
        if not q.graph?
 
          throw new Error("corrupt patch: #{q}")
 

	
 
    log('graph: patch', patch)
 
    @_applyPatch(patch)
 
    @_client.sendPatch(patch) if @_client
 

	
 
  _applyPatch: (patch) ->
 
    # In most cases you want applyAndSendPatch.
 
    # 
0 comments (0 inline, 0 general)