mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-07-16 08:52:51 +00:00
Refactored dependency handling
Now each class of dependency can be tracked individually
This commit is contained in:
parent
10774a724f
commit
95ab295fbb
@ -24,7 +24,7 @@ ImageRenderer.prototype.render = function(tiddler,store) {
|
|||||||
var ImageParseTree = function(type,text) {
|
var ImageParseTree = function(type,text) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.text = text;
|
this.text = text;
|
||||||
this.dependencies = [];
|
this.dependencies = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
ImageParseTree.prototype.compile = function(type) {
|
ImageParseTree.prototype.compile = function(type) {
|
||||||
|
@ -29,7 +29,7 @@ JSONRenderer.prototype.toString = function(type) {
|
|||||||
// The parse tree is degenerate
|
// The parse tree is degenerate
|
||||||
var JSONParseTree = function(tree) {
|
var JSONParseTree = function(tree) {
|
||||||
this.tree = tree;
|
this.tree = tree;
|
||||||
this.dependencies = [];
|
this.dependencies = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
JSONParseTree.prototype.compile = function(type) {
|
JSONParseTree.prototype.compile = function(type) {
|
||||||
|
@ -491,19 +491,9 @@ WikiStore.prototype.refreshDomNode = function(node,changes,renderer,tiddler) {
|
|||||||
// Is this node a macro
|
// Is this node a macro
|
||||||
} else if(macro !== null) {
|
} else if(macro !== null) {
|
||||||
// Get the render step
|
// Get the render step
|
||||||
var r = renderer.renderSteps[renderStep],
|
var r = renderer.renderSteps[renderStep];
|
||||||
hasChanged = false;
|
|
||||||
// Refresh if a dependency has changed
|
// Refresh if a dependency has changed
|
||||||
if(r.dependencies === null) {
|
if(this.hasDependencyChanged(r.dependencies,changes)) {
|
||||||
hasChanged = true;
|
|
||||||
} else {
|
|
||||||
for(var d=0; d<r.dependencies.length; d++) {
|
|
||||||
if(r.dependencies[d] in changes) {
|
|
||||||
hasChanged = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(hasChanged) {
|
|
||||||
renderer.rerender(node,changes,tiddler,this,renderStep);
|
renderer.rerender(node,changes,tiddler,this,renderStep);
|
||||||
} else {
|
} else {
|
||||||
// If no change, just refresh the children
|
// If no change, just refresh the children
|
||||||
@ -515,6 +505,27 @@ WikiStore.prototype.refreshDomNode = function(node,changes,renderer,tiddler) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Check if the specified dependencies are impacted by the specified changes
|
||||||
|
dependencies: a dependencies tree
|
||||||
|
changes: an array of titles of changed tiddlers
|
||||||
|
*/
|
||||||
|
WikiStore.prototype.hasDependencyChanged = function(dependencies,changes) {
|
||||||
|
if(dependencies.dependentAll) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for(var rel in dependencies) {
|
||||||
|
if(rel !== "dependentAll") {
|
||||||
|
for(var t in dependencies[rel]) {
|
||||||
|
if(t in changes) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
exports.WikiStore = WikiStore;
|
exports.WikiStore = WikiStore;
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -17,7 +17,7 @@ var WikiTextRenderer = require("./WikiTextRenderer.js").WikiTextRenderer,
|
|||||||
// Intialise the parse tree object
|
// Intialise the parse tree object
|
||||||
var WikiTextParseTree = function(tree,dependencies,store) {
|
var WikiTextParseTree = function(tree,dependencies,store) {
|
||||||
this.tree = tree;
|
this.tree = tree;
|
||||||
this.dependencies = dependencies; // An array of tiddler names, or null if this tiddler depends on too many to track
|
this.dependencies = dependencies;
|
||||||
this.store = store;
|
this.store = store;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ WikiTextParseTree.prototype.compile = function(type,treenode) {
|
|||||||
]);
|
]);
|
||||||
renderStep.type = "main";
|
renderStep.type = "main";
|
||||||
renderStep.step = renderStepIndex;
|
renderStep.step = renderStepIndex;
|
||||||
renderStep.dependencies = [];
|
renderStep.dependencies = {};
|
||||||
renderStep.handler = eval(parseTree.render());
|
renderStep.handler = eval(parseTree.render());
|
||||||
return renderer;
|
return renderer;
|
||||||
};
|
};
|
||||||
@ -316,12 +316,25 @@ WikiTextParseTree.prototype.toString = function(type) {
|
|||||||
params,
|
params,
|
||||||
["treeNode"]
|
["treeNode"]
|
||||||
));
|
));
|
||||||
ret.push(HTML.splitLabel(
|
if(node.dependencies) {
|
||||||
"dependencies",
|
var dependencies = [];
|
||||||
[HTML.text("Dependencies")],
|
for(var d in node.dependencies) {
|
||||||
[HTML.text(node.dependencies === null ? "*" : node.dependencies.join(", "))],
|
if(d === "dependentAll") {
|
||||||
["treeNode"]
|
dependencies.push(HTML.splitLabel("dependency",[HTML.text(d)],[HTML.text(node.dependencies[d])]));
|
||||||
));
|
} else {
|
||||||
|
var dependents = [];
|
||||||
|
for(var t in node.dependencies[d]) {
|
||||||
|
dependents.push(t);
|
||||||
|
}
|
||||||
|
dependencies.push(HTML.splitLabel("dependency",[HTML.text(d)],[HTML.text(dependents.join(","))]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"dependencies",
|
||||||
|
[HTML.text("Dependencies")],
|
||||||
|
dependencies
|
||||||
|
));
|
||||||
|
}
|
||||||
if(node.children) {
|
if(node.children) {
|
||||||
ret.push(renderArray(node.children));
|
ret.push(renderArray(node.children));
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ WikiTextParser.prototype.parse = function(type,text) {
|
|||||||
this.source = text;
|
this.source = text;
|
||||||
this.nextMatch = 0;
|
this.nextMatch = 0;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
this.dependencies = [];
|
this.dependencies = {};
|
||||||
this.output = null;
|
this.output = null;
|
||||||
this.subWikify(this.children);
|
this.subWikify(this.children);
|
||||||
var tree = new WikiTextParseTree(this.children,this.dependencies,this.store);
|
var tree = new WikiTextParseTree(this.children,this.dependencies,this.store);
|
||||||
@ -76,21 +76,20 @@ WikiTextParser.prototype.parse = function(type,text) {
|
|||||||
return tree;
|
return tree;
|
||||||
};
|
};
|
||||||
|
|
||||||
WikiTextParser.prototype.addDependency = function(dependency) {
|
WikiTextParser.prototype.mergeDependencies = function(newDependencies) {
|
||||||
if(dependency === null) {
|
for(var rel in newDependencies) {
|
||||||
this.dependencies = null;
|
if(rel === "dependentAll") {
|
||||||
} else if(this.dependencies && this.dependencies.indexOf(dependency) === -1) {
|
this.dependencies.dependentAll = newDependencies.dependentAll;
|
||||||
this.dependencies.push(dependency);
|
} else {
|
||||||
}
|
if(!(rel in this.dependencies)) {
|
||||||
};
|
this.dependencies[rel] = {};
|
||||||
|
}
|
||||||
WikiTextParser.prototype.addDependencies = function(dependencies) {
|
for(var t in newDependencies[rel]) {
|
||||||
if(dependencies === null) {
|
if(this.dependencies[rel][t]) {
|
||||||
this.dependencies = null;
|
this.dependencies[rel][t]++;
|
||||||
} else if(this.dependencies !== null){
|
} else {
|
||||||
for(var t=0; t<dependencies.length; t++) {
|
this.dependencies[rel][t] = 1;
|
||||||
if(this.dependencies.indexOf(dependencies[t]) === -1) {
|
}
|
||||||
this.dependencies.push(dependencies[t]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ var HTML = require("./HTML.js").HTML,
|
|||||||
utils = require("./Utils.js");
|
utils = require("./Utils.js");
|
||||||
|
|
||||||
var WikiTextRenderer = function() {
|
var WikiTextRenderer = function() {
|
||||||
this.renderSteps = []; // Array of {step: n, dependencies: [],handler: function(tiddler,renderer,store,utils) {}}
|
this.renderSteps = []; // Array of {step: n, dependencies: {},handler: function(tiddler,renderer,store,utils) {}}
|
||||||
};
|
};
|
||||||
|
|
||||||
WikiTextRenderer.prototype.addRenderStep = function(renderStep) {
|
WikiTextRenderer.prototype.addRenderStep = function(renderStep) {
|
||||||
@ -79,11 +79,25 @@ WikiTextRenderer.prototype.toString = function(type) {
|
|||||||
[HTML.text(node.step.toString())],
|
[HTML.text(node.step.toString())],
|
||||||
[HTML.text(node.type.toString())]
|
[HTML.text(node.type.toString())]
|
||||||
));
|
));
|
||||||
ret.push(HTML.splitLabel(
|
if(node.dependencies) {
|
||||||
"dependencies",
|
var dependencies = [];
|
||||||
[HTML.text("Dependencies")],
|
for(var d in node.dependencies) {
|
||||||
[HTML.text(node.dependencies === null ? "*" : node.dependencies.join(", "))]
|
if(d === "dependentAll") {
|
||||||
));
|
dependencies.push(HTML.splitLabel("dependency",[HTML.text(d)],[HTML.text(node.dependencies[d])]));
|
||||||
|
} else {
|
||||||
|
var dependents = [];
|
||||||
|
for(var t in node.dependencies[d]) {
|
||||||
|
dependents.push(t);
|
||||||
|
}
|
||||||
|
dependencies.push(HTML.splitLabel("dependency",[HTML.text(d)],[HTML.text(dependents.join(","))]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret.push(HTML.splitLabel(
|
||||||
|
"dependencies",
|
||||||
|
[HTML.text("Dependencies")],
|
||||||
|
dependencies
|
||||||
|
));
|
||||||
|
}
|
||||||
if(node.macro) {
|
if(node.macro) {
|
||||||
ret.push(HTML.splitLabel(
|
ret.push(HTML.splitLabel(
|
||||||
"macro",
|
"macro",
|
||||||
|
@ -104,24 +104,33 @@ var enclosedTextHelper = function(w) {
|
|||||||
|
|
||||||
var insertMacroCall = function(w,output,name,params,children) {
|
var insertMacroCall = function(w,output,name,params,children) {
|
||||||
var macro = w.store.macros[name],
|
var macro = w.store.macros[name],
|
||||||
dependencies = [];
|
dependencies = {};
|
||||||
if(macro) {
|
if(macro) {
|
||||||
if(macro.dependentAll) {
|
if(macro.dependentAll) {
|
||||||
dependencies = null;
|
dependencies.dependentAll = true;
|
||||||
}
|
}
|
||||||
for(var m in macro.params) {
|
for(var m in macro.params) {
|
||||||
var param = macro.params[m];
|
var param = macro.params[m];
|
||||||
if(m in params) {
|
if(m in params) {
|
||||||
if(param.type === "tiddler") {
|
if(param.type === "tiddler") {
|
||||||
if(params[m].type === "eval") {
|
if(params[m].type === "eval") {
|
||||||
dependencies = null;
|
dependencies.dependentAll = true;
|
||||||
} else if(dependencies !== null) {
|
} else {
|
||||||
dependencies.push(params[m].value);
|
var rel = param.rel || "include",
|
||||||
|
target = params[m].value;
|
||||||
|
if(!(rel in dependencies)) {
|
||||||
|
dependencies[rel] = {};
|
||||||
|
}
|
||||||
|
if(dependencies[rel][target]) {
|
||||||
|
dependencies[rel][target]++;
|
||||||
|
} else {
|
||||||
|
dependencies[rel][target] = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.addDependencies(dependencies);
|
w.mergeDependencies(dependencies);
|
||||||
output.push(HTML.macro(name,params,children,dependencies));
|
output.push(HTML.macro(name,params,children,dependencies));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -42,12 +42,6 @@ exports.macro = {
|
|||||||
"The render functions for this tiddler",
|
"The render functions for this tiddler",
|
||||||
HTML.raw(parseTree.compile(type).toString(type))),type);
|
HTML.raw(parseTree.compile(type).toString(type))),type);
|
||||||
//break;
|
//break;
|
||||||
case "dependencies":
|
|
||||||
return HTML(HTML.slider("dependencies",
|
|
||||||
"Dependencies",
|
|
||||||
"The dependencies for this tiddler",
|
|
||||||
HTML.raw((parseTree.dependencies === null) ? "*" : encoder(parseTree.dependencies.join(", ")))),type);
|
|
||||||
//break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ exports.macro = {
|
|||||||
wrapperTag: "span",
|
wrapperTag: "span",
|
||||||
types: ["text/html","text/plain"],
|
types: ["text/html","text/plain"],
|
||||||
params: {
|
params: {
|
||||||
target: {byName: "default", type: "tiddler", optional: false}
|
target: {byName: "default", type: "tiddler", rel: "link", optional: false}
|
||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
click: function(event,node,tiddler,store,params) {
|
click: function(event,node,tiddler,store,params) {
|
||||||
|
@ -130,14 +130,10 @@ a.tw-slider-label::after {
|
|||||||
background-color: #eee;
|
background-color: #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
.treeWikiText {
|
.treeWikiText, .treeWikiTextRenderer {
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.nodeWikiText {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
.nodeWikiText .splitLabelLeft[data-tw-label-type='text'] {
|
.nodeWikiText .splitLabelLeft[data-tw-label-type='text'] {
|
||||||
background-color: #62CFFC;
|
background-color: #62CFFC;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
@ -158,6 +154,18 @@ a.tw-slider-label::after {
|
|||||||
color: #fff;
|
color: #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.nodeWikiText .splitLabelLeft[data-tw-label-type='dependencies'],
|
||||||
|
.treeWikiTextRenderer .splitLabelLeft[data-tw-label-type='dependencies'] {
|
||||||
|
background-color: #f89999;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nodeWikiText .splitLabelLeft[data-tw-label-type='dependency'],
|
||||||
|
.treeWikiTextRenderer .splitLabelLeft[data-tw-label-type='dependency'] {
|
||||||
|
background-color: #F80055;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
.treeWikiTextRenderer .splitLabelLeft[data-tw-label-type='rendererStep'] {
|
.treeWikiTextRenderer .splitLabelLeft[data-tw-label-type='rendererStep'] {
|
||||||
background-color: #F89406;
|
background-color: #F89406;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
@ -8,5 +8,4 @@ modifier: JeremyRuston
|
|||||||
{{body{
|
{{body{
|
||||||
<<view text wikified>>}}}
|
<<view text wikified>>}}}
|
||||||
<<info parsetree>>
|
<<info parsetree>>
|
||||||
<<info dependencies>>
|
|
||||||
<<info compiled>>
|
<<info compiled>>
|
Loading…
x
Reference in New Issue
Block a user