From 6c65aa2a6de83faa301939b413a75fc1d46b977a Mon Sep 17 00:00:00 2001 From: Jermolene Date: Sat, 4 Feb 2017 17:25:30 +0000 Subject: [PATCH] Make the syncer more configurable, including names for sync adaptors @danielo515 you may want to add a name to your sync adaptor :smile: --- core/modules/syncer.js | 36 +++++++++++-------- .../filesystem/filesystemadaptor.js | 2 ++ .../tiddlywiki/tiddlyweb/tiddlywebadaptor.js | 2 ++ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/core/modules/syncer.js b/core/modules/syncer.js index cb1191f16..1c1e35f91 100644 --- a/core/modules/syncer.js +++ b/core/modules/syncer.js @@ -12,6 +12,18 @@ The syncer tracks changes to the store. If a syncadaptor is used then individual /*global $tw: false */ "use strict"; +/* +Defaults +*/ +Syncer.prototype.titleIsLoggedIn = "$:/status/IsLoggedIn"; +Syncer.prototype.titleUserName = "$:/status/UserName"; +Syncer.prototype.titleSyncFilter = "$:/config/SyncFilter"; +Syncer.prototype.titleSavedNotification = "$:/language/Notifications/Save/Done"; +Syncer.prototype.taskTimerInterval = 1 * 1000; // Interval for sync timer +Syncer.prototype.throttleInterval = 1 * 1000; // Defer saving tiddlers if they've changed in the last 1s... +Syncer.prototype.fallbackInterval = 10 * 1000; // Unless the task is older than 10s +Syncer.prototype.pollTimerInterval = 60 * 1000; // Interval for polling for changes from the adaptor + /* Instantiate the syncer with the following options: syncadaptor: reference to syncadaptor to be used @@ -21,8 +33,17 @@ function Syncer(options) { var self = this; this.wiki = options.wiki; this.syncadaptor = options.syncadaptor; + this.titleIsLoggedIn = options.titleIsLoggedIn || this.titleIsLoggedIn; + this.titleUserName = options.titleUserName || this.titleUserName; + this.titleSyncFilter = options.titleSyncFilter || this.titleSyncFilter; + this.titleSavedNotification = options.titleSavedNotification || this.titleSavedNotification; + this.taskTimerInterval = options.taskTimerInterval || this.taskTimerInterval; + this.throttleInterval = options.throttleInterval || this.throttleInterval; + this.fallbackInterval = options.fallbackInterval || this.fallbackInterval; + this.pollTimerInterval = options.pollTimerInterval || this.pollTimerInterval; + this.logging = $tw.utils.hop(options,"logging") ? options.logging : true; // Make a logger - this.logger = new $tw.utils.Logger("syncer" + ($tw.browser ? "-browser" : "") + ($tw.node ? "-server" : "")); + this.logger = new $tw.utils.Logger("syncer" + ($tw.browser ? "-browser" : "") + ($tw.node ? "-server" : "") + (this.syncadaptor.name ? ("-" + this.syncadaptor.name) : "")); // Compile the dirty tiddler filter this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter)); // Record information for known tiddlers @@ -69,19 +90,6 @@ function Syncer(options) { }); } -/* -Constants -*/ -Syncer.prototype.titleIsLoggedIn = "$:/status/IsLoggedIn"; -Syncer.prototype.titleUserName = "$:/status/UserName"; -Syncer.prototype.titleSyncFilter = "$:/config/SyncFilter"; -Syncer.prototype.titleSavedNotification = "$:/language/Notifications/Save/Done"; -Syncer.prototype.taskTimerInterval = 1 * 1000; // Interval for sync timer -Syncer.prototype.throttleInterval = 1 * 1000; // Defer saving tiddlers if they've changed in the last 1s... -Syncer.prototype.fallbackInterval = 10 * 1000; // Unless the task is older than 10s -Syncer.prototype.pollTimerInterval = 60 * 1000; // Interval for polling for changes from the adaptor - - /* Read (or re-read) the latest tiddler info from the store */ diff --git a/plugins/tiddlywiki/filesystem/filesystemadaptor.js b/plugins/tiddlywiki/filesystem/filesystemadaptor.js index acbd6faf6..db7b5c856 100644 --- a/plugins/tiddlywiki/filesystem/filesystemadaptor.js +++ b/plugins/tiddlywiki/filesystem/filesystemadaptor.js @@ -24,6 +24,8 @@ function FileSystemAdaptor(options) { $tw.utils.createDirectory($tw.boot.wikiTiddlersPath); } +FileSystemAdaptor.prototype.name = "filesystem"; + FileSystemAdaptor.prototype.isReady = function() { // The file system adaptor is always ready return true; diff --git a/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js b/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js index 9666ed0f8..f3cdde939 100644 --- a/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js +++ b/plugins/tiddlywiki/tiddlyweb/tiddlywebadaptor.js @@ -23,6 +23,8 @@ function TiddlyWebAdaptor(options) { this.logger = new $tw.utils.Logger("TiddlyWebAdaptor"); } +TiddlyWebAdaptor.prototype.name = "tiddlyweb"; + TiddlyWebAdaptor.prototype.isReady = function() { return this.hasStatus; };