1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-01-27 01:14:44 +00:00

Refactored renderer logic to call refreshInDom on macros unconditionally

This allows the macro itself to decide whether it wants to perform an
update or not
This commit is contained in:
Jeremy Ruston 2012-03-30 16:45:24 +01:00
parent 1deb23b82d
commit a7b905cf88
4 changed files with 98 additions and 88 deletions

View File

@ -288,12 +288,12 @@ MacroNode.prototype.refresh = function(changes) {
MacroNode.prototype.refreshInDom = function(changes) {
var t,
self = this;
// Check if any of the dependencies of this macro node have changed
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
// Ask the macro to rerender itself if it can
if(this.macro.refreshInDom) {
this.macro.refreshInDom.call(this,changes);
} else {
// Check if any of the dependencies of this macro node have changed
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
// Manually reexecute and rerender this macro
while(this.domNode.hasChildNodes()) {
this.domNode.removeChild(this.domNode.firstChild);
@ -302,13 +302,13 @@ MacroNode.prototype.refreshInDom = function(changes) {
for(t=0; t<this.content.length; t++) {
this.content[t].renderInDom(this.domNode);
}
}
} else {
// Refresh any children
for(t=0; t<this.content.length; t++) {
this.content[t].refreshInDom(changes);
}
}
}
};
MacroNode.prototype.handleEvent = function(event) {

View File

@ -91,6 +91,7 @@ exports.macro = {
return [editor];
},
refreshInDom: function(changes) {
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
// Don't refresh the editor if it contains the caret or selection
if(!window.getSelection().containsNode(this.domNode, true)) {
// Remove the previous content
@ -105,6 +106,7 @@ exports.macro = {
}
}
}
}
};
})();

View File

@ -145,6 +145,7 @@ exports.macro = {
return [content];
},
refreshInDom: function(changes) {
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
var needContentRefresh = true; // Avoid refreshing the content nodes if we don't need to
// If the state tiddler has changed then reset the open state
if(this.hasParameter("state") && changes.hasOwnProperty(this.params.state)) {
@ -169,6 +170,7 @@ exports.macro = {
}
}
}
}
};
})();

View File

@ -97,6 +97,7 @@ exports.macro = {
},
refreshInDom: function(changes) {
/*jslint browser: true */
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
// Get the tiddlers we're supposed to be displaying
var self = this,
story = JSON.parse(this.store.getTiddlerText(this.params.story)),
@ -123,7 +124,7 @@ exports.macro = {
{target: story.tiddlers[t].title,template: story.tiddlers[t].template},
null,
this.store);
m.execute(this.parents,story.tiddlers[t].title);
m.execute(this.parents,this.tiddlerTitle);
m.renderInDom(this.domNode,this.domNode.childNodes[t]);
this.content.splice(t,0,m);
} else {
@ -149,6 +150,11 @@ exports.macro = {
}
this.content.splice(story.tiddlers.length,this.content.length-story.tiddlers.length);
}
} else {
for(t=0; t<this.content.length; t++) {
this.content[t].refreshInDom(changes);
}
}
}
};