<commit_before>var View = Backbone.View.extend({

  constructor: function() {
    this._children = [];
    Backbone.View.apply(this, arguments);
  },

  add: function(view, selector, method) {
    var child = { view: view, selector: selector, method: method };
    this._children.push(child);
    this._attachChild(child);
    return this;
  },

  removeChildren: function() {
    _.invoke(_.pluck(this._children, 'view'), 'remove');
    return this;
  },

  remove: function() {
    this.removeChildren();
    Backbone.View.prototype.remove.apply(this, arguments);
    return this;
  },

  render: function() {
    _.each(this._children, function(child) {
      this._attachChild(child);
      child.view.delegateEvents();
    }, this);

    return this;
  },

  _attachChild: function(child) {
    method = child.method || 'append';
    var target = child.selector ? this.$(child.selector) : this.$el;

    target[method](child.view.$el);
  }
});<commit_msg>add attachChildren helper and restructure methods<commit_after>var View = Backbone.View.extend({

  constructor: function() {
    this._children = [];
    Backbone.View.apply(this, arguments);
  },

  add: function(view, selector, method) {
    var child = { view: view, selector: selector, method: method };
    this._children.push(child);
    this._attachChild(child);
    return this;
  },

  remove: function() {
    this.removeChildren();
    Backbone.View.prototype.remove.apply(this, arguments);
    return this;
  },

  removeChildren: function() {
    _.invoke(_.pluck(this._children, 'view'), 'remove');
    return this;
  },

  render: function() {
    this._attachChildren();
    return this;
  },

  _attachChild: function(child) {
    method = child.method || 'append';
    var target = child.selector ? this.$(child.selector) : this.$el;

    target[method](child.view.$el);
  },

  _attachChildren: function() {
    _.each(this._children, function(child) {
      this._attachChild(child);
      child.view.delegateEvents();
    }, this);
  }
});
{'fraction_non_alphanumeric': 0.15734784760019793, 'fraction_numerical': 0.0, 'mean_word_length': 3.3390557939914163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2434585', 'n_tokens_mistral': 627, 'n_tokens_neox': 610, 'n_words': 124}