diff --git a/core/connection_db.js b/core/connection_db.js index ce7e9487b..a09a33945 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -49,16 +49,12 @@ Blockly.ConnectionDB = function() { * @param {!Blockly.Connection} connection The connection to be added. */ Blockly.ConnectionDB.prototype.addConnection = function(connection) { - if (connection.inDB_) { - throw Error('Connection already in database.'); - } if (connection.getSourceBlock().isInFlyout) { // Don't bother maintaining a database of connections in a flyout. return; } var position = this.findPositionForConnection_(connection); this.connections_.splice(position, 0, connection); - connection.inDB_ = true; }; /** @@ -136,14 +132,10 @@ Blockly.ConnectionDB.prototype.findPositionForConnection_ = function( * @private */ Blockly.ConnectionDB.prototype.removeConnection_ = function(connection) { - if (!connection.inDB_) { - throw Error('Connection not in database.'); - } var removalIndex = this.findConnection(connection); if (removalIndex == -1) { throw Error('Unable to find connection in connectionDB.'); } - connection.inDB_ = false; this.connections_.splice(removalIndex, 1); }; @@ -207,7 +199,6 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { return neighbours; }; - /** * Is the candidate connection close to the reference connection. * Extremely fast; only looks at Y distance. diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 5320f819d..79d49af69 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -68,18 +68,11 @@ Blockly.RenderedConnection = function(source, type) { this.offsetInBlock_ = new Blockly.utils.Coordinate(0, 0); /** - * Has this connection been added to the connection database? + * Whether this connections is tracked in the database or not. * @type {boolean} * @private */ - this.inDB_ = false; - - /** - * Whether this connections is hidden (not tracked in a database) or not. - * @type {boolean} - * @private - */ - this.hidden_ = !this.db_; + this.tracked_ = false; }; Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection); @@ -87,7 +80,7 @@ Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection); * @override */ Blockly.RenderedConnection.prototype.dispose = function() { - if (this.inDB_) { + if (this.tracked_) { this.db_.removeConnection_(this); } Blockly.RenderedConnection.superClass_.dispose.call(this); @@ -161,16 +154,12 @@ Blockly.RenderedConnection.prototype.bumpAwayFrom_ = function(staticConnection) * @param {number} y New absolute y coordinate, in workspace coordinates. */ Blockly.RenderedConnection.prototype.moveTo = function(x, y) { - // Remove it from its old location in the database (if already present) - if (this.inDB_) { + if (this.tracked_) { this.db_.removeConnection_(this); + this.db_.addConnection(this); } this.x_ = x; this.y_ = y; - // Insert it into its new location in the database. - if (!this.hidden_) { - this.db_.addConnection(this); - } }; /** @@ -338,12 +327,17 @@ Blockly.RenderedConnection.prototype.unhighlight = function() { * @param {boolean} hidden True if connection is hidden. */ Blockly.RenderedConnection.prototype.setHidden = function(hidden) { - this.hidden_ = hidden; - if (hidden && this.inDB_) { - this.db_.removeConnection_(this); - } else if (!hidden && !this.inDB_) { - this.db_.addConnection(this); + // Temporary: if we're setting hidden to true we want to set tracked to false. + var track = !hidden; + if (track == this.tracked_) { + return; } + if (track) { + this.db_.addConnection(this); + } else { + this.db_.removeConnection_(this); + } + this.tracked_ = track; }; /**