components/blockly-src/blocks/procedures.js
function(paramNames, paramIds) {
    // Data structures:
    // this.arguments = ['x', 'y']
    //     Existing param names.
    // this.quarkConnections_ {piua: null, f8b_: Blockly.Connection}
    //     Look-up of paramIds to connections plugged into the call block.
    // this.quarkIds_ = ['piua', 'f8b_']
    //     Existing param IDs.
    // Note that quarkConnections_ may include IDs that no longer exist, but
    // which might reappear if a param is reattached in the mutator.
    var defBlock = Blockly.Procedures.getDefinition(this.getProcedureCall(),
        this.workspace);
    var mutatorOpen = defBlock && defBlock.mutator &&
        defBlock.mutator.isVisible();
    if (!mutatorOpen) {
      this.quarkConnections_ = {};
      this.quarkIds_ = null;
    }
    if (!paramIds) {
      // Reset the quarks (a mutator is about to open).
      return;
    }
    if (goog.array.equals(this.arguments_, paramNames)) {
      // No change.
      this.quarkIds_ = paramIds;
      return;
    }
    if (paramIds.length != paramNames.length) {
      throw 'Error: paramNames and paramIds must be the same length.';
    }
    this.setCollapsed(false);
    if (!this.quarkIds_) {
      // Initialize tracking for this block.
      this.quarkConnections_ = {};
      if (paramNames.join('\n') == this.arguments_.join('\n')) {
        // No change to the parameters, allow quarkConnections_ to be
        // populated with the existing connections.
        this.quarkIds_ = paramIds;
      } else {
        this.quarkIds_ = [];
      }
    }
    // Switch off rendering while the block is rebuilt.
    var savedRendered = this.rendered;
    this.rendered = false;
    // Update the quarkConnections_ with existing connections.
    for (var i = 0; i < this.arguments_.length; i++) {
      var input = this.getInput('ARG' + i);
      if (input) {
        var connection = input.connection.targetConnection;
        this.quarkConnections_[this.quarkIds_[i]] = connection;
        if (mutatorOpen && connection &&
            paramIds.indexOf(this.quarkIds_[i]) == -1) {
          // This connection should no longer be attached to this block.
          connection.disconnect();
          connection.getSourceBlock().bumpNeighbours_();
        }
      }
    }
    // Rebuild the block's arguments.
    this.arguments_ = [].concat(paramNames);
    this.updateShape_();
    this.quarkIds_ = paramIds;
    // Reconnect any child blocks.
    if (this.quarkIds_) {
      for (var i = 0; i < this.arguments_.length; i++) {
        var quarkId = this.quarkIds_[i];
        if (quarkId in this.quarkConnections_) {
          var connection = this.quarkConnections_[quarkId];
          if (!Blockly.Mutator.reconnect(connection, this, 'ARG' + i)) {
            // Block no longer exists or has been attached elsewhere.
            delete this.quarkConnections_[quarkId];
          }
        }
      }
    }
    // Restore rendering and show the changes.
    this.rendered = savedRendered;
    if (this.rendered) {
      this.render();
    }
  }
function(paramNames, paramIds) {
    // Data structures:
    // this.arguments = ['x', 'y']
    //     Existing param names.
    // this.quarkConnections_ {piua: null, f8b_: Blockly.Connection}
    //     Look-up of paramIds to connections plugged into the call block.
    // this.quarkIds_ = ['piua', 'f8b_']
    //     Existing param IDs.
    // Note that quarkConnections_ may include IDs that no longer exist, but
    // which might reappear if a param is reattached in the mutator.
    var defBlock = Blockly.Procedures.getDefinition(this.getProcedureCall(),
        this.workspace);
    var mutatorOpen = defBlock && defBlock.mutator &&
        defBlock.mutator.isVisible();
    if (!mutatorOpen) {
      this.quarkConnections_ = {};
      this.quarkIds_ = null;
    }
    if (!paramIds) {
      // Reset the quarks (a mutator is about to open).
      return;
    }
    if (goog.array.equals(this.arguments_, paramNames)) {
      // No change.
      this.quarkIds_ = paramIds;
      return;
    }
    if (paramIds.length != paramNames.length) {
      throw 'Error: paramNames and paramIds must be the same length.';
    }
    this.setCollapsed(false);
    if (!this.quarkIds_) {
      // Initialize tracking for this block.
      this.quarkConnections_ = {};
      if (paramNames.join('\n') == this.arguments_.join('\n')) {
        // No change to the parameters, allow quarkConnections_ to be
        // populated with the existing connections.
        this.quarkIds_ = paramIds;
      } else {
        this.quarkIds_ = [];
      }
    }
    // Switch off rendering while the block is rebuilt.
    var savedRendered = this.rendered;
    this.rendered = false;
    // Update the quarkConnections_ with existing connections.
    for (var i = 0; i < this.arguments_.length; i++) {
      var input = this.getInput('ARG' + i);
      if (input) {
        var connection = input.connection.targetConnection;
        this.quarkConnections_[this.quarkIds_[i]] = connection;
        if (mutatorOpen && connection &&
            paramIds.indexOf(this.quarkIds_[i]) == -1) {
          // This connection should no longer be attached to this block.
          connection.disconnect();
          connection.getSourceBlock().bumpNeighbours_();
        }
      }
    }
    // Rebuild the block's arguments.
    this.arguments_ = [].concat(paramNames);
    this.updateShape_();
    this.quarkIds_ = paramIds;
    // Reconnect any child blocks.
    if (this.quarkIds_) {
      for (var i = 0; i < this.arguments_.length; i++) {
        var quarkId = this.quarkIds_[i];
        if (quarkId in this.quarkConnections_) {
          var connection = this.quarkConnections_[quarkId];
          if (!Blockly.Mutator.reconnect(connection, this, 'ARG' + i)) {
            // Block no longer exists or has been attached elsewhere.
            delete this.quarkConnections_[quarkId];
          }
        }
      }
    }
    // Restore rendering and show the changes.
    this.rendered = savedRendered;
    if (this.rendered) {
      this.render();
    }
  }
