Remove goog.array

This commit is contained in:
Neil Fraser
2018-06-10 22:51:55 -07:00
committed by Neil Fraser
parent 03bf9f5e71
commit 06d90c9b34
11 changed files with 36 additions and 22 deletions

View File

@@ -36,10 +36,11 @@ goog.require('Blockly.Events.BlockMove');
goog.require('Blockly.Extensions');
goog.require('Blockly.Input');
goog.require('Blockly.Mutator');
goog.require('Blockly.utils');
goog.require('Blockly.Warning');
goog.require('Blockly.Workspace');
goog.require('Blockly.Xml');
goog.require('goog.array');
goog.require('goog.math.Coordinate');
@@ -496,7 +497,7 @@ Blockly.Block.prototype.setParent = function(newParent) {
}
if (this.parentBlock_) {
// Remove this block from the old parent's child list.
goog.array.remove(this.parentBlock_.childBlocks_, this);
Blockly.utils.arrayRemove(this.parentBlock_.childBlocks_, this);
// Disconnect from superior blocks.
if (this.previousConnection && this.previousConnection.isConnected()) {
@@ -1444,7 +1445,7 @@ Blockly.Block.prototype.removeInput = function(name, opt_quiet) {
}
}
if (!opt_quiet) {
throw ReferenceErrer('Input not found: ' + name);
throw ReferenceError('Input not found: ' + name);
}
};

View File

@@ -37,7 +37,6 @@ goog.provide('Blockly.Events.Move'); // Deprecated.
goog.require('Blockly.Events');
goog.require('Blockly.Events.Abstract');
goog.require('goog.array');
goog.require('goog.math.Coordinate');

View File

@@ -37,6 +37,7 @@ goog.require('Blockly.Tooltip');
goog.require('Blockly.Touch');
goog.require('Blockly.utils');
goog.require('goog.color');
goog.require('goog.dom');
goog.require('goog.math.Coordinate');

View File

@@ -654,9 +654,13 @@ Blockly.Connection.prototype.toString = function() {
} else if (block.nextConnection == this) {
msg = 'Next Connection of ';
} else {
var parentInput = goog.array.find(block.inputList, function(input) {
return input.connection == this;
}, this);
var parentInput = null;
for (var i = 0, input; input = block.inputList[i]; i++) {
if (input.connection == this) {
parentInput = input;
break;
}
}
if (parentInput) {
msg = 'Input "' + parentInput.name + '" connection on ';
} else {

View File

@@ -30,7 +30,6 @@
*/
goog.provide('Blockly.Events');
goog.require('goog.array');
goog.require('goog.math.Coordinate');
@@ -193,7 +192,7 @@ Blockly.Events.fireNow_ = function() {
* @return {!Array.<!Blockly.Events.Abstract>} Array of filtered events.
*/
Blockly.Events.filter = function(queueIn, forward) {
var queue = goog.array.clone(queueIn);
var queue = queueIn.slice(); // Shallow copy of queue.
if (!forward) {
// Undo is merged in reverse order.
queue.reverse();

View File

@@ -28,8 +28,6 @@
goog.provide('Blockly.Events.Abstract');
goog.require('Blockly.Events');
goog.require('goog.array');
goog.require('goog.math.Coordinate');
/**
* Abstract class for an event.

View File

@@ -29,8 +29,6 @@ goog.provide('Blockly.Events.Ui');
goog.require('Blockly.Events');
goog.require('Blockly.Events.Abstract');
goog.require('goog.array');
goog.require('goog.math.Coordinate');
/**
* Class for a UI event.

View File

@@ -912,3 +912,19 @@ Blockly.utils.getViewportBBox = function() {
Blockly.utils.startsWith = function(str, prefix) {
return str.lastIndexOf(prefix, 0) == 0;
};
/**
* Removes the first occurrence of a particular value from an array.
* @param {!Array} arr Array from which to remove
* value.
* @param {*} obj Object to remove.
* @return {boolean} True if an element was removed.
*/
Blockly.utils.arrayRemove = function(arr, obj) {
var i = arr.indexOf(obj);
if (i == -1) {
return false;
}
arr.splice(i, 1);
return true;
};

View File

@@ -32,9 +32,6 @@ goog.provide('Blockly.Events.VarRename');
goog.require('Blockly.Events');
goog.require('Blockly.Events.Abstract');
goog.require('goog.array');
goog.require('goog.math.Coordinate');
/**
* Abstract class for a variable event.

View File

@@ -26,9 +26,10 @@
goog.provide('Blockly.Workspace');
goog.require('Blockly.utils');
goog.require('Blockly.VariableMap');
goog.require('Blockly.WorkspaceComment');
goog.require('goog.array');
goog.require('goog.math');
@@ -160,7 +161,7 @@ Blockly.Workspace.prototype.addTopBlock = function(block) {
* @param {!Blockly.Block} block Block to remove.
*/
Blockly.Workspace.prototype.removeTopBlock = function(block) {
if (!goog.array.remove(this.topBlocks_, block)) {
if (!Blockly.utils.arrayRemove(this.topBlocks_, block)) {
throw Error('Block not present in workspace\'s list of top-most blocks.');
}
};
@@ -211,7 +212,7 @@ Blockly.Workspace.prototype.addTopComment = function(comment) {
* @package
*/
Blockly.Workspace.prototype.removeTopComment = function(comment) {
if (!goog.array.remove(this.topComments_, comment)) {
if (!Blockly.utils.arrayRemove(this.topComments_, comment)) {
throw Error('Comment not present in workspace\'s list of top-most ' +
'comments.');
}
@@ -511,7 +512,7 @@ Blockly.Workspace.prototype.addChangeListener = function(func) {
* @param {Function} func Function to stop calling.
*/
Blockly.Workspace.prototype.removeChangeListener = function(func) {
goog.array.remove(this.listeners_, func);
Blockly.utils.arrayRemove(this.listeners_, func);
};
/**

View File

@@ -38,6 +38,7 @@ goog.require('Blockly.ScrollbarPair');
goog.require('Blockly.Touch');
goog.require('Blockly.TouchGesture');
goog.require('Blockly.Trashcan');
goog.require('Blockly.utils');
goog.require('Blockly.VariablesDynamic');
goog.require('Blockly.Workspace');
goog.require('Blockly.WorkspaceAudio');
@@ -48,7 +49,6 @@ goog.require('Blockly.WorkspaceDragSurfaceSvg');
goog.require('Blockly.Xml');
goog.require('Blockly.ZoomControls');
goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.math.Coordinate');
@@ -926,7 +926,7 @@ Blockly.WorkspaceSvg.prototype.highlightBlock = function(id, opt_state) {
var state = (opt_state === undefined) || opt_state;
// Using Set here would be great, but at the cost of IE10 support.
if (!state) {
goog.array.remove(this.highlightedBlocks_, block);
Blockly.utils.arrayRemove(this.highlightedBlocks_, block);
} else if (this.highlightedBlocks_.indexOf(block) == -1) {
this.highlightedBlocks_.push(block);
}