mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-01-12 10:20:26 +00:00
Revert getTiddlerData() and add getTiddlerDataCached()
For backwards compatibility, we now explicitly request the cacheable version of this method. Fixes #1873
This commit is contained in:
parent
0c276c327b
commit
32f6d7f1b0
@ -43,7 +43,7 @@ Command.prototype.execute = function() {
|
|||||||
basepath = this.params[2],
|
basepath = this.params[2],
|
||||||
skinnyListTitle = this.params[3];
|
skinnyListTitle = this.params[3];
|
||||||
// Get the container tiddler as data
|
// Get the container tiddler as data
|
||||||
var containerData = self.commander.wiki.getTiddlerData(containerTitle,undefined);
|
var containerData = self.commander.wiki.getTiddlerDataCached(containerTitle,undefined);
|
||||||
if(!containerData) {
|
if(!containerData) {
|
||||||
return "'" + containerTitle + "' is not a tiddler bundle";
|
return "'" + containerTitle + "' is not a tiddler bundle";
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ Command.prototype.execute = function() {
|
|||||||
}
|
}
|
||||||
var self = this,
|
var self = this,
|
||||||
title = this.params[0],
|
title = this.params[0],
|
||||||
pluginData = this.commander.wiki.getTiddlerData(title);
|
pluginData = this.commander.wiki.getTiddlerDataCached(title);
|
||||||
if(!pluginData) {
|
if(!pluginData) {
|
||||||
return "Plugin '" + title + "' not found";
|
return "Plugin '" + title + "' not found";
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ Export our filter function
|
|||||||
exports.indexes = function(source,operator,options) {
|
exports.indexes = function(source,operator,options) {
|
||||||
var results = [];
|
var results = [];
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
var data = options.wiki.getTiddlerData(title);
|
var data = options.wiki.getTiddlerDataCached(title);
|
||||||
if(data) {
|
if(data) {
|
||||||
$tw.utils.pushTop(results,Object.keys(data));
|
$tw.utils.pushTop(results,Object.keys(data));
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ Export our filter function
|
|||||||
exports.plugintiddlers = function(source,operator,options) {
|
exports.plugintiddlers = function(source,operator,options) {
|
||||||
var results = [];
|
var results = [];
|
||||||
source(function(tiddler,title) {
|
source(function(tiddler,title) {
|
||||||
var pluginInfo = options.wiki.getPluginInfo(title) || options.wiki.getTiddlerData(title,{tiddlers:[]});
|
var pluginInfo = options.wiki.getPluginInfo(title) || options.wiki.getTiddlerDataCached(title,{tiddlers:[]});
|
||||||
if(pluginInfo && pluginInfo.tiddlers) {
|
if(pluginInfo && pluginInfo.tiddlers) {
|
||||||
$tw.utils.each(pluginInfo.tiddlers,function(fields,title) {
|
$tw.utils.each(pluginInfo.tiddlers,function(fields,title) {
|
||||||
results.push(title);
|
results.push(title);
|
||||||
|
@ -18,7 +18,7 @@ var ZoominListView = function(listWidget) {
|
|||||||
var self = this;
|
var self = this;
|
||||||
this.listWidget = listWidget;
|
this.listWidget = listWidget;
|
||||||
// Get the index of the tiddler that is at the top of the history
|
// Get the index of the tiddler that is at the top of the history
|
||||||
var history = this.listWidget.wiki.getTiddlerData(this.listWidget.historyTitle,[]),
|
var history = this.listWidget.wiki.getTiddlerDataCached(this.listWidget.historyTitle,[]),
|
||||||
targetTiddler;
|
targetTiddler;
|
||||||
if(history.length > 0) {
|
if(history.length > 0) {
|
||||||
targetTiddler = history[history.length-1].title;
|
targetTiddler = history[history.length-1].title;
|
||||||
|
@ -44,7 +44,7 @@ exports.upgrade = function(wiki,titles,tiddlers) {
|
|||||||
var mapping = MAPPINGS[title];
|
var mapping = MAPPINGS[title];
|
||||||
if(mapping) {
|
if(mapping) {
|
||||||
var tiddler = new $tw.Tiddler(tiddlers[title]),
|
var tiddler = new $tw.Tiddler(tiddlers[title]),
|
||||||
tiddlerData = wiki.getTiddlerData(tiddler,{});
|
tiddlerData = wiki.getTiddlerDataCached(tiddler,{});
|
||||||
for(var index in mapping) {
|
for(var index in mapping) {
|
||||||
var mappedTitle = mapping[index];
|
var mappedTitle = mapping[index];
|
||||||
if(!tiddlers[mappedTitle] || tiddlers[mappedTitle].title !== mappedTitle) {
|
if(!tiddlers[mappedTitle] || tiddlers[mappedTitle].title !== mappedTitle) {
|
||||||
|
@ -171,6 +171,17 @@ exports.extendDeepCopy = function(object,extendedProperties) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.deepFreeze = function deepFreeze(object) {
|
||||||
|
var property, key;
|
||||||
|
Object.freeze(object);
|
||||||
|
for(key in object) {
|
||||||
|
property = object[key];
|
||||||
|
if($tw.utils.hop(object,key) && (typeof property === "object") && !Object.isFrozen(property)) {
|
||||||
|
deepFreeze(property);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
exports.slowInSlowOut = function(t) {
|
exports.slowInSlowOut = function(t) {
|
||||||
return (1 - ((Math.cos(t * Math.PI) + 1) / 2));
|
return (1 - ((Math.cos(t * Math.PI) + 1) / 2));
|
||||||
};
|
};
|
||||||
|
@ -156,7 +156,7 @@ Handle any changes to the history list
|
|||||||
*/
|
*/
|
||||||
ListWidget.prototype.handleHistoryChanges = function() {
|
ListWidget.prototype.handleHistoryChanges = function() {
|
||||||
// Get the history data
|
// Get the history data
|
||||||
var newHistory = this.wiki.getTiddlerData(this.historyTitle,[]);
|
var newHistory = this.wiki.getTiddlerDataCached(this.historyTitle,[]);
|
||||||
// Ignore any entries of the history that match the previous history
|
// Ignore any entries of the history that match the previous history
|
||||||
var entry = 0;
|
var entry = 0;
|
||||||
while(entry < newHistory.length && entry < this.history.length && newHistory[entry].title === this.history[entry].title) {
|
while(entry < newHistory.length && entry < this.history.length && newHistory[entry].title === this.history[entry].title) {
|
||||||
|
@ -539,7 +539,7 @@ NavigatorWidget.prototype.handleImportTiddlersEvent = function(event) {
|
|||||||
NavigatorWidget.prototype.handlePerformImportEvent = function(event) {
|
NavigatorWidget.prototype.handlePerformImportEvent = function(event) {
|
||||||
var self = this,
|
var self = this,
|
||||||
importTiddler = this.wiki.getTiddler(event.param),
|
importTiddler = this.wiki.getTiddler(event.param),
|
||||||
importData = this.wiki.getTiddlerData(event.param,{tiddlers: {}}),
|
importData = this.wiki.getTiddlerDataCached(event.param,{tiddlers: {}}),
|
||||||
importReport = [];
|
importReport = [];
|
||||||
// Add the tiddlers to the store
|
// Add the tiddlers to the store
|
||||||
importReport.push("The following tiddlers were imported:\n");
|
importReport.push("The following tiddlers were imported:\n");
|
||||||
|
@ -577,7 +577,7 @@ exports.sortByList = function(array,listTitle) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
exports.getSubTiddler = function(title,subTiddlerTitle) {
|
exports.getSubTiddler = function(title,subTiddlerTitle) {
|
||||||
var bundleInfo = this.getPluginInfo(title) || this.getTiddlerData(title);
|
var bundleInfo = this.getPluginInfo(title) || this.getTiddlerDataCached(title);
|
||||||
if(bundleInfo && bundleInfo.tiddlers) {
|
if(bundleInfo && bundleInfo.tiddlers) {
|
||||||
var subTiddler = bundleInfo.tiddlers[subTiddlerTitle];
|
var subTiddler = bundleInfo.tiddlers[subTiddlerTitle];
|
||||||
if(subTiddler) {
|
if(subTiddler) {
|
||||||
@ -613,6 +613,29 @@ Other types currently just return null.
|
|||||||
|
|
||||||
titleOrTiddler: string tiddler title or a tiddler object
|
titleOrTiddler: string tiddler title or a tiddler object
|
||||||
defaultData: default data to be returned if the tiddler is missing or doesn't contain data
|
defaultData: default data to be returned if the tiddler is missing or doesn't contain data
|
||||||
|
|
||||||
|
Note that the same value is returned for repeated calls for the same tiddler data. The value is frozen to prevent modification; otherwise modifications would be visible to all callers
|
||||||
|
*/
|
||||||
|
exports.getTiddlerDataCached = function(titleOrTiddler,defaultData) {
|
||||||
|
var self = this,
|
||||||
|
tiddler = titleOrTiddler;
|
||||||
|
if(!(tiddler instanceof $tw.Tiddler)) {
|
||||||
|
tiddler = this.getTiddler(tiddler);
|
||||||
|
}
|
||||||
|
if(tiddler) {
|
||||||
|
return this.getCacheForTiddler(tiddler.fields.title,"data",function() {
|
||||||
|
// Return the frozen value
|
||||||
|
var value = self.getTiddlerData(tiddler.fields.title,defaultData);
|
||||||
|
$tw.utils.deepFreeze(value);
|
||||||
|
return value;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return defaultData;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Alternative, uncached version of getTiddlerDataCached(). The return value can be mutated freely and reused
|
||||||
*/
|
*/
|
||||||
exports.getTiddlerData = function(titleOrTiddler,defaultData) {
|
exports.getTiddlerData = function(titleOrTiddler,defaultData) {
|
||||||
var tiddler = titleOrTiddler,
|
var tiddler = titleOrTiddler,
|
||||||
@ -621,20 +644,18 @@ exports.getTiddlerData = function(titleOrTiddler,defaultData) {
|
|||||||
tiddler = this.getTiddler(tiddler);
|
tiddler = this.getTiddler(tiddler);
|
||||||
}
|
}
|
||||||
if(tiddler && tiddler.fields.text) {
|
if(tiddler && tiddler.fields.text) {
|
||||||
return this.getCacheForTiddler(tiddler.fields.title,"data",function() {
|
switch(tiddler.fields.type) {
|
||||||
switch(tiddler.fields.type) {
|
case "application/json":
|
||||||
case "application/json":
|
// JSON tiddler
|
||||||
// JSON tiddler
|
try {
|
||||||
try {
|
data = JSON.parse(tiddler.fields.text);
|
||||||
data = JSON.parse(tiddler.fields.text);
|
} catch(ex) {
|
||||||
} catch(ex) {
|
return defaultData;
|
||||||
return defaultData;
|
}
|
||||||
}
|
return data;
|
||||||
return data;
|
case "application/x-tiddler-dictionary":
|
||||||
case "application/x-tiddler-dictionary":
|
return $tw.utils.parseFields(tiddler.fields.text);
|
||||||
return $tw.utils.parseFields(tiddler.fields.text);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return defaultData;
|
return defaultData;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user