diff --git a/core/block.js b/core/block.js index 139ff002a..f8233f67b 100644 --- a/core/block.js +++ b/core/block.js @@ -819,40 +819,6 @@ Blockly.Block.prototype.setEditable = function(editable) { } }; -/** - * Set whether the connections are hidden (not tracked in a database) or not. - * Recursively walk down all child blocks (except collapsed blocks). - * @param {boolean} hidden True if connections are hidden. - */ -Blockly.Block.prototype.setConnectionsHidden = function(hidden) { - if (!hidden && this.isCollapsed()) { - if (this.outputConnection) { - this.outputConnection.setHidden(hidden); - } - if (this.previousConnection) { - this.previousConnection.setHidden(hidden); - } - if (this.nextConnection) { - this.nextConnection.setHidden(hidden); - var child = this.nextConnection.targetBlock(); - if (child) { - child.setConnectionsHidden(hidden); - } - } - } else { - var myConnections = this.getConnections_(true); - for (var i = 0, connection; connection = myConnections[i]; i++) { - connection.setHidden(hidden); - if (connection.isSuperior()) { - var child = connection.targetBlock(); - if (child) { - child.setConnectionsHidden(hidden); - } - } - } - } -}; - /** * Find the connection on this block that corresponds to the given connection * on the other block. diff --git a/core/block_svg.js b/core/block_svg.js index 4b697eee3..b04f5eccb 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -1437,6 +1437,41 @@ Blockly.BlockSvg.prototype.appendInput_ = function(type, name) { return input; }; +/** + * Set whether the connections are hidden (not tracked in a database) or not. + * Recursively walk down all child blocks (except collapsed blocks). + * @param {boolean} hidden True if connections are hidden. + * @package + */ +Blockly.BlockSvg.prototype.setConnectionsHidden = function(hidden) { + if (!hidden && this.isCollapsed()) { + if (this.outputConnection) { + this.outputConnection.setHidden(hidden); + } + if (this.previousConnection) { + this.previousConnection.setHidden(hidden); + } + if (this.nextConnection) { + this.nextConnection.setHidden(hidden); + var child = this.nextConnection.targetBlock(); + if (child) { + child.setConnectionsHidden(hidden); + } + } + } else { + var myConnections = this.getConnections_(true); + for (var i = 0, connection; connection = myConnections[i]; i++) { + connection.setHidden(hidden); + if (connection.isSuperior()) { + var child = connection.targetBlock(); + if (child) { + child.setConnectionsHidden(hidden); + } + } + } + } +}; + /** * Returns connections originating from this block. * @param {boolean} all If true, return all connections even hidden ones. diff --git a/core/connection.js b/core/connection.js index 13a3f6c6a..082eb9b8c 100644 --- a/core/connection.js +++ b/core/connection.js @@ -45,13 +45,6 @@ Blockly.Connection = function(source, type) { this.sourceBlock_ = source; /** @type {number} */ this.type = type; - // Shortcut for the databases for this connection's workspace. - if (source.workspace.connectionDBList) { - this.db_ = source.workspace.connectionDBList[type]; - this.dbOpposite_ = - source.workspace.connectionDBList[Blockly.OPPOSITE_TYPE[type]]; - this.hidden_ = !this.db_; - } }; /** @@ -106,35 +99,6 @@ Blockly.Connection.prototype.x_ = 0; */ Blockly.Connection.prototype.y_ = 0; -/** - * Has this connection been added to the connection database? - * @type {boolean} - * @protected - */ -Blockly.Connection.prototype.inDB_ = false; - -/** - * Connection database for connections of this type on the current workspace. - * @type {Blockly.ConnectionDB} - * @protected - */ -Blockly.Connection.prototype.db_ = null; - -/** - * Connection database for connections compatible with this type on the - * current workspace. - * @type {Blockly.ConnectionDB} - * @protected - */ -Blockly.Connection.prototype.dbOpposite_ = null; - -/** - * Whether this connections is hidden (not tracked in a database) or not. - * @type {boolean} - * @protected - */ -Blockly.Connection.prototype.hidden_ = null; - /** * Connect two connections together. This is the connection on the superior * block. @@ -259,10 +223,6 @@ Blockly.Connection.prototype.dispose = function() { } } - if (this.inDB_) { - this.db_.removeConnection_(this); - } - this.disposed = true; }; diff --git a/core/rendered_connection.js b/core/rendered_connection.js index 907e20db6..5320f819d 100644 --- a/core/rendered_connection.js +++ b/core/rendered_connection.js @@ -44,15 +44,55 @@ goog.require('Blockly.utils.object'); Blockly.RenderedConnection = function(source, type) { Blockly.RenderedConnection.superClass_.constructor.call(this, source, type); + /** + * Connection database for connections of this type on the current workspace. + * @const {!Blockly.ConnectionDB} + * @private + */ + this.db_ = source.workspace.connectionDBList[type]; + + /** + * Connection database for connections compatible with this type on the + * current workspace. + * @const {!Blockly.ConnectionDB} + * @private + */ + this.dbOpposite_ = source.workspace + .connectionDBList[Blockly.OPPOSITE_TYPE[type]]; + /** * Workspace units, (0, 0) is top left of block. * @type {!Blockly.utils.Coordinate} * @private */ this.offsetInBlock_ = new Blockly.utils.Coordinate(0, 0); + + /** + * Has this connection been added to the connection database? + * @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_; }; Blockly.utils.object.inherits(Blockly.RenderedConnection, Blockly.Connection); +/** + * @override + */ +Blockly.RenderedConnection.prototype.dispose = function() { + if (this.inDB_) { + this.db_.removeConnection_(this); + } + Blockly.RenderedConnection.superClass_.dispose.call(this); +}; + /** * Returns the distance between this connection and another connection in * workspace units. diff --git a/tests/mocha/connection_test.js b/tests/mocha/connection_test.js index 4f84e8ff4..6b98984bc 100644 --- a/tests/mocha/connection_test.js +++ b/tests/mocha/connection_test.js @@ -18,8 +18,7 @@ * limitations under the License. */ -// TODO: Re-enable once headless connections ignore databases. -suite.skip('Connections', function() { +suite('Connections', function() { suite('Can Connect With Reason', function() { test('Target Null', function() { var connection = new Blockly.Connection({}, Blockly.INPUT_VALUE);