Use goog.array.remove

This commit is contained in:
Neil Fraser
2016-10-04 21:20:07 -07:00
parent 70a8bcd4df
commit bd4c6d096f
3 changed files with 5 additions and 20 deletions

View File

@@ -454,13 +454,7 @@ Blockly.Block.prototype.setParent = function(newParent) {
}
if (this.parentBlock_) {
// Remove this block from the old parent's child list.
var children = this.parentBlock_.childBlocks_;
for (var child, x = 0; child = children[x]; x++) {
if (child == this) {
children.splice(x, 1);
break;
}
}
goog.array.remove(this.parentBlock_.childBlocks_, this);
// Disconnect from superior blocks.
if (this.previousConnection && this.previousConnection.isConnected()) {

View File

@@ -26,6 +26,7 @@
goog.provide('Blockly.Events');
goog.require('goog.array');
goog.require('goog.math.Coordinate');

View File

@@ -26,6 +26,7 @@
goog.provide('Blockly.Workspace');
goog.require('goog.array');
goog.require('goog.math');
@@ -136,15 +137,7 @@ Blockly.Workspace.prototype.addTopBlock = function(block) {
* @param {!Blockly.Block} block Block to remove.
*/
Blockly.Workspace.prototype.removeTopBlock = function(block) {
var found = false;
for (var child, i = 0; child = this.topBlocks_[i]; i++) {
if (child == block) {
this.topBlocks_.splice(i, 1);
found = true;
break;
}
}
if (!found) {
if (!goog.array.remove(this.topBlocks_, block)) {
throw 'Block not present in workspace\'s list of top-most blocks.';
}
};
@@ -444,10 +437,7 @@ Blockly.Workspace.prototype.addChangeListener = function(func) {
* @param {Function} func Function to stop calling.
*/
Blockly.Workspace.prototype.removeChangeListener = function(func) {
var i = this.listeners_.indexOf(func);
if (i != -1) {
this.listeners_.splice(i, 1);
}
goog.array.remove(this.listeners_, func);
};
/**