function compose(containerBlock) {
      var itemBlock = containerBlock.getInputTargetBlock('STACK'); // Count number of inputs.

      var connections = [containerBlock.valueConnection_];
      var blockTypes = ['ast_Comp_create_with_for'];

      while (itemBlock) {
        connections.push(itemBlock.valueConnection_);
        blockTypes.push(itemBlock.type);
        itemBlock = itemBlock.nextConnection && itemBlock.nextConnection.targetBlock();
      } // Disconnect any children that don't belong.


      for (var i = 1; i < this.itemCount_; i++) {
        var connection = this.getInput('GENERATOR' + i).connection.targetConnection;

        if (connection && connections.indexOf(connection) === -1) {
          var connectedBlock = connection.getSourceBlock();

          if (connectedBlock.type === 'ast_comprehensionIf') {
            var testField = connectedBlock.getInput('TEST');

            if (testField.connection.targetConnection) {
              testField.connection.targetConnection.getSourceBlock().unplug(true);
            }
          } else if (connectedBlock.type === 'ast_comprehensionFor') {
            var iterField = connectedBlock.getInput('ITER');

            if (iterField.connection.targetConnection) {
              iterField.connection.targetConnection.getSourceBlock().unplug(true);
            }

            var targetField = connectedBlock.getInput('TARGET');

            if (targetField.connection.targetConnection) {
              targetField.connection.targetConnection.getSourceBlock().unplug(true);
            }
          } else {
            throw Error("Unknown block type: " + connectedBlock.type);
          }

          connection.disconnect();
          connection.getSourceBlock().dispose();
        }
      }

      this.itemCount_ = connections.length;
      this.updateShape_(); // Reconnect any child blocks.

      for (var i = 1; i < this.itemCount_; i++) {
        Blockly.Mutator.reconnect(connections[i], this, 'GENERATOR' + i); // TODO: glitch when inserting into middle, deletes children values

        if (!connections[i]) {
          var createName = void 0;

          if (blockTypes[i] === 'ast_Comp_create_with_if') {
            createName = 'ast_comprehensionIf';
          } else if (blockTypes[i] === 'ast_Comp_create_with_for') {
            createName = 'ast_comprehensionFor';
          } else {
            throw Error("Unknown block type: " + blockTypes[i]);
          }

          var _itemBlock2 = this.workspace.newBlock(createName);

          _itemBlock2.setDeletable(false);

          _itemBlock2.setMovable(false);

          _itemBlock2.initSvg();

          this.getInput('GENERATOR' + i).connection.connect(_itemBlock2.outputConnection);

          _itemBlock2.render(); //this.get(itemBlock, 'ADD'+i)

        }
      }
    }
/**
     * Reconfigure this block based on the mutator dialog's components.
     * @param {!Blockly.Block} containerBlock Root block in mutator.
     * @this Blockly.Block
     */
Reconfigure this block based on the mutator dialog's components.
@param {!Blockly.Block} containerBlock Root block in mutator.
Reconfigure this block based on the mutator dialog ' s components . @param { !Blockly . Block } containerBlock Root block in mutator .
function compose(containerBlock) {
      var itemBlock = containerBlock.getInputTargetBlock('STACK'); 
      var connections = [containerBlock.valueConnection_];
      var blockTypes = ['ast_Comp_create_with_for'];
      while (itemBlock) {
        connections.push(itemBlock.valueConnection_);
        blockTypes.push(itemBlock.type);
        itemBlock = itemBlock.nextConnection && itemBlock.nextConnection.targetBlock();
      } 
      for (var i = 1; i < this.itemCount_; i++) {
        var connection = this.getInput('GENERATOR' + i).connection.targetConnection;
        if (connection && connections.indexOf(connection) === -1) {
          var connectedBlock = connection.getSourceBlock();
          if (connectedBlock.type === 'ast_comprehensionIf') {
            var testField = connectedBlock.getInput('TEST');
            if (testField.connection.targetConnection) {
              testField.connection.targetConnection.getSourceBlock().unplug(true);
            }
          } else if (connectedBlock.type === 'ast_comprehensionFor') {
            var iterField = connectedBlock.getInput('ITER');
            if (iterField.connection.targetConnection) {
              iterField.connection.targetConnection.getSourceBlock().unplug(true);
            }
            var targetField = connectedBlock.getInput('TARGET');
            if (targetField.connection.targetConnection) {
              targetField.connection.targetConnection.getSourceBlock().unplug(true);
            }
          } else {
            throw Error("Unknown block type: " + connectedBlock.type);
          }
          connection.disconnect();
          connection.getSourceBlock().dispose();
        }
      }
      this.itemCount_ = connections.length;
      this.updateShape_(); 
      for (var i = 1; i < this.itemCount_; i++) {
        Blockly.Mutator.reconnect(connections[i], this, 'GENERATOR' + i); 
        if (!connections[i]) {
          var createName = void 0;
          if (blockTypes[i] === 'ast_Comp_create_with_if') {
            createName = 'ast_comprehensionIf';
          } else if (blockTypes[i] === 'ast_Comp_create_with_for') {
            createName = 'ast_comprehensionFor';
          } else {
            throw Error("Unknown block type: " + blockTypes[i]);
          }
          var _itemBlock2 = this.workspace.newBlock(createName);
          _itemBlock2.setDeletable(false);
          _itemBlock2.setMovable(false);
          _itemBlock2.initSvg();
          this.getInput('GENERATOR' + i).connection.connect(_itemBlock2.outputConnection);
          _itemBlock2.render(); 
        }
      }
    }
