Mercurial > code > home > repos > light9
changeset 1647:67347c027b2a
hopefully harmmless steps towards making the handler tree right
Ignore-this: 1e7acf9e64ac8cc5250a3da3876af130
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sat, 10 Jun 2017 10:19:35 +0000 |
parents | 40bd7f24cae8 |
children | ffa3b81c6d95 |
files | light9/web/graph.coffee |
diffstat | 1 files changed, 37 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/web/graph.coffee Sat Jun 10 09:21:23 2017 +0000 +++ b/light9/web/graph.coffee Sat Jun 10 10:19:35 2017 +0000 @@ -45,6 +45,7 @@ console.time("handler #{label}") @_rerunHandler(h, null) console.timeEnd("handler #{label}") + @_logHandlerTree() _rerunHandler: (handler, patch) -> handler.patterns = [] @@ -66,18 +67,47 @@ indent = '' for i in [0...depth] indent += ' ' - log(indent + h.label) + log("#{indent} \"#{h.label}\" #{h.patterns.length} pats") for c in h.innerHandlers prn(c, depth + 1) prn(@handlers, 0) + + _allPatchSubjs: (patch) -> + + allPatchSubjs = [] + for stmt in patch.addQuads + allPatchSubjs.push(stmt.subject) + for stmt in patch.delQuads + allPatchSubjs.push(stmt.subject) + allPatchSubjs = _.uniq(allPatchSubjs) + if _.contains(allPatchSubjs, null) or allPatchSubjs.length == 0 + allPatchSubjs = null + log('allPatchSubjs', allPatchSubjs) + _handlerIsAffected: (child, allPatchSubjs) -> + if allPatchSubjs == null + return true + if not child.patterns.length + return false + + for stmt in child.patterns + if _.contains(allPatchSubjs, stmt[0]) + return true + + return false + graphChanged: (patch) -> # SyncedGraph is telling us this patch just got applied to the graph. + + allPatchSubjs = @_allPatchSubjs(patch) + rerunInners = (cur) => toRun = cur.innerHandlers.slice() for child in toRun - + match = @_handlerIsAffected(child, allPatchSubjs) + log('match', child.label, match) #child.innerHandlers = [] # let all children get called again + @_rerunHandler(child, patch) rerunInners(child) rerunInners(@handlers) @@ -155,17 +185,19 @@ [q.subject, q.predicate, q.object, q.graph] for q in @graph.find() applyAndSendPatch: (patch) -> + console.time('applyAndSendPatch') if !Array.isArray(patch.addQuads) || !Array.isArray(patch.delQuads) - throw new Error("corrupt patch: #{patch}") + throw new Error("corrupt patch: #{JSON.stringify(patch)}") for qs in [patch.addQuads, patch.delQuads] for q in qs if not q.graph? - throw new Error("corrupt patch: #{q}") + throw new Error("corrupt patch: #{JSON.stringify(q)}") @_applyPatch(patch) @_client.sendPatch(patch) if @_client - + console.timeEnd('applyAndSendPatch') + _applyPatch: (patch) -> # In most cases you want applyAndSendPatch. #