Improve comments and coding style

print-window-tiddler
Jermolene 2014-09-01 20:39:08 +01:00
rodzic ca1de2be99
commit 2f6d16b0fa
2 zmienionych plików z 11 dodań i 9 usunięć

Wyświetl plik

@ -32,22 +32,24 @@ function SaverHandler(options) {
if($tw.browser && this.dirtyTracking) { if($tw.browser && this.dirtyTracking) {
// Compile the dirty tiddler filter // Compile the dirty tiddler filter
this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter)); this.filterFn = this.wiki.compileFilter(this.wiki.getTiddlerText(this.titleSyncFilter));
// Count of tiddlers that have been changed but not yet saved // Count of changes that have not yet been saved
this.numTasksInQueue = 0; this.numChanges = 0;
// Listen out for changes to tiddlers // Listen out for changes to tiddlers
this.wiki.addEventListener("change",function(changes) { this.wiki.addEventListener("change",function(changes) {
// Filter the changes so that we only count changes to tiddlers that we care about
var filteredChanges = self.filterFn.call(self.wiki,function(callback) { var filteredChanges = self.filterFn.call(self.wiki,function(callback) {
$tw.utils.each(changes,function(change,title) { $tw.utils.each(changes,function(change,title) {
var tiddler = self.wiki.getTiddler(title); var tiddler = self.wiki.getTiddler(title);
callback(tiddler,title); callback(tiddler,title);
}); });
}); });
self.numTasksInQueue += filteredChanges.length; // Adjust the number of changes
self.numChanges += filteredChanges.length;
self.updateDirtyStatus(); self.updateDirtyStatus();
// Do any autosave if one is pending and there's no more change events // Do any autosave if one is pending and there's no more change events
if(self.pendingAutoSave && self.wiki.getSizeOfTiddlerEventQueue() === 0) { if(self.pendingAutoSave && self.wiki.getSizeOfTiddlerEventQueue() === 0) {
// Check if we're dirty // Check if we're dirty
if(self.numTasksInQueue > 0) { if(self.numChanges > 0) {
self.saveWiki({ self.saveWiki({
method: "autosave", method: "autosave",
downloadType: "text/plain" downloadType: "text/plain"
@ -61,7 +63,7 @@ function SaverHandler(options) {
// Do the autosave unless there are outstanding tiddler change events // Do the autosave unless there are outstanding tiddler change events
if(self.wiki.getSizeOfTiddlerEventQueue() === 0) { if(self.wiki.getSizeOfTiddlerEventQueue() === 0) {
// Check if we're dirty // Check if we're dirty
if(self.numTasksInQueue > 0) { if(self.numChanges > 0) {
self.saveWiki({ self.saveWiki({
method: "autosave", method: "autosave",
downloadType: "text/plain" downloadType: "text/plain"
@ -150,7 +152,7 @@ SaverHandler.prototype.saveWiki = function(options) {
} else { } else {
// Clear the task queue if we're saving (rather than downloading) // Clear the task queue if we're saving (rather than downloading)
if(method !== "download") { if(method !== "download") {
self.numTasksInQueue = 0; self.numChanges = 0;
self.updateDirtyStatus(); self.updateDirtyStatus();
} }
$tw.notifier.display(self.titleSavedNotification); $tw.notifier.display(self.titleSavedNotification);
@ -178,7 +180,7 @@ SaverHandler.prototype.saveWiki = function(options) {
Checks whether the wiki is dirty (ie the window shouldn't be closed) Checks whether the wiki is dirty (ie the window shouldn't be closed)
*/ */
SaverHandler.prototype.isDirty = function() { SaverHandler.prototype.isDirty = function() {
return this.numTasksInQueue > 0; return this.numChanges > 0;
}; };
/* /*

Wyświetl plik

@ -63,7 +63,7 @@ function Syncer(options) {
self.handleLazyLoadEvent(title); self.handleLazyLoadEvent(title);
}); });
// Get the login status // Get the login status
this.getStatus(function (err,isLoggedIn) { this.getStatus(function(err,isLoggedIn) {
// Do a sync from the server // Do a sync from the server
self.syncFromServer(); self.syncFromServer();
}); });
@ -173,7 +173,7 @@ Syncer.prototype.syncFromServer = function() {
this.pollTimerId = null; this.pollTimerId = null;
} }
this.syncadaptor.getSkinnyTiddlers(function(err,tiddlers) { this.syncadaptor.getSkinnyTiddlers(function(err,tiddlers) {
// Trigger another sync // Trigger the next sync
self.pollTimerId = setTimeout(function() { self.pollTimerId = setTimeout(function() {
self.pollTimerId = null; self.pollTimerId = null;
self.syncFromServer.call(self); self.syncFromServer.call(self);