From db98e56e726633cac127f62df04886fbf52a518e Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 22 Sep 2017 17:33:46 +0000 Subject: [PATCH] Reduced extraneous auto bakes --- src/core/operations/Hash.js | 2 +- src/web/App.js | 20 +++++++++++++------- src/web/ControlsWaiter.js | 1 + src/web/InputWaiter.js | 2 -- src/web/Manager.js | 5 ++--- src/web/RecipeWaiter.js | 2 +- 6 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/core/operations/Hash.js b/src/core/operations/Hash.js index 3a59abcd..b165f51e 100755 --- a/src/core/operations/Hash.js +++ b/src/core/operations/Hash.js @@ -280,7 +280,7 @@ const Hash = { * @default */ WHIRLPOOL_VARIANT: ["Whirlpool", "Whirlpool-T", "Whirlpool-0"], - + /** * Whirlpool operation. * diff --git a/src/web/App.js b/src/web/App.js index 53c0158f..ef3dc3f6 100755 --- a/src/web/App.js +++ b/src/web/App.js @@ -122,7 +122,12 @@ App.prototype.bake = function(step) { * Runs Auto Bake if it is set. */ App.prototype.autoBake = function() { - if (this.autoBake_ && !this.autoBakePause && !this.baking) { + // If autoBakePause is set, we are loading a full recipe (and potentially input), so there is no + // need to set the staleness indicator. Just exit and wait until auto bake is called after loading + // has completed. + if (this.autoBakePause) return false; + + if (this.autoBake_ && !this.baking) { this.bake(); } else { this.manager.controls.showStaleIndicator(); @@ -369,10 +374,6 @@ App.prototype.loadURIParams = function() { window.location.hash; this.uriParams = Utils.parseURIParams(params); - // Pause auto-bake while loading but don't modify `this.autoBake_` - // otherwise `manualBake` cannot trigger. - this.autoBakePause = true; - // Read in recipe from URI params if (this.uriParams.recipe) { try { @@ -407,8 +408,6 @@ App.prototype.loadURIParams = function() { } catch (err) {} } - // Unpause auto-bake - this.autoBakePause = false; this.autoBake(); }; @@ -441,6 +440,10 @@ App.prototype.getRecipeConfig = function() { App.prototype.setRecipeConfig = function(recipeConfig) { document.getElementById("rec-list").innerHTML = null; + // Pause auto-bake while loading but don't modify `this.autoBake_` + // otherwise `manualBake` cannot trigger. + this.autoBakePause = true; + for (let i = 0; i < recipeConfig.length; i++) { const item = this.manager.recipe.addOperation(recipeConfig[i].op); @@ -473,6 +476,9 @@ App.prototype.setRecipeConfig = function(recipeConfig) { this.progress = 0; } + + // Unpause auto bake + this.autoBakePause = false; }; diff --git a/src/web/ControlsWaiter.js b/src/web/ControlsWaiter.js index 85982e46..a49ad4fa 100755 --- a/src/web/ControlsWaiter.js +++ b/src/web/ControlsWaiter.js @@ -361,6 +361,7 @@ ControlsWaiter.prototype.loadButtonClick = function() { try { const recipeConfig = Utils.parseRecipeConfig(document.getElementById("load-text").value); this.app.setRecipeConfig(recipeConfig); + this.app.autoBake(); $("#rec-list [data-toggle=popover]").popover(); } catch (e) { diff --git a/src/web/InputWaiter.js b/src/web/InputWaiter.js index b771be2a..aba57334 100755 --- a/src/web/InputWaiter.js +++ b/src/web/InputWaiter.js @@ -158,13 +158,11 @@ InputWaiter.prototype.inputDrop = function(e) { const CHUNK_SIZE = 20480; // 20KB const setInput = function() { - this.app.autoBakePause = true; const recipeConfig = this.app.getRecipeConfig(); if (!recipeConfig[0] || recipeConfig[0].op !== "From Hex") { recipeConfig.unshift({op: "From Hex", args: ["Space"]}); this.app.setRecipeConfig(recipeConfig); } - this.app.autoBakePause = false; this.set(inputCharcode); diff --git a/src/web/Manager.js b/src/web/Manager.js index 39efc458..1d32758c 100755 --- a/src/web/Manager.js +++ b/src/web/Manager.js @@ -119,9 +119,8 @@ Manager.prototype.initialiseEventListeners = function() { this.addDynamicListener("li.operation", "operationadd", this.recipe.opAdd.bind(this.recipe)); // Recipe - this.addDynamicListener(".arg", "keyup", this.recipe.ingChange, this.recipe); - this.addDynamicListener(".arg", "change", this.recipe.ingChange, this.recipe); - this.addDynamicListener(".arg", "input", this.recipe.ingChange, this.recipe); + this.addDynamicListener(".arg:not(select)", "input", this.recipe.ingChange, this.recipe); + this.addDynamicListener(".arg[type=checkbox], .arg[type=radio], select.arg", "change", this.recipe.ingChange, this.recipe); this.addDynamicListener(".disable-icon", "click", this.recipe.disableClick, this.recipe); this.addDynamicListener(".breakpoint", "click", this.recipe.breakpointClick, this.recipe); this.addDynamicListener("#rec-list li.operation", "dblclick", this.recipe.operationDblclick, this.recipe); diff --git a/src/web/RecipeWaiter.js b/src/web/RecipeWaiter.js index 80c2fe96..121b64d2 100755 --- a/src/web/RecipeWaiter.js +++ b/src/web/RecipeWaiter.js @@ -191,7 +191,7 @@ RecipeWaiter.prototype.favDrop = function(e) { * * @fires Manager#statechange */ -RecipeWaiter.prototype.ingChange = function() { +RecipeWaiter.prototype.ingChange = function(e) { window.dispatchEvent(this.manager.statechange); };