2012-02-17 14:11:25 +00:00
|
|
|
/*\
|
|
|
|
title: js/Dependencies.js
|
|
|
|
|
2012-03-30 15:42:35 +00:00
|
|
|
Represents the dependencies of a tiddler or a parser node as these fields:
|
2012-02-17 14:11:25 +00:00
|
|
|
|
|
|
|
tiddlers: A hashmap of explicitly tiddler titles, with the value `false` if the dependency is skinny, and `true` if it is fat
|
|
|
|
dependentAll: True if there is an implicit skinny dependency on all available tiddlers
|
2012-03-30 15:42:35 +00:00
|
|
|
dependentOnContextTiddler: True if the node has a fat dependency on the current context tiddler
|
2012-02-17 14:11:25 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var utils = require("./Utils.js");
|
|
|
|
|
2012-02-20 18:03:51 +00:00
|
|
|
var Dependencies = function(skinnyTiddlers,fatTiddlers,dependentAll) {
|
|
|
|
var t,tiddlerTitle;
|
|
|
|
this.tiddlers = {};
|
2012-02-17 14:11:25 +00:00
|
|
|
this.dependentAll = dependentAll;
|
2012-02-20 18:03:51 +00:00
|
|
|
if(skinnyTiddlers) {
|
|
|
|
for(t=0; t<skinnyTiddlers.length; t++) {
|
|
|
|
tiddlerTitle = skinnyTiddlers[t];
|
|
|
|
if(typeof tiddlerTitle === "string" && tiddlerTitle !== "") {
|
|
|
|
this.tiddlers[tiddlerTitle] = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(fatTiddlers) {
|
|
|
|
for(t=0; t<fatTiddlers.length; t++) {
|
|
|
|
tiddlerTitle = fatTiddlers[t];
|
|
|
|
if(typeof tiddlerTitle === "string" && tiddlerTitle !== "") {
|
|
|
|
this.tiddlers[tiddlerTitle] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-02-17 14:11:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Adds a dependency to a given tiddler. Note how setting a dependency of fat=false on a tiddler that already has
|
|
|
|
a dependency of fat=true will leave the fat setting as true
|
|
|
|
*/
|
|
|
|
Dependencies.prototype.addDependency = function(tiddlerTitle,fat) {
|
|
|
|
if(!this.tiddlers[tiddlerTitle]) {
|
|
|
|
this.tiddlers[tiddlerTitle] = fat;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Dependencies.prototype.mergeDependencies = function(dep) {
|
|
|
|
this.dependentAll = dep.dependentAll || this.dependentAll;
|
|
|
|
for(var t in dep.tiddlers) {
|
|
|
|
this.addDependency(t,dep.tiddlers[t]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Determine if these dependencies are impacted by the specified array of changes
|
|
|
|
changes: Hashmap of {title: "created|modified|deleted"}
|
2012-03-30 12:48:16 +00:00
|
|
|
contextTiddlerTitle: The title of the current context tiddler
|
2012-02-17 14:11:25 +00:00
|
|
|
*/
|
2012-03-30 12:48:16 +00:00
|
|
|
Dependencies.prototype.hasChanged = function(changes,contextTiddlerTitle) {
|
2012-02-17 14:11:25 +00:00
|
|
|
if(this.dependentAll) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-30 15:42:35 +00:00
|
|
|
if(!!this.dependentOnContextTiddler && contextTiddlerTitle !== undefined && changes.hasOwnProperty(contextTiddlerTitle)) {
|
2012-03-30 12:48:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-02-17 14:11:25 +00:00
|
|
|
for(var c in changes) {
|
|
|
|
if(this.tiddlers.hasOwnProperty(c)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.Dependencies = Dependencies;
|
|
|
|
|
|
|
|
})();
|