<commit_before>window.AutoloadingView = extendWithAutoloading(Backbone.Marionette.ItemView);

class window.ActivitiesView extends AutoloadingView

  childViews: []

  template: 'activities/list'

  initialize: (opts) ->
    this.collection.on('reset', this.reset, this);
    this.collection.on('add', this.add, this);
    this.itemView = ActivityItemView;

  render: () ->
    super arguments
    this.renderChildren()

  renderChildren: () ->
    this.$('.list').html('')
    for childView in @childViews
      this.appendHtml(this, childView)

  reset: () ->
    this.collection.each( this.add, this );
    this.renderChildren();

  add: (model) ->
    last = _.last(this.childViews);

    if (last && (last.appendable(model)))
      appendTo = last;
    else
      appendTo = this.newChildView(model);
      this.childViews.push(appendTo);
      this.appendHtml(this, appendTo)

    appendTo.collection.add(model);

  appendHtml: (collectionView, childView) ->
    childView.render();
    this.$(".list").append(childView.$el);

  newChildView: (model) ->
    ch = this.collection.channel;
    return new UserActivitiesView({model: model.getActivity(), collection: new ChannelActivities([], {channel: ch})});<commit_msg>properly close child views<commit_after>window.AutoloadingView = extendWithAutoloading(Backbone.Marionette.ItemView);

class window.ActivitiesView extends AutoloadingView

  childViews: []

  template: 'activities/list'

  initialize: (opts) ->
    this.collection.on('reset', this.reset, this);
    this.collection.on('add', this.add, this);
    this.itemView = ActivityItemView;

  render: () ->
    super arguments
    this.renderChildren()

  renderChildren: () ->
    this.$('.list').html('')
    for childView in @childViews
      this.appendHtml(this, childView)

  reset: () ->
    this.collection.each( this.add, this );
    this.renderChildren();

  add: (model) ->
    last = _.last(this.childViews);

    if (last && (last.appendable(model)))
      appendTo = last;
    else
      appendTo = this.newChildView(model);
      this.childViews.push(appendTo);
      this.appendHtml(this, appendTo)

    appendTo.collection.add(model);

  beforeClose: ->
    for childView in @childViews
      childView.close

  appendHtml: (collectionView, childView) ->
    childView.render();
    this.$(".list").append(childView.$el);

  newChildView: (model) ->
    ch = this.collection.channel;
    new UserActivitiesView
      model: model.getActivity(),
      collection: new ChannelActivities([], {channel: ch})
{'fraction_non_alphanumeric': 0.1452249408050513, 'fraction_numerical': 0.0, 'mean_word_length': 3.5267857142857144, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 18, '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': '3945953', 'n_tokens_mistral': 795, 'n_tokens_neox': 770, 'n_words': 148}