function compose ( containerBlock ) { var itemBlock = containerBlock . getInputTargetBlock ( 'STACK' ) ; var connections = [ containerBlock . valueConnection_ ] ; var blockTypes = [ 'ast_Comp_create_with_for' ] ; while ( itemBlock ) { connections . push ( itemBlock . valueConnection_ ) ; blockTypes . push ( itemBlock . type ) ; itemBlock = itemBlock . nextConnection && itemBlock . nextConnection . targetBlock ( ) ; } for ( var i = 1 ; i < this . itemCount_ ; i ++ ) { var connection = this . getInput ( 'GENERATOR' + i ) . connection . targetConnection ; if ( connection && connections . indexOf ( connection ) === - 1 ) { var connectedBlock = connection . getSourceBlock ( ) ; if ( connectedBlock . type === 'ast_comprehensionIf' ) { var testField = connectedBlock . getInput ( 'TEST' ) ; if ( testField . connection . targetConnection ) { testField . connection . targetConnection . getSourceBlock ( ) . unplug ( true ) ; } } else if ( connectedBlock . type === 'ast_comprehensionFor' ) { var iterField = connectedBlock . getInput ( 'ITER' ) ; if ( iterField . connection . targetConnection ) { iterField . connection . targetConnection . getSourceBlock ( ) . unplug ( true ) ; } var targetField = connectedBlock . getInput ( 'TARGET' ) ; if ( targetField . connection . targetConnection ) { targetField . connection . targetConnection . getSourceBlock ( ) . unplug ( true ) ; } } else { throw Error ( "Unknown block type: " + connectedBlock . type ) ; } connection . disconnect ( ) ; connection . getSourceBlock ( ) . dispose ( ) ; } } this . itemCount_ = connections . length ; this . updateShape_ ( ) ; for ( var i = 1 ; i < this . itemCount_ ; i ++ ) { Blockly . Mutator . reconnect ( connections [ i ] , this , 'GENERATOR' + i ) ; if ( ! connections [ i ] ) { var createName = void 0 ; if ( blockTypes [ i ] === 'ast_Comp_create_with_if' ) { createName = 'ast_comprehensionIf' ; } else if ( blockTypes [ i ] === 'ast_Comp_create_with_for' ) { createName = 'ast_comprehensionFor' ; } else { throw Error ( "Unknown block type: " + blockTypes [ i ] ) ; } var _itemBlock2 = this . workspace . newBlock ( createName ) ; _itemBlock2 . setDeletable ( false ) ; _itemBlock2 . setMovable ( false ) ; _itemBlock2 . initSvg ( ) ; this . getInput ( 'GENERATOR' + i ) . connection . connect ( _itemBlock2 . outputConnection ) ; _itemBlock2 . render ( ) ; } } }
Reconfigure this block based on the mutator dialog's components.
Reconfigure this block based on the mutator dialog ' s components .
// Count number of inputs. // Disconnect any children that don't belong. // Reconnect any child blocks. // TODO: glitch when inserting into middle, deletes children values //this.get(itemBlock, 'ADD'+i)