From 49405a88bde1e0a958a587313a23769a702fcaea Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Fri, 2 Aug 2019 09:27:25 -0700 Subject: [PATCH] Changed connections to handle disposing of connected blocks. --- core/connection.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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; }; /**