mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-11-22 10:14:51 +00:00
Extend refresh throttling to tiddlers having a "throttle.refresh" field
See discussion here: https://groups.google.com/d/msgid/tiddlywiki/7738644f-b53f-4fb0-b0df-16243fe51795%40googlegroups.com
This commit is contained in:
@@ -25,7 +25,7 @@ var PAGE_TEMPLATE_TITLE = "$:/core/ui/PageTemplate";
|
||||
|
||||
// Time (in ms) that we defer refreshing changes to draft tiddlers
|
||||
var DRAFT_TIDDLER_TIMEOUT_TITLE = "$:/config/Drafts/TypingTimeout";
|
||||
var DRAFT_TIDDLER_TIMEOUT = 400;
|
||||
var THROTTLE_REFRESH_TIMEOUT = 400;
|
||||
|
||||
exports.startup = function() {
|
||||
// Set up the title
|
||||
@@ -78,12 +78,12 @@ exports.startup = function() {
|
||||
}
|
||||
// Add the change event handler
|
||||
$tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) {
|
||||
// Check if only drafts have changed
|
||||
var onlyDraftsHaveChanged = true;
|
||||
// Check if only tiddlers that are throttled have changed
|
||||
var onlyThrottledTiddlersHaveChanged = true;
|
||||
for(var title in changes) {
|
||||
var tiddler = $tw.wiki.getTiddler(title);
|
||||
if(!tiddler || !tiddler.hasField("draft.of")) {
|
||||
onlyDraftsHaveChanged = false;
|
||||
if(!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh"))) {
|
||||
onlyThrottledTiddlersHaveChanged = false;
|
||||
}
|
||||
}
|
||||
// Defer the change if only drafts have changed
|
||||
@@ -91,10 +91,10 @@ exports.startup = function() {
|
||||
clearTimeout(timerId);
|
||||
}
|
||||
timerId = null;
|
||||
if(onlyDraftsHaveChanged) {
|
||||
if(onlyThrottledTiddlersHaveChanged) {
|
||||
var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10);
|
||||
if(isNaN(timeout)) {
|
||||
timeout = DRAFT_TIDDLER_TIMEOUT;
|
||||
timeout = THROTTLE_REFRESH_TIMEOUT;
|
||||
}
|
||||
timerId = setTimeout(refresh,timeout);
|
||||
$tw.utils.extend(deferredChanges,changes);
|
||||
|
||||
Reference in New Issue
Block a user