diff --git a/core/connection.js b/core/connection.js index 52e5f9f11..4fafba222 100644 --- a/core/connection.js +++ b/core/connection.js @@ -233,15 +233,29 @@ Blockly.Connection.prototype.connect_ = function(childConnection) { }; /** - * Sever all links to this connection (not including from the source object). + * Dispose of this connection. Deal with connected blocks and remove this + * connection from the database. */ Blockly.Connection.prototype.dispose = function() { + + // isConnected returns true for shadows and non-shadows. if (this.isConnected()) { - throw Error('Disconnect connection before disposing of it.'); + this.setShadowDom(null); + var targetBlock = this.targetBlock(); + if (targetBlock.isShadow()) { + // Destroy the attached shadow block & its children. + targetBlock.dispose(); + } else { + // Disconnect the attached normal block. + targetBlock.unplug(); + } } + if (this.inDB_) { this.db_.removeConnection_(this); } + + this.disposed = true; }; /**