mirror of
https://github.com/google/blockly.git
synced 2026-01-14 04:17:10 +01:00
Changed connections to handle disposing of connected blocks.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user