Move block database to workspace.

This commit is contained in:
Neil Fraser
2016-04-05 18:43:39 -07:00
parent 4e42a1b78e
commit 61b3fbfe11
5 changed files with 29 additions and 30 deletions

View File

@@ -51,6 +51,8 @@ Blockly.Workspace = function(opt_options) {
this.undoStack_ = [];
/** @type {!Array.<!Blockly.Events.Abstract>} */
this.redoStack_ = [];
/** @type {!Object} */
this.blockDB_ = Object.create(null);
};
/**
@@ -289,6 +291,15 @@ Blockly.Workspace.prototype.fireChangeListener = function(event) {
}
};
/**
* Find the block on this workspace with the specified ID.
* @param {string} id ID of block to find.
* @return {Blockly.Block} The sought after block or null if not found.
*/
Blockly.Workspace.prototype.getBlockById = function(id) {
return this.blockDB_[id] || null;
};
/**
* Database of all workspaces.
* @private