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

class window.ActivitiesView extends AutoloadingView

  template: 'activities/list'

  initialize: (opts) ->
    @collection.on('reset remove', @reset, this)
    @collection.on('add', @add, this)

    @addShowHideToggle('loadingIndicator', 'div.loading');
    @collection.on('startLoading', @loadingIndicatorOn, this);
    @collection.on('stopLoading', @loadingIndicatorOff, this);

    @childViews = []

  onRender: ->
    @renderChildren()

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

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

  add: (model, collection, options) ->
    index = options.index

    appendableCandidate =
      if index == 0
        _.first(@childViews)
      else
        _.last(@childViews);

    appendTo =
      if (appendableCandidate && (appendableCandidate.appendable(model)))
        appendableCandidate
      else
        @createNewAppendable(model, index)

    appendTo.collection.add(model, at: index);

  createNewAppendable: (model, index) ->
      appendTo = @newChildView(model)
      if index == 0
        @childViews.unshift(appendTo)
      else
        @childViews.push(appendTo)
      @appendHtml(this, appendTo, index)
      appendTo


  closeChildViews: ->
    childView.close() for childView in @childViews
    @childViews = []

  beforeClose: -> @closeChildviews()


  appendHtml: (collectionView, childView, index) ->
    childView.render()
    if index == 0
      @$(".list").prepend(childView.$el)
    else
      @$(".list").append(childView.$el)

  newChildView: (model) ->
    ch = @collection.channel
    new UserActivitiesView
      model: model.getActivity(),
      collection: new ChannelActivities([], {channel: ch})

  emptyViewOn: ->
    if @collection.channel.get('discover_stream?')
      @suggestedTopics = new SuggestedTopics()
      @suggestedTopics.fetch()
      @emptyView = new SuggestedTopicsView
        model: new Backbone.Model({current_url: @collection.link()})
        collection: collectionDifference(SuggestedTopics,'slug_title',@suggestedTopics, window.Channels);
    else
      @emptyView = getTextView('Currently there are no activities related to this channel')

    @$('.empty_stream').html(@emptyView.render().el)

<commit_msg>fixed typo<commit_after>AutoloadingView = extendWithAutoloading(Backbone.Marionette.ItemView);

class window.ActivitiesView extends AutoloadingView

  template: 'activities/list'

  initialize: (opts) ->
    @collection.on('reset remove', @reset, this)
    @collection.on('add', @add, this)

    @addShowHideToggle('loadingIndicator', 'div.loading');
    @collection.on('startLoading', @loadingIndicatorOn, this);
    @collection.on('stopLoading', @loadingIndicatorOff, this);

    @childViews = []

  onRender: ->
    @renderChildren()

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

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

  add: (model, collection, options) ->
    index = options.index

    appendableCandidate =
      if index == 0
        _.first(@childViews)
      else
        _.last(@childViews);

    appendTo =
      if (appendableCandidate && (appendableCandidate.appendable(model)))
        appendableCandidate
      else
        @createNewAppendable(model, index)

    appendTo.collection.add(model, at: index);

  createNewAppendable: (model, index) ->
      appendTo = @newChildView(model)
      if index == 0
        @childViews.unshift(appendTo)
      else
        @childViews.push(appendTo)
      @appendHtml(this, appendTo, index)
      appendTo


  closeChildViews: ->
    childView.close() for childView in @childViews
    @childViews = []

  beforeClose: -> @closeChildViews()


  appendHtml: (collectionView, childView, index) ->
    childView.render()
    if index == 0
      @$(".list").prepend(childView.$el)
    else
      @$(".list").append(childView.$el)

  newChildView: (model) ->
    ch = @collection.channel
    new UserActivitiesView
      model: model.getActivity(),
      collection: new ChannelActivities([], {channel: ch})

  emptyViewOn: ->
    if @collection.channel.get('discover_stream?')
      @suggestedTopics = new SuggestedTopics()
      @suggestedTopics.fetch()
      @emptyView = new SuggestedTopicsView
        model: new Backbone.Model({current_url: @collection.link()})
        collection: collectionDifference(SuggestedTopics,'slug_title',@suggestedTopics, window.Channels);
    else
      @emptyView = getTextView('Currently there are no activities related to this channel')

    @$('.empty_stream').html(@emptyView.render().el)


{'fraction_non_alphanumeric': 0.13250259605399792, 'fraction_numerical': 0.0012461059190031153, 'mean_word_length': 3.41025641025641, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '5822533', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1433, 'n_words': 287}