Switch Blockly listener to normal function (not closure/generated)

This commit is contained in:
Tim Mickel 2016-08-31 11:34:17 -04:00
parent aa70c1bc3b
commit 05a5369d7b

View file

@ -120,18 +120,12 @@ Blocks.prototype.getInputs = function (id) {
/**
* Create event listener for blocks. Handles validation and serves as a generic
* adapter between the blocks and the runtime interface.
* @param {Object} e Blockly "block" event
* @param {boolean} isFlyout If true, create a listener for flyout events.
* @param {?Runtime} opt_runtime Optional runtime to forward click events to.
* @return {Function} A generated listener to attach to Blockly instance.
*/
Blocks.prototype.generateBlockListener = function (isFlyout, opt_runtime) {
var instance = this;
/**
* The actual generated block listener.
* @param {Object} e Blockly "block" event
*/
return function (e) {
Blocks.prototype.blocklyListen = function (e, isFlyout, opt_runtime) {
// Validate event
if (typeof e !== 'object') return;
if (typeof e.blockId !== 'string') return;
@ -150,11 +144,11 @@ Blocks.prototype.generateBlockListener = function (isFlyout, opt_runtime) {
var newBlocks = adapter(e);
// A create event can create many blocks. Add them all.
for (var i = 0; i < newBlocks.length; i++) {
instance.createBlock(newBlocks[i], isFlyout);
this.createBlock(newBlocks[i], isFlyout);
}
break;
case 'change':
instance.changeBlock({
this.changeBlock({
id: e.blockId,
element: e.element,
name: e.name,
@ -162,21 +156,21 @@ Blocks.prototype.generateBlockListener = function (isFlyout, opt_runtime) {
});
break;
case 'move':
instance.moveBlock({
this.moveBlock({
id: e.blockId,
oldParent: e.oldParentId,
oldInput: e.oldInputName,
newParent: e.newParentId,
newInput: e.newInputName
newInput: e.newInputName,
newCoordinate: e.newCoordinate
});
break;
case 'delete':
instance.deleteBlock({
this.deleteBlock({
id: e.blockId
});
break;
}
};
};
// ---------------------------------------------------------------------