Improve previous commit (faster, remove dependency).

This commit is contained in:
Neil Fraser
2015-02-02 17:00:19 -08:00
parent 43261ef086
commit deb133cc25
2 changed files with 14 additions and 11 deletions

View File

@@ -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;
}
};