mirror of
https://github.com/google/blockly.git
synced 2026-01-11 02:47:09 +01:00
Use Blockly.utils.arrayRemove (#5420)
Recently added code doesn't use existing utility function.
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
|
||||
goog.provide('Blockly.ComponentManager');
|
||||
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.requireType('Blockly.IAutoHideable');
|
||||
goog.requireType('Blockly.IComponent');
|
||||
goog.requireType('Blockly.IDeleteArea');
|
||||
@@ -93,8 +95,7 @@ Blockly.ComponentManager.prototype.removeComponent = function(id) {
|
||||
}
|
||||
for (var i = 0; i < componentInfo.capabilities.length; i++) {
|
||||
var capability = String(componentInfo.capabilities[i]).toLowerCase();
|
||||
this.capabilityToComponentIds_[capability].splice(
|
||||
this.capabilityToComponentIds_[capability].indexOf(id), 1);
|
||||
Blockly.utils.arrayRemove(this.capabilityToComponentIds_[capability], id);
|
||||
}
|
||||
delete this.componentData_[id];
|
||||
};
|
||||
@@ -139,10 +140,8 @@ Blockly.ComponentManager.prototype.removeCapability = function(id, capability) {
|
||||
return;
|
||||
}
|
||||
capability = String(capability).toLowerCase();
|
||||
this.componentData_[id].capabilities.splice(
|
||||
this.componentData_[id].capabilities.indexOf(capability), 1);
|
||||
this.capabilityToComponentIds_[capability].splice(
|
||||
this.capabilityToComponentIds_[capability].indexOf(id), 1);
|
||||
Blockly.utils.arrayRemove(this.componentData_[id].capabilities, capability);
|
||||
Blockly.utils.arrayRemove(this.capabilityToComponentIds_[capability], id);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
goog.provide('Blockly.ThemeManager');
|
||||
|
||||
goog.require('Blockly.Theme');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.requireType('Blockly.Workspace');
|
||||
goog.requireType('Blockly.WorkspaceSvg');
|
||||
@@ -129,11 +130,9 @@ Blockly.ThemeManager.prototype.subscribeWorkspace = function(workspace) {
|
||||
* @package
|
||||
*/
|
||||
Blockly.ThemeManager.prototype.unsubscribeWorkspace = function(workspace) {
|
||||
var index = this.subscribedWorkspaces_.indexOf(workspace);
|
||||
if (index < 0) {
|
||||
if (!Blockly.utils.arrayRemove(this.subscribedWorkspaces_, workspace)) {
|
||||
throw Error('Cannot unsubscribe a workspace that hasn\'t been subscribed.');
|
||||
}
|
||||
this.subscribedWorkspaces_.splice(index, 1);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -519,14 +519,13 @@ Blockly.utils.getViewportBBox = function() {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param {!Array} arr Array from which to remove value.
|
||||
* @param {*} value Value to remove.
|
||||
* @return {boolean} True if an element was removed.
|
||||
* @package
|
||||
*/
|
||||
Blockly.utils.arrayRemove = function(arr, obj) {
|
||||
var i = arr.indexOf(obj);
|
||||
Blockly.utils.arrayRemove = function(arr, value) {
|
||||
var i = arr.indexOf(value);
|
||||
if (i == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -149,10 +149,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable,
|
||||
Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))(
|
||||
variable));
|
||||
// And remove it from the list.
|
||||
var variableList = this.getVariablesOfType(type);
|
||||
var variableIndex = variableList.indexOf(variable);
|
||||
this.variableMap_[type].splice(variableIndex, 1);
|
||||
|
||||
Blockly.utils.arrayRemove(this.variableMap_[type], variable);
|
||||
};
|
||||
|
||||
/* End functions for renaming variables. */
|
||||
@@ -205,9 +202,10 @@ Blockly.VariableMap.prototype.createVariable = function(name,
|
||||
* @param {!Blockly.VariableModel} variable Variable to delete.
|
||||
*/
|
||||
Blockly.VariableMap.prototype.deleteVariable = function(variable) {
|
||||
var variableId = variable.getId();
|
||||
var variableList = this.variableMap_[variable.type];
|
||||
for (var i = 0, tempVar; (tempVar = variableList[i]); i++) {
|
||||
if (tempVar.getId() == variable.getId()) {
|
||||
if (tempVar.getId() == variableId) {
|
||||
variableList.splice(i, 1);
|
||||
Blockly.Events.fire(new (Blockly.Events.get(Blockly.Events.VAR_DELETE))(
|
||||
variable));
|
||||
|
||||
@@ -240,8 +240,7 @@ Blockly.Workspace.prototype.addTypedBlock = function(block) {
|
||||
* @param {!Blockly.Block} block Block to remove.
|
||||
*/
|
||||
Blockly.Workspace.prototype.removeTypedBlock = function(block) {
|
||||
this.typedBlocksDB_[block.type].splice(this.typedBlocksDB_[block.type]
|
||||
.indexOf(block), 1);
|
||||
Blockly.utils.arrayRemove(this.typedBlocksDB_[block.type], block);
|
||||
if (!this.typedBlocksDB_[block.type].length) {
|
||||
delete this.typedBlocksDB_[block.type];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user