From fcebc0979459f8bcaec68e411349ac01b625f229 Mon Sep 17 00:00:00 2001 From: Kabir Shah Date: Thu, 18 Apr 2019 00:33:46 -0700 Subject: [PATCH] async execution of next set of phases --- packages/moon/dist/moon.js | 17 +++++++++++++---- packages/moon/dist/moon.min.js | 2 +- packages/moon/src/executor/executor.js | 19 +++++++++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/packages/moon/dist/moon.js b/packages/moon/dist/moon.js index 4d58328d..aa595d21 100644 --- a/packages/moon/dist/moon.js +++ b/packages/moon/dist/moon.js @@ -934,7 +934,17 @@ executeQueue.shift(); // If there is new data in the execution queue, continue to it. if (executeQueue.length !== 0) { - executeNext(); + if (performance.now() - executeStart >= 16) { + // If the current frame doesn't have sufficient time left to keep + // running then start the next execution in the next frame. + requestAnimationFrame(function () { + executeStart = performance.now(); + executeNext(); + }); + } else { + executeStart = performance.now(); + executeNext(); + } } } /** @@ -944,9 +954,7 @@ function executeNext() { // Get the next data update. - var dataNew = executeQueue[0]; // Record the current time to reference when running different functions. - - executeStart = performance.now(); // Merge new data into current data. + var dataNew = executeQueue[0]; // Merge new data into current data. for (var key in dataNew) { data[key] = dataNew[key]; @@ -988,6 +996,7 @@ executeQueue.push(dataNew); // Execute the next function in the queue if none are scheduled yet. if (executeQueue.length === 1) { + executeStart = performance.now(); executeNext(); } } diff --git a/packages/moon/dist/moon.min.js b/packages/moon/dist/moon.min.js index efa09d01..e7b38c31 100644 --- a/packages/moon/dist/moon.min.js +++ b/packages/moon/dist/moon.min.js @@ -4,4 +4,4 @@ * Released under the MIT License * https://kbrsh.github.io/moon */ -!function(e,n){"undefined"==typeof module?e.Moon=n():module.exports=n()}(this,function(){"use strict";var v={element:0,text:1,component:2};var N=/<([\w\d-_]+)([^>]*?)(\/?)>/g,A=/\s*([\w\d-_:@]*)(?:=(?:("[^"]*"|'[^']*')|{([^{}]*)}))?/g,k=/"[^"]*"|'[^']*'|\d+[a-zA-Z$_]\w*|\.[a-zA-Z$_]\w*|[a-zA-Z$_]\w*:|([a-zA-Z$_]\w*)/g,E=["NaN","false","in","null","this","true","typeof","undefined","window"];function n(e){e=e.trim();for(var n=[],t=0;t",t+2),d=e.slice(t+2,o);0,n.push({type:"tagClose",value:d}),t=o+1;continue}if("!"===a&&"-"===e[t+2]&&"-"===e[t+3]){var i=e.indexOf("--\x3e",t+4);0,t=i+3;continue}N.lastIndex=t;var l=N.exec(e);0;for(var u=l[0],p=l[1],f=l[2],s=l[3],c={},v=void 0;null!==(v=A.exec(f));){var h=v[0],m=v[1],w=v[2],g=v[3];0===h.length?A.lastIndex+=1:c[m]=void 0===g?w:g}n.push({type:"tagOpen",value:p,attributes:c,closed:"/"===s}),t+=u.length}else if("{"===r){var y="";for(t+=1;t]*?)(\/?)>/g,A=/\s*([\w\d-_:@]*)(?:=(?:("[^"]*"|'[^']*')|{([^{}]*)}))?/g,k=/"[^"]*"|'[^']*'|\d+[a-zA-Z$_]\w*|\.[a-zA-Z$_]\w*|[a-zA-Z$_]\w*:|([a-zA-Z$_]\w*)/g,E=["NaN","false","in","null","this","true","typeof","undefined","window"];function n(e){e=e.trim();for(var n=[],t=0;t",t+2),i=e.slice(t+2,o);0,n.push({type:"tagClose",value:i}),t=o+1;continue}if("!"===a&&"-"===e[t+2]&&"-"===e[t+3]){var d=e.indexOf("--\x3e",t+4);0,t=d+3;continue}N.lastIndex=t;var l=N.exec(e);0;for(var u=l[0],p=l[1],f=l[2],s=l[3],c={},v=void 0;null!==(v=A.exec(f));){var h=v[0],m=v[1],w=v[2],g=v[3];0===h.length?A.lastIndex+=1:c[m]=void 0===g?w:g}n.push({type:"tagOpen",value:p,attributes:c,closed:"/"===s}),t+=u.length}else if("{"===r){var y="";for(t+=1;t= 16) { + // If the current frame doesn't have sufficient time left to keep + // running then start the next execution in the next frame. + requestAnimationFrame(() => { + executeStart = performance.now(); + + executeNext(); + }); + } else { + executeStart = performance.now(); + + executeNext(); + } } } @@ -358,9 +370,6 @@ function executeNext() { // Get the next data update. const dataNew = executeQueue[0]; - // Record the current time to reference when running different functions. - executeStart = performance.now(); - // Merge new data into current data. for (let key in dataNew) { data[key] = dataNew[key]; @@ -402,6 +411,8 @@ export function execute(dataNew) { // Execute the next function in the queue if none are scheduled yet. if (executeQueue.length === 1) { + executeStart = performance.now(); + executeNext(); } }