Changed connections to handle disposing of connected blocks.

This commit is contained in:
Beka Westberg
2019-08-02 09:27:25 -07:00
parent f34f2beac7
commit 49405a88bd

View File

@@ -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;
};
/**