From 7593cf107516a2ca1a549612e236ca9c86623f41 Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Fri, 14 Dec 2012 19:31:37 +0000 Subject: [PATCH] Cleaning up the widget refresh mechanism --- core/modules/rendertree/renderers/widget.js | 34 +++------------------ core/modules/widgets/link.js | 2 +- core/modules/widgets/list/list.js | 2 -- core/modules/widgets/navigator.js | 2 -- core/modules/widgets/transclude.js | 4 +-- core/modules/widgets/view/view.js | 2 -- 6 files changed, 7 insertions(+), 39 deletions(-) diff --git a/core/modules/rendertree/renderers/widget.js b/core/modules/rendertree/renderers/widget.js index 54f87a97c..0ae2c7979 100644 --- a/core/modules/rendertree/renderers/widget.js +++ b/core/modules/rendertree/renderers/widget.js @@ -20,19 +20,6 @@ var WidgetRenderer = function(renderTree,renderContext,parseTreeNode) { this.renderTree = renderTree; this.renderContext = renderContext; this.parseTreeNode = parseTreeNode; - // Compute the default dependencies - this.dependencies = {}; - var self = this; - $tw.utils.each(this.parseTreeNode.attributes,function(attribute,name) { - if(attribute.type === "indirect") { - var tr = self.renderTree.wiki.parseTextReference(attribute.textReference); - if(tr.title) { - self.dependencies[tr.title] = true; - } else { - self.dependencies[renderContext.tiddlerTitle] = true; - } - } - }); // Compute our attributes this.attributes = {}; this.computeAttributes(); @@ -106,23 +93,12 @@ WidgetRenderer.prototype.renderInDom = function() { }; WidgetRenderer.prototype.refreshInDom = function(changedTiddlers) { - // Refresh if the widget cleared the depencies hashmap to indicate that it should always be refreshed, or if any of our dependencies have changed - if(!this.dependencies || $tw.utils.checkDependencies(this.dependencies,changedTiddlers)) { - // Update our attributes - var changedAttributes = this.computeAttributes(); - // Refresh the widget - if(this.widget && this.widget.refreshInDom) { - this.widget.refreshInDom(changedAttributes,changedTiddlers); - return; - } + // Update our attributes + var changedAttributes = this.computeAttributes(); + // Refresh the widget + if(this.widget && this.widget.refreshInDom) { + this.widget.refreshInDom(changedAttributes,changedTiddlers); } - // If the widget itself didn't need refreshing, just refresh any child nodes - var self = this; - $tw.utils.each(this.children,function(node,index) { - if(node.refreshInDom) { - node.refreshInDom(changedTiddlers); - } - }); }; WidgetRenderer.prototype.getContextTiddlerTitle = function() { diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index ea5fa4bbe..470aad362 100644 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -99,7 +99,7 @@ exports.handleMouseOverOrOutEvent = function(event) { exports.refreshInDom = function(changedAttributes,changedTiddlers) { // Set the class for missing tiddlers - if(this.targetTitle) { + if(this.targetTitle && changedTiddlers[this.targetTitle]) { $tw.utils.toggleClass(this.children[0].domNode,"tw-tiddler-missing",!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle)); } // Check if any of our attributes have changed, or if a tiddler we're interested in has changed diff --git a/core/modules/widgets/list/list.js b/core/modules/widgets/list/list.js index 7545d2790..dd9c422e0 100644 --- a/core/modules/widgets/list/list.js +++ b/core/modules/widgets/list/list.js @@ -33,8 +33,6 @@ exports.init = function(renderer) { }; exports.generateChildNodes = function() { - // We'll manage our own dependencies - this.renderer.dependencies = undefined; // Get our attributes this.itemClass = this.renderer.getAttribute("itemClass"); this.template = this.renderer.getAttribute("template"); diff --git a/core/modules/widgets/navigator.js b/core/modules/widgets/navigator.js index cb86c14ab..d92e5d4b3 100644 --- a/core/modules/widgets/navigator.js +++ b/core/modules/widgets/navigator.js @@ -22,8 +22,6 @@ exports.init = function(renderer) { }; exports.generateChildNodes = function() { - // We'll manage our own dependencies - this.renderer.dependencies = undefined; // Get our parameters this.storyTitle = this.renderer.getAttribute("story"); this.historyTitle = this.renderer.getAttribute("history"); diff --git a/core/modules/widgets/transclude.js b/core/modules/widgets/transclude.js index ac5001a48..0aac98bdb 100644 --- a/core/modules/widgets/transclude.js +++ b/core/modules/widgets/transclude.js @@ -57,8 +57,6 @@ exports.init = function(renderer) { exports.generateChildNodes = function() { var tr, templateParseTree, templateTiddler; - // We'll manage our own dependencies - this.renderer.dependencies = undefined; // Get the render target details this.targetTitle = this.renderer.getAttribute("target",this.renderer.getContextTiddlerTitle()); // Get the render tree for the template @@ -102,7 +100,7 @@ exports.generateChildNodes = function() { exports.refreshInDom = function(changedAttributes,changedTiddlers) { // Set the class for missing tiddlers - if(this.targetTitle) { + if(this.targetTitle && changedTiddlers[this.targetTitle]) { $tw.utils.toggleClass(this.children[0].domNode,"tw-tiddler-missing",!this.renderer.renderTree.wiki.tiddlerExists(this.targetTitle)); } // Check if any of our attributes have changed, or if a tiddler we're interested in has changed diff --git a/core/modules/widgets/view/view.js b/core/modules/widgets/view/view.js index 198ba794e..bee8fa095 100644 --- a/core/modules/widgets/view/view.js +++ b/core/modules/widgets/view/view.js @@ -55,8 +55,6 @@ exports.init = function(renderer) { }; exports.generateChildNodes = function() { - // We'll manage our own dependencies - this.renderer.dependencies = undefined; // Get parameters from our attributes this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.getContextTiddlerTitle()); this.fieldName = this.renderer.getAttribute("field","text");