Merge pull request #9 from tmickel/feature/flyout-listening

Add listener for new blocks that doesn't add to stacks
This commit is contained in:
Tim Mickel 2016-04-29 17:17:49 -04:00
commit 69450031cd
2 changed files with 26 additions and 3 deletions

View file

@ -50,7 +50,7 @@ Runtime.THREAD_STEP_INTERVAL = 1000 / 60;
* Block management: create blocks and stacks from a `create` event
* @param {!Object} block Blockly create event to be processed
*/
Runtime.prototype.createBlock = function (block) {
Runtime.prototype.createBlock = function (block, opt_isFlyoutBlock) {
// Create new block
this.blocks[block.id] = block;
@ -67,7 +67,9 @@ Runtime.prototype.createBlock = function (block) {
// Push block id to stacks array. New blocks are always a stack even if only
// momentary. If the new block is added to an existing stack this stack will
// be removed by the `moveBlock` method below.
this.stacks.push(block.id);
if (!opt_isFlyoutBlock) {
this.stacks.push(block.id);
}
};
/**

View file

@ -31,7 +31,7 @@ function VirtualMachine () {
// Blocks
switch (e.type) {
case 'create':
instance.runtime.createBlock(adapter(e));
instance.runtime.createBlock(adapter(e), false);
break;
case 'change':
instance.runtime.changeBlock({
@ -57,6 +57,27 @@ function VirtualMachine () {
break;
}
};
instance.flyoutBlockListener = function (e) {
switch (e.type) {
case 'create':
instance.runtime.createBlock(adapter(e), true);
break;
case 'change':
instance.runtime.changeBlock({
id: e.blockId,
element: e.element,
name: e.name,
value: e.newValue
});
break;
case 'delete':
instance.runtime.deleteBlock({
id: e.blockId
});
break;
}
};
}
/**