mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-27 09:24:45 +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:
parent
1deb23b82d
commit
a7b905cf88
@ -288,12 +288,12 @@ MacroNode.prototype.refresh = function(changes) {
|
|||||||
MacroNode.prototype.refreshInDom = function(changes) {
|
MacroNode.prototype.refreshInDom = function(changes) {
|
||||||
var t,
|
var t,
|
||||||
self = this;
|
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
|
// Ask the macro to rerender itself if it can
|
||||||
if(this.macro.refreshInDom) {
|
if(this.macro.refreshInDom) {
|
||||||
this.macro.refreshInDom.call(this,changes);
|
this.macro.refreshInDom.call(this,changes);
|
||||||
} else {
|
} 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
|
// Manually reexecute and rerender this macro
|
||||||
while(this.domNode.hasChildNodes()) {
|
while(this.domNode.hasChildNodes()) {
|
||||||
this.domNode.removeChild(this.domNode.firstChild);
|
this.domNode.removeChild(this.domNode.firstChild);
|
||||||
@ -302,13 +302,13 @@ MacroNode.prototype.refreshInDom = function(changes) {
|
|||||||
for(t=0; t<this.content.length; t++) {
|
for(t=0; t<this.content.length; t++) {
|
||||||
this.content[t].renderInDom(this.domNode);
|
this.content[t].renderInDom(this.domNode);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Refresh any children
|
// Refresh any children
|
||||||
for(t=0; t<this.content.length; t++) {
|
for(t=0; t<this.content.length; t++) {
|
||||||
this.content[t].refreshInDom(changes);
|
this.content[t].refreshInDom(changes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MacroNode.prototype.handleEvent = function(event) {
|
MacroNode.prototype.handleEvent = function(event) {
|
||||||
|
@ -91,6 +91,7 @@ exports.macro = {
|
|||||||
return [editor];
|
return [editor];
|
||||||
},
|
},
|
||||||
refreshInDom: function(changes) {
|
refreshInDom: function(changes) {
|
||||||
|
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
|
||||||
// Don't refresh the editor if it contains the caret or selection
|
// Don't refresh the editor if it contains the caret or selection
|
||||||
if(!window.getSelection().containsNode(this.domNode, true)) {
|
if(!window.getSelection().containsNode(this.domNode, true)) {
|
||||||
// Remove the previous content
|
// Remove the previous content
|
||||||
@ -105,6 +106,7 @@ exports.macro = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -145,6 +145,7 @@ exports.macro = {
|
|||||||
return [content];
|
return [content];
|
||||||
},
|
},
|
||||||
refreshInDom: function(changes) {
|
refreshInDom: function(changes) {
|
||||||
|
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
|
||||||
var needContentRefresh = true; // Avoid refreshing the content nodes if we don't need to
|
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 the state tiddler has changed then reset the open state
|
||||||
if(this.hasParameter("state") && changes.hasOwnProperty(this.params.state)) {
|
if(this.hasParameter("state") && changes.hasOwnProperty(this.params.state)) {
|
||||||
@ -169,6 +170,7 @@ exports.macro = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -97,6 +97,7 @@ exports.macro = {
|
|||||||
},
|
},
|
||||||
refreshInDom: function(changes) {
|
refreshInDom: function(changes) {
|
||||||
/*jslint browser: true */
|
/*jslint browser: true */
|
||||||
|
if(this.dependencies.hasChanged(changes,this.tiddlerTitle)) {
|
||||||
// Get the tiddlers we're supposed to be displaying
|
// Get the tiddlers we're supposed to be displaying
|
||||||
var self = this,
|
var self = this,
|
||||||
story = JSON.parse(this.store.getTiddlerText(this.params.story)),
|
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},
|
{target: story.tiddlers[t].title,template: story.tiddlers[t].template},
|
||||||
null,
|
null,
|
||||||
this.store);
|
this.store);
|
||||||
m.execute(this.parents,story.tiddlers[t].title);
|
m.execute(this.parents,this.tiddlerTitle);
|
||||||
m.renderInDom(this.domNode,this.domNode.childNodes[t]);
|
m.renderInDom(this.domNode,this.domNode.childNodes[t]);
|
||||||
this.content.splice(t,0,m);
|
this.content.splice(t,0,m);
|
||||||
} else {
|
} else {
|
||||||
@ -149,6 +150,11 @@ exports.macro = {
|
|||||||
}
|
}
|
||||||
this.content.splice(story.tiddlers.length,this.content.length-story.tiddlers.length);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user