1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-26 19:47:20 +00:00

make this work

This commit is contained in:
BurningTreeC 2024-10-15 21:18:56 +02:00
parent 64019cb0b4
commit 9da4964ee9
2 changed files with 36 additions and 20 deletions

View File

@ -59,6 +59,7 @@ exports.startup = function() {
options = options || {}; options = options || {};
// Check if only tiddlers that are throttled have changed // Check if only tiddlers that are throttled have changed
var onlyThrottledTiddlersHaveChanged = true; var onlyThrottledTiddlersHaveChanged = true;
var deferredChanges = options.mainCondition ? mainDeferredChanges : styleDeferredChanges;
for(var title in changes) { for(var title in changes) {
var tiddler = $tw.wiki.getTiddler(title); var tiddler = $tw.wiki.getTiddler(title);
if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") ||
@ -67,19 +68,30 @@ exports.startup = function() {
} }
} }
// Defer the change if only drafts have changed // Defer the change if only drafts have changed
if(options.timerId) { if(options.mainCondition) {
clearTimeout(options.timerId); if(mainTimerId) {
clearTimeout(mainTimerId);
}
mainTimerId = null;
} else if(options.styleCondition) {
if(styleTimerId) {
clearTimeout(styleTimerId);
}
styleTimerId = null;
} }
options.timerId = null;
if(onlyThrottledTiddlersHaveChanged) { if(onlyThrottledTiddlersHaveChanged) {
var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10);
if(isNaN(timeout)) { if(isNaN(timeout)) {
timeout = THROTTLE_REFRESH_TIMEOUT; timeout = THROTTLE_REFRESH_TIMEOUT;
} }
options.timerId = setTimeout(options.throttledRefresh,timeout); if(options.mainCondition) {
$tw.utils.extend(options.deferredChanges,changes); mainTimerId = setTimeout(options.throttledRefresh,timeout);
} else if(options.styleCondition) {
styleTimerId = setTimeout(options.throttledRefresh,timeout);
}
$tw.utils.extend(deferredChanges,changes);
} else { } else {
$tw.utils.extend(options.deferredChanges,changes); $tw.utils.extend(deferredChanges,changes);
options.callback(); options.callback();
} }
}; };
@ -104,8 +116,6 @@ exports.startup = function() {
styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh);
$tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) { $tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) {
throttledRefreshFn(changes,{ throttledRefreshFn(changes,{
deferredChanges: styleDeferredChanges,
timerId: styleTimerId,
throttledRefresh: styleThrottledRefresh, throttledRefresh: styleThrottledRefresh,
callback: styleRefresh, callback: styleRefresh,
mainCondition: false, mainCondition: false,
@ -131,8 +141,6 @@ exports.startup = function() {
// Add the change event handler // Add the change event handler
$tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) { $tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) {
throttledRefreshFn(changes,{ throttledRefreshFn(changes,{
deferredChanges: mainDeferredChanges,
timerId: mainTimerId,
throttledRefresh: mainThrottledRefresh, throttledRefresh: mainThrottledRefresh,
callback: refresh, callback: refresh,
mainCondition: true, mainCondition: true,

View File

@ -89,6 +89,7 @@ exports.startup = function() {
options = options || {}; options = options || {};
// Check if only tiddlers that are throttled have changed // Check if only tiddlers that are throttled have changed
var onlyThrottledTiddlersHaveChanged = true; var onlyThrottledTiddlersHaveChanged = true;
var deferredChanges = options.mainCondition ? mainDeferredChanges : styleDeferredChanges;
for(var title in changes) { for(var title in changes) {
var tiddler = $tw.wiki.getTiddler(title); var tiddler = $tw.wiki.getTiddler(title);
if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") || if(!$tw.wiki.isVolatileTiddler(title) && (!tiddler || !(tiddler.hasField("draft.of") || tiddler.hasField("throttle.refresh") ||
@ -97,19 +98,30 @@ exports.startup = function() {
} }
} }
// Defer the change if only drafts have changed // Defer the change if only drafts have changed
if(options.timerId) { if(options.mainCondition) {
clearTimeout(options.timerId); if(mainTimerId) {
clearTimeout(mainTimerId);
}
mainTimerId = null;
} else if(options.styleCondition) {
if(styleTimerId) {
clearTimeout(styleTimerId);
}
styleTimerId = null;
} }
options.timerId = null;
if(onlyThrottledTiddlersHaveChanged) { if(onlyThrottledTiddlersHaveChanged) {
var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10);
if(isNaN(timeout)) { if(isNaN(timeout)) {
timeout = THROTTLE_REFRESH_TIMEOUT; timeout = THROTTLE_REFRESH_TIMEOUT;
} }
options.timerId = setTimeout(options.throttledRefresh,timeout); if(options.mainCondition) {
$tw.utils.extend(options.deferredChanges,changes); mainTimerId = setTimeout(options.throttledRefresh,timeout);
} else if(options.styleCondition) {
styleTimerId = setTimeout(options.throttledRefresh,timeout);
}
$tw.utils.extend(deferredChanges,changes);
} else { } else {
$tw.utils.extend(options.deferredChanges,changes); $tw.utils.extend(deferredChanges,changes);
options.callback(); options.callback();
} }
}; };
@ -131,8 +143,6 @@ exports.startup = function() {
styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh);
styleRefreshHandler = function(changes) { styleRefreshHandler = function(changes) {
throttledRefreshFn(changes,{ throttledRefreshFn(changes,{
deferredChanged: styleDeferredChanges,
timerId: styleTimerId,
throttledRefresh: styleThrottledRefresh, throttledRefresh: styleThrottledRefresh,
callback: styleRefresh, callback: styleRefresh,
mainCondition: false, mainCondition: false,
@ -141,8 +151,6 @@ exports.startup = function() {
}; };
mainRefreshHandler = function(changes) { mainRefreshHandler = function(changes) {
throttledRefreshFn(changes,{ throttledRefreshFn(changes,{
deferredChanges: mainDeferredChanges,
timerId: mainTimerId,
throttledRefresh: mainThrottledRefresh, throttledRefresh: mainThrottledRefresh,
callback: mainRefresh, callback: mainRefresh,
mainCondition: true, mainCondition: true,