1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Cleaning up the widget refresh mechanism

This commit is contained in:
Jeremy Ruston 2012-12-14 19:31:37 +00:00
parent 966684cb13
commit 7593cf1075
6 changed files with 7 additions and 39 deletions

View File

@ -20,19 +20,6 @@ var WidgetRenderer = function(renderTree,renderContext,parseTreeNode) {
this.renderTree = renderTree; this.renderTree = renderTree;
this.renderContext = renderContext; this.renderContext = renderContext;
this.parseTreeNode = parseTreeNode; 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 // Compute our attributes
this.attributes = {}; this.attributes = {};
this.computeAttributes(); this.computeAttributes();
@ -106,23 +93,12 @@ WidgetRenderer.prototype.renderInDom = function() {
}; };
WidgetRenderer.prototype.refreshInDom = function(changedTiddlers) { 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 // Update our attributes
var changedAttributes = this.computeAttributes(); var changedAttributes = this.computeAttributes();
// Refresh the widget // Refresh the widget
if(this.widget && this.widget.refreshInDom) { if(this.widget && this.widget.refreshInDom) {
this.widget.refreshInDom(changedAttributes,changedTiddlers); this.widget.refreshInDom(changedAttributes,changedTiddlers);
return;
} }
}
// 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() { WidgetRenderer.prototype.getContextTiddlerTitle = function() {

View File

@ -99,7 +99,7 @@ exports.handleMouseOverOrOutEvent = function(event) {
exports.refreshInDom = function(changedAttributes,changedTiddlers) { exports.refreshInDom = function(changedAttributes,changedTiddlers) {
// Set the class for missing tiddlers // 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)); $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 // Check if any of our attributes have changed, or if a tiddler we're interested in has changed

View File

@ -33,8 +33,6 @@ exports.init = function(renderer) {
}; };
exports.generateChildNodes = function() { exports.generateChildNodes = function() {
// We'll manage our own dependencies
this.renderer.dependencies = undefined;
// Get our attributes // Get our attributes
this.itemClass = this.renderer.getAttribute("itemClass"); this.itemClass = this.renderer.getAttribute("itemClass");
this.template = this.renderer.getAttribute("template"); this.template = this.renderer.getAttribute("template");

View File

@ -22,8 +22,6 @@ exports.init = function(renderer) {
}; };
exports.generateChildNodes = function() { exports.generateChildNodes = function() {
// We'll manage our own dependencies
this.renderer.dependencies = undefined;
// Get our parameters // Get our parameters
this.storyTitle = this.renderer.getAttribute("story"); this.storyTitle = this.renderer.getAttribute("story");
this.historyTitle = this.renderer.getAttribute("history"); this.historyTitle = this.renderer.getAttribute("history");

View File

@ -57,8 +57,6 @@ exports.init = function(renderer) {
exports.generateChildNodes = function() { exports.generateChildNodes = function() {
var tr, templateParseTree, templateTiddler; var tr, templateParseTree, templateTiddler;
// We'll manage our own dependencies
this.renderer.dependencies = undefined;
// Get the render target details // Get the render target details
this.targetTitle = this.renderer.getAttribute("target",this.renderer.getContextTiddlerTitle()); this.targetTitle = this.renderer.getAttribute("target",this.renderer.getContextTiddlerTitle());
// Get the render tree for the template // Get the render tree for the template
@ -102,7 +100,7 @@ exports.generateChildNodes = function() {
exports.refreshInDom = function(changedAttributes,changedTiddlers) { exports.refreshInDom = function(changedAttributes,changedTiddlers) {
// Set the class for missing tiddlers // 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)); $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 // Check if any of our attributes have changed, or if a tiddler we're interested in has changed

View File

@ -55,8 +55,6 @@ exports.init = function(renderer) {
}; };
exports.generateChildNodes = function() { exports.generateChildNodes = function() {
// We'll manage our own dependencies
this.renderer.dependencies = undefined;
// Get parameters from our attributes // Get parameters from our attributes
this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.getContextTiddlerTitle()); this.tiddlerTitle = this.renderer.getAttribute("tiddler",this.renderer.getContextTiddlerTitle());
this.fieldName = this.renderer.getAttribute("field","text"); this.fieldName = this.renderer.getAttribute("field","text");