mirror of
https://github.com/google/blockly.git
synced 2026-01-08 09:30:06 +01:00
Refactor workspace.connectionDBList
It seems wrong that Blockly.ConnectionDB.init reaches in to create a property on workspace. It seems wrong that this database isn’t disposed of when the workspace is. It seems unnecessary that disposed connections need to drop their reference *to* the workspace’s database since the connection object is going away anyway, and the databases aren’t.
This commit is contained in:
@@ -242,8 +242,6 @@ Blockly.Connection.prototype.dispose = function() {
|
||||
if (this.inDB_) {
|
||||
this.db_.removeConnection_(this);
|
||||
}
|
||||
this.db_ = null;
|
||||
this.dbOpposite_ = null;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -287,15 +287,15 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius,
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize a set of connection DBs for a specified workspace.
|
||||
* @param {!Blockly.Workspace} workspace The workspace this DB is for.
|
||||
* Initialize a set of connection DBs for a workspace.
|
||||
* @return {!Array.<!Blockly.ConnectionDB>} Array of databases.
|
||||
*/
|
||||
Blockly.ConnectionDB.init = function(workspace) {
|
||||
Blockly.ConnectionDB.init = function() {
|
||||
// Create four databases, one for each connection type.
|
||||
var dbList = [];
|
||||
dbList[Blockly.INPUT_VALUE] = new Blockly.ConnectionDB();
|
||||
dbList[Blockly.OUTPUT_VALUE] = new Blockly.ConnectionDB();
|
||||
dbList[Blockly.NEXT_STATEMENT] = new Blockly.ConnectionDB();
|
||||
dbList[Blockly.PREVIOUS_STATEMENT] = new Blockly.ConnectionDB();
|
||||
workspace.connectionDBList = dbList;
|
||||
return dbList;
|
||||
};
|
||||
|
||||
@@ -135,6 +135,12 @@ Blockly.Workspace.prototype.isClearing = false;
|
||||
*/
|
||||
Blockly.Workspace.prototype.MAX_UNDO = 1024;
|
||||
|
||||
/**
|
||||
* Set of databases for rapid lookup of connection locations.
|
||||
* @type {Array.<!Blockly.ConnectionDB>}
|
||||
*/
|
||||
Blockly.Workspace.prototype.connectionDBList = null;
|
||||
|
||||
/**
|
||||
* Dispose of this workspace.
|
||||
* Unlink from all DOM elements to prevent memory leaks.
|
||||
|
||||
@@ -74,7 +74,7 @@ Blockly.WorkspaceSvg = function(options,
|
||||
this.setMetrics =
|
||||
options.setMetrics || Blockly.WorkspaceSvg.setTopLevelWorkspaceMetrics_;
|
||||
|
||||
Blockly.ConnectionDB.init(this);
|
||||
this.connectionDBList = Blockly.ConnectionDB.init();
|
||||
|
||||
if (opt_blockDragSurface) {
|
||||
this.blockDragSurface_ = opt_blockDragSurface;
|
||||
@@ -607,6 +607,8 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
|
||||
this.grid_ = null;
|
||||
}
|
||||
|
||||
this.connectionDBList = null;
|
||||
|
||||
this.toolboxCategoryCallbacks_ = null;
|
||||
this.flyoutButtonCallbacks_ = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user