1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-10-01 08:20:46 +00:00

Refactored dependency handling

Now each class of dependency can be tracked individually
This commit is contained in:
Jeremy Ruston 2012-02-07 19:03:59 +00:00
parent 10774a724f
commit 95ab295fbb
11 changed files with 111 additions and 64 deletions

View File

@ -24,7 +24,7 @@ ImageRenderer.prototype.render = function(tiddler,store) {
var ImageParseTree = function(type,text) {
this.type = type;
this.text = text;
this.dependencies = [];
this.dependencies = {};
};
ImageParseTree.prototype.compile = function(type) {

View File

@ -29,7 +29,7 @@ JSONRenderer.prototype.toString = function(type) {
// The parse tree is degenerate
var JSONParseTree = function(tree) {
this.tree = tree;
this.dependencies = [];
this.dependencies = {};
};
JSONParseTree.prototype.compile = function(type) {

View File

@ -491,19 +491,9 @@ WikiStore.prototype.refreshDomNode = function(node,changes,renderer,tiddler) {
// Is this node a macro
} else if(macro !== null) {
// Get the render step
var r = renderer.renderSteps[renderStep],
hasChanged = false;
var r = renderer.renderSteps[renderStep];
// Refresh if a dependency has changed
if(r.dependencies === null) {
hasChanged = true;
} else {
for(var d=0; d<r.dependencies.length; d++) {
if(r.dependencies[d] in changes) {
hasChanged = true;
}
}
}
if(hasChanged) {
if(this.hasDependencyChanged(r.dependencies,changes)) {
renderer.rerender(node,changes,tiddler,this,renderStep);
} else {
// 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;
})();

View File

@ -17,7 +17,7 @@ var WikiTextRenderer = require("./WikiTextRenderer.js").WikiTextRenderer,
// Intialise the parse tree object
var WikiTextParseTree = function(tree,dependencies,store) {
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;
};
@ -69,7 +69,7 @@ WikiTextParseTree.prototype.compile = function(type,treenode) {
]);
renderStep.type = "main";
renderStep.step = renderStepIndex;
renderStep.dependencies = [];
renderStep.dependencies = {};
renderStep.handler = eval(parseTree.render());
return renderer;
};
@ -316,12 +316,25 @@ WikiTextParseTree.prototype.toString = function(type) {
params,
["treeNode"]
));
ret.push(HTML.splitLabel(
"dependencies",
[HTML.text("Dependencies")],
[HTML.text(node.dependencies === null ? "*" : node.dependencies.join(", "))],
["treeNode"]
));
if(node.dependencies) {
var dependencies = [];
for(var d in node.dependencies) {
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.children) {
ret.push(renderArray(node.children));
}

View File

@ -67,7 +67,7 @@ WikiTextParser.prototype.parse = function(type,text) {
this.source = text;
this.nextMatch = 0;
this.children = [];
this.dependencies = [];
this.dependencies = {};
this.output = null;
this.subWikify(this.children);
var tree = new WikiTextParseTree(this.children,this.dependencies,this.store);
@ -76,24 +76,23 @@ WikiTextParser.prototype.parse = function(type,text) {
return tree;
};
WikiTextParser.prototype.addDependency = function(dependency) {
if(dependency === null) {
this.dependencies = null;
} else if(this.dependencies && this.dependencies.indexOf(dependency) === -1) {
this.dependencies.push(dependency);
}
};
WikiTextParser.prototype.addDependencies = function(dependencies) {
if(dependencies === null) {
this.dependencies = null;
} else if(this.dependencies !== null){
for(var t=0; t<dependencies.length; t++) {
if(this.dependencies.indexOf(dependencies[t]) === -1) {
this.dependencies.push(dependencies[t]);
WikiTextParser.prototype.mergeDependencies = function(newDependencies) {
for(var rel in newDependencies) {
if(rel === "dependentAll") {
this.dependencies.dependentAll = newDependencies.dependentAll;
} else {
if(!(rel in this.dependencies)) {
this.dependencies[rel] = {};
}
for(var t in newDependencies[rel]) {
if(this.dependencies[rel][t]) {
this.dependencies[rel][t]++;
} else {
this.dependencies[rel][t] = 1;
}
}
}
}
}
};
WikiTextParser.prototype.outputText = function(place,startPos,endPos) {

View File

@ -13,7 +13,7 @@ var HTML = require("./HTML.js").HTML,
utils = require("./Utils.js");
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) {
@ -79,11 +79,25 @@ WikiTextRenderer.prototype.toString = function(type) {
[HTML.text(node.step.toString())],
[HTML.text(node.type.toString())]
));
ret.push(HTML.splitLabel(
"dependencies",
[HTML.text("Dependencies")],
[HTML.text(node.dependencies === null ? "*" : node.dependencies.join(", "))]
));
if(node.dependencies) {
var dependencies = [];
for(var d in node.dependencies) {
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) {
ret.push(HTML.splitLabel(
"macro",

View File

@ -104,24 +104,33 @@ var enclosedTextHelper = function(w) {
var insertMacroCall = function(w,output,name,params,children) {
var macro = w.store.macros[name],
dependencies = [];
dependencies = {};
if(macro) {
if(macro.dependentAll) {
dependencies = null;
dependencies.dependentAll = true;
}
for(var m in macro.params) {
var param = macro.params[m];
if(m in params) {
if(param.type === "tiddler") {
if(params[m].type === "eval") {
dependencies = null;
} else if(dependencies !== null) {
dependencies.push(params[m].value);
dependencies.dependentAll = true;
} else {
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));
}
};

View File

@ -42,12 +42,6 @@ exports.macro = {
"The render functions for this tiddler",
HTML.raw(parseTree.compile(type).toString(type))),type);
//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;
}
}
}

View File

@ -15,7 +15,7 @@ exports.macro = {
wrapperTag: "span",
types: ["text/html","text/plain"],
params: {
target: {byName: "default", type: "tiddler", optional: false}
target: {byName: "default", type: "tiddler", rel: "link", optional: false}
},
events: {
click: function(event,node,tiddler,store,params) {

View File

@ -130,14 +130,10 @@ a.tw-slider-label::after {
background-color: #eee;
}
.treeWikiText {
.treeWikiText, .treeWikiTextRenderer {
list-style-type: none;
}
.nodeWikiText {
}
.nodeWikiText .splitLabelLeft[data-tw-label-type='text'] {
background-color: #62CFFC;
color: #fff;
@ -158,6 +154,18 @@ a.tw-slider-label::after {
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'] {
background-color: #F89406;
color: #fff;

View File

@ -8,5 +8,4 @@ modifier: JeremyRuston
{{body{
<<view text wikified>>}}}
<<info parsetree>>
<<info dependencies>>
<<info compiled>>