<commit_before># Manage list of comment views
class app.Views.Comments extends Backbone.View
  initialize: ->
    @listenTo @collection, 'add', @add
    @listenTo @collection, 'reset', @addAll
    @fetch()
    @addAll()

  # Fetch comments for the given url without reseting existing comments.
  fetch: (url = @collection.url) ->
    @collection.fetch(url: url, reset: false, remove: false).done(@scroll).done(@paginate)

  # Ajax callback to fetch next page of comments if the link exists.
  paginate: (data, options, xhr) =>
    @fetch(link) if link = @nextLink(xhr.getResponseHeader("Link"))

  # Parse the Link header, looking for rel=next
  nextLink: (header) =>
    return unless header
    links = _.map header.split(/\s*,\s*/), (link) => new app.Models.Link(link)
    _.find links, (link) -> link.rel == 'next'

  # Render the given commment
  add: (comment) ->
    view = new app.Views.Comment(model: comment)
    @$el.append(view.render().el)

  # Render all comments in the collection
  addAll: ->
    @collection.each(@add, @)

  # Scroll to the first unread comment
  scroll: =>
    return if @collection.selected
    if unread = @collection.detect((comment) -> comment.isUnread())
      unread.select(scroll: true)

<commit_msg>Fix recursive loading of paginated comments (again)<commit_after># Manage list of comment views
class app.Views.Comments extends Backbone.View
  initialize: ->
    @listenTo @collection, 'add', @add
    @listenTo @collection, 'reset', @addAll
    @fetch()
    @addAll()

  # Fetch comments for the given url without reseting existing comments.
  fetch: (url = @collection.url) ->
    @collection.fetch(url: url, reset: false, remove: false).done(@scroll).done(@paginate)

  # Ajax callback to fetch next page of comments if the link exists.
  paginate: (data, options, xhr) =>
    @fetch(link.href) if link = @nextLink(xhr.getResponseHeader("Link"))

  # Parse the Link header, looking for rel=next
  nextLink: (header) =>
    return unless header
    links = _.map header.split(/\s*,\s*/), (link) => new app.Models.Link(link)
    _.find links, (link) -> link.rel == 'next'

  # Render the given commment
  add: (comment) ->
    view = new app.Views.Comment(model: comment)
    @$el.append(view.render().el)

  # Render all comments in the collection
  addAll: ->
    @collection.each(@add, @)

  # Scroll to the first unread comment
  scroll: =>
    return if @collection.selected
    if unread = @collection.detect((comment) -> comment.isUnread())
      unread.select(scroll: true)


{'fraction_non_alphanumeric': 0.1373169766521567, 'fraction_numerical': 0.0, 'mean_word_length': 3.579710144927536, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '5774335', 'n_tokens_mistral': 793, 'n_tokens_neox': 775, 'n_words': 242}