function ( paramNames , paramIds ) { // Data structures: // this.arguments = ['x', 'y'] //     Existing param names. // this.quarkConnections_ {piua: null, f8b_: Blockly.Connection} //     Look-up of paramIds to connections plugged into the call block. // this.quarkIds_ = ['piua', 'f8b_'] //     Existing param IDs. // Note that quarkConnections_ may include IDs that no longer exist, but // which might reappear if a param is reattached in the mutator. var defBlock = Blockly . Procedures . getDefinition ( this . getProcedureCall ( ) , this . workspace ) ; var mutatorOpen = defBlock && defBlock . mutator && defBlock . mutator . isVisible ( ) ; if ( ! mutatorOpen ) { this . quarkConnections_ = { } ; this . quarkIds_ = null ; } if ( ! paramIds ) { // Reset the quarks (a mutator is about to open). return ; } if ( goog . array . equals ( this . arguments_ , paramNames ) ) { // No change. this . quarkIds_ = paramIds ; return ; } if ( paramIds . length != paramNames . length ) { throw 'Error: paramNames and paramIds must be the same length.' ; } this . setCollapsed ( false ) ; if ( ! this . quarkIds_ ) { // Initialize tracking for this block. this . quarkConnections_ = { } ; if ( paramNames . join ( '\n' ) == this . arguments_ . join ( '\n' ) ) { // No change to the parameters, allow quarkConnections_ to be // populated with the existing connections. this . quarkIds_ = paramIds ; } else { this . quarkIds_ = [ ] ; } } // Switch off rendering while the block is rebuilt. var savedRendered = this . rendered ; this . rendered = false ; // Update the quarkConnections_ with existing connections. for ( var i = 0 ; i < this . arguments_ . length ; i ++ ) { var input = this . getInput ( 'ARG' + i ) ; if ( input ) { var connection = input . connection . targetConnection ; this . quarkConnections_ [ this . quarkIds_ [ i ] ] = connection ; if ( mutatorOpen && connection && paramIds . indexOf ( this . quarkIds_ [ i ] ) == - 1 ) { // This connection should no longer be attached to this block. connection . disconnect ( ) ; connection . getSourceBlock ( ) . bumpNeighbours_ ( ) ; } } } // Rebuild the block's arguments. this . arguments_ = [ ] . concat ( paramNames ) ; this . updateShape_ ( ) ; this . quarkIds_ = paramIds ; // Reconnect any child blocks. if ( this . quarkIds_ ) { for ( var i = 0 ; i < this . arguments_ . length ; i ++ ) { var quarkId = this . quarkIds_ [ i ] ; if ( quarkId in this . quarkConnections_ ) { var connection = this . quarkConnections_ [ quarkId ] ; if ( ! Blockly . Mutator . reconnect ( connection , this , 'ARG' + i ) ) { // Block no longer exists or has been attached elsewhere. delete this . quarkConnections_ [ quarkId ] ; } } } } // Restore rendering and show the changes. this . rendered = savedRendered ; if ( this . rendered ) { this . render ( ) ; } }
Notification that the procedure's parameters have changed.
@param {!Array.<string>} paramNames New param names, e.g. ['x', 'y', 'z'].
@param {!Array.<string>} paramIds IDs of params (consistent for each
parameter through the life of a mutator, regardless of param renaming),
e.g. ['piua', 'f8b_', 'oi.o'].
@private
@this Blockly.Block
Notification that the procedure s parameters have changed .