From deb133cc2517e954c468dbed3300561bd9ead046 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 2 Feb 2015 17:00:19 -0800 Subject: [PATCH] Improve previous commit (faster, remove dependency). --- blocks/logic.js | 21 ++++++++++++--------- blocks_compressed.js | 4 ++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/blocks/logic.js b/blocks/logic.js index 5a66ae2d5..8846b7141 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -299,6 +299,7 @@ Blockly.Blocks['logic_compare'] = { }; return TOOLTIPS[op]; }); + this.prevBlocks_ = [null, null]; }, /** * Called whenever anything on the workspace changes. @@ -312,18 +313,20 @@ Blockly.Blocks['logic_compare'] = { } var blockA = this.getInputTargetBlock('A'); var blockB = this.getInputTargetBlock('B'); - // Kick blocks that existed prior to this change if they don't match - if (this.blocks_ && blockA && blockB && - !blockA.outputConnection.checkType_(blockB.outputConnection)) { + // Kick blocks that existed prior to this change if they don't match. + if (blockA && blockB && + !blockA.outputConnection.checkType_(blockB.outputConnection)) { // Mismatch between two inputs. Disconnect previous and bump it away. - goog.array.forEach(this.blocks_, function(e) { - if (e === blockA || e === blockB) { - e.setParent(null); - e.bumpNeighbours_(); + for (var i = 0; i < this.prevBlocks_.length; i++) { + var block = this.prevBlocks_[i]; + if (block === blockA || block === blockB) { + block.setParent(null); + block.bumpNeighbours_(); } - }); + } } - this.blocks_ = [blockA, blockB]; + this.prevBlocks_[0] = blockA; + this.prevBlocks_[1] = blockB; } }; diff --git a/blocks_compressed.js b/blocks_compressed.js index 0e42fe733..77f8f6462 100644 --- a/blocks_compressed.js +++ b/blocks_compressed.js @@ -47,8 +47,8 @@ b++;break;case "controls_if_else":d=this.getInput("ELSE");a.statementConnection_ Blockly.Blocks.controls_if_elseif={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_ELSEIF_TITLE_ELSEIF);this.setPreviousStatement(!0);this.setNextStatement(!0);this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSEIF_TOOLTIP);this.contextMenu=!1}}; Blockly.Blocks.controls_if_else={init:function(){this.setColour(Blockly.Blocks.logic.HUE);this.appendDummyInput().appendField(Blockly.Msg.CONTROLS_IF_ELSE_TITLE_ELSE);this.setPreviousStatement(!0);this.setTooltip(Blockly.Msg.CONTROLS_IF_ELSE_TOOLTIP);this.contextMenu=!1}}; Blockly.Blocks.logic_compare={init:function(){var a=Blockly.RTL?[["=","EQ"],["\u2260","NEQ"],[">","LT"],["\u2265","LTE"],["<","GT"],["\u2264","GTE"]]:[["=","EQ"],["\u2260","NEQ"],["<","LT"],["\u2264","LTE"],[">","GT"],["\u2265","GTE"]];this.setHelpUrl(Blockly.Msg.LOGIC_COMPARE_HELPURL);this.setColour(Blockly.Blocks.logic.HUE);this.setOutput(!0,"Boolean");this.appendValueInput("A");this.appendValueInput("B").appendField(new Blockly.FieldDropdown(a),"OP");this.setInputsInline(!0);var b=this;this.setTooltip(function(){var a= -b.getFieldValue("OP");return{EQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,NEQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,LT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,LTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,GT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,GTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE}[a]})},onchange:function(){if(this.workspace){var a=this.getInputTargetBlock("A"),b=this.getInputTargetBlock("B");a&&!b?this.blockAPriority_=!1:!a&&b?this.blockAPriority_=!0:a&&b&&!a.outputConnection.checkType_(b.outputConnection)&& -(a=this.blockAPriority_?b:a,a.setParent(null),a.bumpNeighbours_())}}}; +b.getFieldValue("OP");return{EQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_EQ,NEQ:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_NEQ,LT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LT,LTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_LTE,GT:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GT,GTE:Blockly.Msg.LOGIC_COMPARE_TOOLTIP_GTE}[a]});this.prevBlocks_=[null,null]},onchange:function(){if(this.workspace){var a=this.getInputTargetBlock("A"),b=this.getInputTargetBlock("B");if(a&&b&&!a.outputConnection.checkType_(b.outputConnection))for(var c=0;c