1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-11-04 17:43:00 +00:00

Support for lazy loaded tiddlers

This commit is contained in:
Jeremy Ruston
2012-11-18 13:14:28 +00:00
parent 17334f64cc
commit 5c87b437ee
5 changed files with 86 additions and 16 deletions

View File

@@ -730,6 +730,17 @@ exports.initServerConnections = function() {
});
};
/*
Invoke all the active server connections
*/
exports.invokeServerConnections = function(method /* ,args */) {
var args = Array.prototype.slice.call(arguments,1);
for(var title in this.serverConnections) {
var connection = this.serverConnections[title];
connection.syncer[method].apply(connection.syncer,[connection.connection].concat(args));
}
};
/*
Handle a syncer message
*/
@@ -739,4 +750,24 @@ exports.handleSyncerEvent = function(event) {
}
};
/*
Trigger a load for a tiddler if it is skinny. Returns the text, or undefined if the tiddler is missing, null if the tiddler is being lazily loaded.
*/
exports.getTiddlerText = function(title) {
var tiddler = this.getTiddler(title);
// Return undefined if the tiddler isn't found
if(!tiddler) {
return undefined;
}
if(tiddler.fields.text) {
// Just return the text if we've got it
return tiddler.fields.text;
} else {
// Ask all the server connections to load the tiddler if they can
this.invokeServerConnections("lazyLoad",title,tiddler);
// Indicate that the text is being loaded
return null;
}
};
})();