diff --git a/core/modules/startup/render.js b/core/modules/startup/render.js index 5453a0c7e..10a90b938 100644 --- a/core/modules/startup/render.js +++ b/core/modules/startup/render.js @@ -59,6 +59,7 @@ exports.startup = function() { options = options || {}; // Check if only tiddlers that are throttled have changed var onlyThrottledTiddlersHaveChanged = true; + var deferredChanges = options.mainCondition ? mainDeferredChanges : styleDeferredChanges; for(var title in changes) { var tiddler = $tw.wiki.getTiddler(title); 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 - if(options.timerId) { - clearTimeout(options.timerId); + if(options.mainCondition) { + if(mainTimerId) { + clearTimeout(mainTimerId); + } + mainTimerId = null; + } else if(options.styleCondition) { + if(styleTimerId) { + clearTimeout(styleTimerId); + } + styleTimerId = null; } - options.timerId = null; if(onlyThrottledTiddlersHaveChanged) { var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); if(isNaN(timeout)) { timeout = THROTTLE_REFRESH_TIMEOUT; } - options.timerId = setTimeout(options.throttledRefresh,timeout); - $tw.utils.extend(options.deferredChanges,changes); + if(options.mainCondition) { + mainTimerId = setTimeout(options.throttledRefresh,timeout); + } else if(options.styleCondition) { + styleTimerId = setTimeout(options.throttledRefresh,timeout); + } + $tw.utils.extend(deferredChanges,changes); } else { - $tw.utils.extend(options.deferredChanges,changes); + $tw.utils.extend(deferredChanges,changes); options.callback(); } }; @@ -104,8 +116,6 @@ exports.startup = function() { styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); $tw.wiki.addEventListener("change",$tw.perf.report("styleRefresh",function(changes) { throttledRefreshFn(changes,{ - deferredChanges: styleDeferredChanges, - timerId: styleTimerId, throttledRefresh: styleThrottledRefresh, callback: styleRefresh, mainCondition: false, @@ -131,8 +141,6 @@ exports.startup = function() { // Add the change event handler $tw.wiki.addEventListener("change",$tw.perf.report("mainRefresh",function(changes) { throttledRefreshFn(changes,{ - deferredChanges: mainDeferredChanges, - timerId: mainTimerId, throttledRefresh: mainThrottledRefresh, callback: refresh, mainCondition: true, diff --git a/core/modules/startup/windows.js b/core/modules/startup/windows.js index 52b389fd9..83d136f8f 100644 --- a/core/modules/startup/windows.js +++ b/core/modules/startup/windows.js @@ -89,6 +89,7 @@ exports.startup = function() { options = options || {}; // Check if only tiddlers that are throttled have changed var onlyThrottledTiddlersHaveChanged = true; + var deferredChanges = options.mainCondition ? mainDeferredChanges : styleDeferredChanges; for(var title in changes) { var tiddler = $tw.wiki.getTiddler(title); 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 - if(options.timerId) { - clearTimeout(options.timerId); + if(options.mainCondition) { + if(mainTimerId) { + clearTimeout(mainTimerId); + } + mainTimerId = null; + } else if(options.styleCondition) { + if(styleTimerId) { + clearTimeout(styleTimerId); + } + styleTimerId = null; } - options.timerId = null; if(onlyThrottledTiddlersHaveChanged) { var timeout = parseInt($tw.wiki.getTiddlerText(DRAFT_TIDDLER_TIMEOUT_TITLE,""),10); if(isNaN(timeout)) { timeout = THROTTLE_REFRESH_TIMEOUT; } - options.timerId = setTimeout(options.throttledRefresh,timeout); - $tw.utils.extend(options.deferredChanges,changes); + if(options.mainCondition) { + mainTimerId = setTimeout(options.throttledRefresh,timeout); + } else if(options.styleCondition) { + styleTimerId = setTimeout(options.throttledRefresh,timeout); + } + $tw.utils.extend(deferredChanges,changes); } else { - $tw.utils.extend(options.deferredChanges,changes); + $tw.utils.extend(deferredChanges,changes); options.callback(); } }; @@ -131,8 +143,6 @@ exports.startup = function() { styleThrottledRefresh = $tw.perf.report("throttledStyleRefresh",styleRefresh); styleRefreshHandler = function(changes) { throttledRefreshFn(changes,{ - deferredChanged: styleDeferredChanges, - timerId: styleTimerId, throttledRefresh: styleThrottledRefresh, callback: styleRefresh, mainCondition: false, @@ -141,8 +151,6 @@ exports.startup = function() { }; mainRefreshHandler = function(changes) { throttledRefreshFn(changes,{ - deferredChanges: mainDeferredChanges, - timerId: mainTimerId, throttledRefresh: mainThrottledRefresh, callback: mainRefresh, mainCondition: true,