1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-10-30 07:03:00 +00:00

Refactored autosave mechanism

Previously we were using a message `tw-auto-save-wiki` to trigger an
autosave. The message was generated by certain UI actions such as
saving a tiddler. The trouble was that the message was being processed
before the wiki change event for the accompanying change had had a
chance to percolate. The end result was that the dirty indicator was
staying lit when using autosave.

The new approach abandons the autosave message and instead triggers the
autosave in the wiki change event when a relevant change occurs.

One happy side effect of these changes is that the dirty indicator now
works as expected with the client server edition - ie, when typing in a
draft tiddler the dirty indicator will flash briefly, and then clear
when the sync mechanism has completed saving the draft.
This commit is contained in:
Jermolene
2014-08-27 10:04:54 +01:00
parent 9d871309c2
commit 13c4e028b1
7 changed files with 16 additions and 42 deletions

View File

@@ -243,8 +243,6 @@ NavigatorWidget.prototype.handleDeleteTiddlerEvent = function(event) {
// Remove the closed tiddler from the story
this.removeTitleFromStory(storyList,title);
this.saveStoryList(storyList);
// Send a notification event
this.dispatchEvent({type: "tw-auto-save-wiki"});
return false;
};
@@ -333,8 +331,6 @@ NavigatorWidget.prototype.handleSaveTiddlerEvent = function(event) {
if(draftTitle !== this.storyTitle) {
this.saveStoryList(storyList);
}
// Send a notification event
this.dispatchEvent({type: "tw-auto-save-wiki"});
}
}
}
@@ -376,13 +372,8 @@ NavigatorWidget.prototype.handleNewTiddlerEvent = function(event) {
var storyList = this.getStoryList();
// Get the template tiddler if there is one
var templateTiddler = this.wiki.getTiddler(event.param);
// Create the new tiddler
// Title the new tiddler
var title = this.wiki.generateNewTitle((templateTiddler && templateTiddler.fields.title) || "New Tiddler");
var tiddler = new $tw.Tiddler(this.wiki.getCreationFields(),{
text: "Newly created tiddler",
title: title
},this.wiki.getModificationFields());
this.wiki.addTiddler(tiddler);
// Create the draft tiddler
var draftTitle = this.generateDraftTitle(title),
draftTiddler = new $tw.Tiddler({
@@ -487,8 +478,6 @@ NavigatorWidget.prototype.handlePerformImportEvent = function(event) {
}));
// Navigate to the $:/Import tiddler
this.addToHistory([IMPORT_TITLE]);
// Send a notification event
this.dispatchEvent({type: "tw-auto-save-wiki"});
};
exports.navigator = NavigatorWidget;