1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-09-27 14:48:19 +00:00

Improve comments and coding style

This commit is contained in:
Jermolene 2014-09-01 20:39:08 +01:00
parent ca1de2be99
commit 2f6d16b0fa
2 changed files with 11 additions and 9 deletions

View File

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

View File

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