Rename stacks to scripts

Further pushing toward removing ambiguity of what "stack" means in the codebase.
This commit is contained in:
Tim Mickel 2016-08-11 11:11:27 -04:00
parent caab305b52
commit 4faaf1b685
3 changed files with 68 additions and 68 deletions
src/engine

View file

@ -15,11 +15,11 @@ function Blocks () {
this._blocks = {};
/**
* All stacks in the workspace.
* A list of block IDs that represent stacks (first block in stack).
* All top-level scripts in the workspace.
* A list of block IDs that represent scripts (i.e., first block in script).
* @type {Array.<String>}
*/
this._stacks = [];
this._scripts = [];
}
/**
@ -39,11 +39,11 @@ Blocks.prototype.getBlock = function (blockId) {
};
/**
* Get all known top-level blocks that start stacks.
* Get all known top-level blocks that start scripts.
* @return {Array.<string>} List of block IDs.
*/
Blocks.prototype.getStacks = function () {
return this._stacks;
Blocks.prototype.getScripts = function () {
return this._scripts;
};
/**
@ -136,10 +136,10 @@ Blocks.prototype.generateBlockListener = function (isFlyout, opt_runtime) {
if (typeof e !== 'object') return;
if (typeof e.blockId !== 'string') return;
// UI event: clicked stacks toggle in the runtime.
// UI event: clicked scripts toggle in the runtime.
if (e.element === 'stackclick') {
if (opt_runtime) {
opt_runtime.toggleStack(e.blockId);
opt_runtime.toggleScript(e.blockId);
}
return;
}
@ -182,7 +182,7 @@ Blocks.prototype.generateBlockListener = function (isFlyout, opt_runtime) {
// ---------------------------------------------------------------------
/**
* Block management: create blocks and stacks from a `create` event
* Block management: create blocks and scripts from a `create` event
* @param {!Object} block Blockly create event to be processed
* @param {boolean} opt_isFlyoutBlock Whether the block is in the flyout.
*/
@ -190,12 +190,12 @@ Blocks.prototype.createBlock = function (block, opt_isFlyoutBlock) {
// Create new block
this._blocks[block.id] = block;
// Push block id to stacks array.
// Push block id to scripts array.
// Blocks are added as a top-level stack if they are marked as a top-block
// (if they were top-level XML in the event) and if they are not
// flyout blocks.
if (!opt_isFlyoutBlock && block.topLevel) {
this._addStack(block.id);
this._addScript(block.id);
}
};
@ -233,10 +233,10 @@ Blocks.prototype.moveBlock = function (e) {
// Has the block become a top-level block?
if (e.newParent === undefined) {
this._addStack(e.id);
this._addScript(e.id);
} else {
// Remove stack, if one exists.
this._deleteStack(e.id);
// Remove script, if one exists.
this._deleteScript(e.id);
// Otherwise, try to connect it in its new place.
if (e.newInput !== undefined) {
// Moved to the new parent's input.
@ -252,11 +252,11 @@ Blocks.prototype.moveBlock = function (e) {
};
/**
* Block management: delete blocks and their associated stacks
* @param {!Object} e Blockly delete event to be processed
* Block management: delete blocks and their associated scripts.
* @param {!Object} e Blockly delete event to be processed.
*/
Blocks.prototype.deleteBlock = function (e) {
// @todo In runtime, stop threads running on this stack
// @todo In runtime, stop threads running on this script.
// Get block
var block = this._blocks[e.id];
@ -274,36 +274,36 @@ Blocks.prototype.deleteBlock = function (e) {
}
}
// Delete stack
this._deleteStack(e.id);
// Delete any script starting with this block.
this._deleteScript(e.id);
// Delete block
// Delete block itself.
delete this._blocks[e.id];
};
// ---------------------------------------------------------------------
/**
* Helper to add a stack to `this._stacks`
* @param {?string} id ID of block that starts the stack
* Helper to add a stack to `this._scripts`.
* @param {?string} topBlockId ID of block that starts the script.
*/
Blocks.prototype._addStack = function (id) {
var i = this._stacks.indexOf(id);
if (i > -1) return; // Already in stacks.
this._stacks.push(id);
Blocks.prototype._addScript = function (topBlockId) {
var i = this._scripts.indexOf(topBlockId);
if (i > -1) return; // Already in scripts.
this._scripts.push(topBlockId);
// Update `topLevel` property on the top block.
this._blocks[id].topLevel = true;
this._blocks[topBlockId].topLevel = true;
};
/**
* Helper to remove a stack from `this._stacks`
* @param {?string} id ID of block that starts the stack
* Helper to remove a script from `this._scripts`.
* @param {?string} topBlockId ID of block that starts the script.
*/
Blocks.prototype._deleteStack = function (id) {
var i = this._stacks.indexOf(id);
if (i > -1) this._stacks.splice(i, 1);
Blocks.prototype._deleteScript = function (topBlockId) {
var i = this._scripts.indexOf(topBlockId);
if (i > -1) this._scripts.splice(i, 1);
// Update `topLevel` property on the top block.
if (this._blocks[id]) this._blocks[id].topLevel = false;
if (this._blocks[topBlockId]) this._blocks[topBlockId].topLevel = false;
};
module.exports = Blocks;