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:
parent
966684cb13
commit
7593cf1075
@ -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() {
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
@ -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
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user