From e194aed4493df55d9c329ea4eae18136a77a191a Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 17 Nov 2012 20:18:36 +0000 Subject: [PATCH] Introduce syncer mechanism --- core/modules/startup.js | 11 ++- core/modules/wiki.js | 47 ++++++++--- editions/tw5tiddlyweb/tiddlers/HelloThere.tid | 4 +- .../tw5tiddlyweb/wiki/TiddlyWebConnection.tid | 5 +- plugins/tiddlywiki/tiddlyweb/loginmacro.js | 41 --------- plugins/tiddlywiki/tiddlyweb/logoutmacro.js | 41 --------- plugins/tiddlywiki/tiddlyweb/tiddlyweb.js | 84 ++++++++++++------- 7 files changed, 101 insertions(+), 132 deletions(-) delete mode 100644 plugins/tiddlywiki/tiddlyweb/loginmacro.js delete mode 100644 plugins/tiddlywiki/tiddlyweb/logoutmacro.js diff --git a/core/modules/startup.js b/core/modules/startup.js index 26fad35c6..de04bd630 100644 --- a/core/modules/startup.js +++ b/core/modules/startup.js @@ -34,9 +34,10 @@ exports.startup = function() { $tw.wiki.initMacros(); $tw.wiki.initEditors(); $tw.wiki.initFieldViewers(); - $tw.wiki.initStoryViews(); $tw.wiki.initListViews(); $tw.wiki.initParsers(); + $tw.wiki.initSyncers(); + $tw.wiki.initServerConnections(); // Set up the command modules $tw.Commander.initCommands(); // Host-specific startup @@ -57,6 +58,12 @@ exports.startup = function() { document.addEventListener("tw-modal",function(event) { $tw.modal.display(event.param); },false); + // Install the syncer message mechanism + var handleSyncerEvent = function(event) { + $tw.wiki.handleSyncerEvent.call($tw.wiki,event); + }; + document.addEventListener("tw-login",handleSyncerEvent,false); + document.addEventListener("tw-logout",handleSyncerEvent,false); // Install the scroller $tw.scroller = new $tw.utils.Scroller(); // Install the sprite factory @@ -100,7 +107,7 @@ exports.startup = function() { $tw.renderer.refreshInDom(changes); }); } else { - // Start a commander with the command line arguments + // On the server, start a commander with the command line arguments commander = new $tw.Commander( Array.prototype.slice.call(process.argv,2), function(err) { diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 7b3820d34..adc484c32 100644 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -557,18 +557,6 @@ exports.initListViews = function(moduleType) { } }; -/* -Install view modules for the story macro -*/ -exports.initStoryViews = function(moduleType) { - moduleType = moduleType || "storyview"; - var storyMacro = this.macros.story; - if(storyMacro) { - storyMacro.viewers = {}; - $tw.modules.applyMethods(moduleType,storyMacro.viewers); - } -}; - /* Select the appropriate saver modules and set them up */ @@ -701,4 +689,39 @@ exports.search = function(text,options) { return results; }; +/* +Initialise syncers +*/ +exports.initSyncers = function() { + this.syncers = {}; + var self = this; + $tw.modules.forEachModuleOfType("syncer",function(title,module) { + if(module.name && module.syncer) { + self.syncers[module.name] = new module.syncer({ + wiki: self + }); + } + }); +}; + +/* +Initialise server connections +*/ +exports.initServerConnections = function() { + this.serverConnections = {}; + var self = this; + $tw.modules.forEachModuleOfType("serverconnection",function(title,module) { + self.serverConnections[title] = module; + }); +}; + +/* +Handle a syncer message +*/ +exports.handleSyncerEvent = function(event) { + for(var syncer in this.syncers) { + this.syncers[syncer].handleEvent(event); + } +}; + })(); diff --git a/editions/tw5tiddlyweb/tiddlers/HelloThere.tid b/editions/tw5tiddlyweb/tiddlers/HelloThere.tid index f20326c8b..2864dc0b0 100644 --- a/editions/tw5tiddlyweb/tiddlers/HelloThere.tid +++ b/editions/tw5tiddlyweb/tiddlers/HelloThere.tid @@ -3,10 +3,10 @@ title: HelloThere Experimenting with TiddlyWeb integration for TiddlyWiki5. << -Log in to TiddlyWeb: <> +Log in to TiddlyWeb: <