1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-18 01:07:38 +00:00

Changed importVariable to store its own variables (#4108)

* Changed importVariable to store its ownvariables

Before, importVariables was creating a setWidget for every single variable it would find in its tiddlers, and it would create a long-ass call tree. Now, instead, it just accumulates the variables in itself.

* Can't use Object.assign

Learned the hardway while working on tw5-relink that Object.assign
doesn't exist in IE11. Using $tw.utils.extend instead.

* Retaining setWidget transclusion flexibility

* One more test to verify mixing sets and macros
This commit is contained in:
Cameron Fischer
2020-01-30 07:53:26 -05:00
committed by GitHub
parent 151eed5c81
commit aa817f66d2
2 changed files with 72 additions and 24 deletions

View File

@@ -37,49 +37,45 @@ ImportVariablesWidget.prototype.render = function(parent,nextSibling) {
Compute the internal state of the widget
*/
ImportVariablesWidget.prototype.execute = function(tiddlerList) {
var self = this;
var widgetPointer = this;
// Get our parameters
this.filter = this.getAttribute("filter");
// Compute the filter
this.tiddlerList = tiddlerList || this.wiki.filterTiddlers(this.filter,this);
// Accumulate the <$set> widgets from each tiddler
var widgetStackStart,widgetStackEnd;
function addWidgetNode(widgetNode) {
if(widgetNode) {
if(!widgetStackStart && !widgetStackEnd) {
widgetStackStart = widgetNode;
widgetStackEnd = widgetNode;
} else {
widgetStackEnd.children = [widgetNode];
widgetStackEnd = widgetNode;
}
}
}
$tw.utils.each(this.tiddlerList,function(title) {
var parser = self.wiki.parseTiddler(title);
var parser = widgetPointer.wiki.parseTiddler(title);
if(parser) {
var parseTreeNode = parser.tree[0];
while(parseTreeNode && parseTreeNode.type === "set") {
addWidgetNode({
var node = {
type: "set",
attributes: parseTreeNode.attributes,
params: parseTreeNode.params,
isMacroDefinition: parseTreeNode.isMacroDefinition
});
};
if (parseTreeNode.isMacroDefinition) {
// Macro definitions can be folded into
// current widget instead of adding
// another link to the chain.
var widget = widgetPointer.makeChildWidget(node);
widget.computeAttributes();
widget.execute();
$tw.utils.extend(widgetPointer.variables,widget.variables);
} else {
widgetPointer.makeChildWidgets([node]);
widgetPointer = widgetPointer.children[0];
}
parseTreeNode = parseTreeNode.children && parseTreeNode.children[0];
}
}
});
// Add our own children to the end of the pile
var parseTreeNodes;
if(widgetStackStart && widgetStackEnd) {
parseTreeNodes = [widgetStackStart];
widgetStackEnd.children = this.parseTreeNode.children;
if (widgetPointer != this) {
widgetPointer.parseTreeNode.children = this.parseTreeNode.children;
} else {
parseTreeNodes = this.parseTreeNode.children;
widgetPointer.makeChildWidgets();
}
// Construct the child widgets
this.makeChildWidgets(parseTreeNodes);
};
/*