<commit_before>window.AutoloadCollectionOnTimestamp = {
  _loading: undefined,
  _timestamp: undefined,
  hasMore: true,

  updateTimestamp: function(){
    var lastModel = this.models[(this.length - 1) || 0];
    this._timestamp = (lastModel ? lastModel.get('timestamp') : undefined);
    console.info('updated timestamp to ', this._timestamp);
  },

  startLoading: function(){
    this._loading = true;
    this.trigger('startLoading',this);
  },

  stopLoading: function(){
    this._loading = false;
    this.trigger('stopLoading',this);
  },

  needsMore: function(){
    return this.hasMore && ! this._loading;
  },

  loadMore: function() {
    if( ! this.needsMore() ) {return;}
    
    var prevlength = this.length;
    
    this.startLoading();
    this.fetch({
      add: true,
      data: {
        timestamp: this._timestamp
      },
      success: _.bind(function() {
        console.info('lange jan', this.length);
        this.updateTimestamp();
        this.stopLoading();
        if (prevlength === this.length){
          this.hasMore = false;
        }
      }, this),
      error: _.bind(function() {
        this.updateTimestamp();
        this.stopLoading();
        this.hasMore = false;
      }, this)
    });
  }
}<commit_msg>a bit more racecondition-proof (though at this point it probably does not matter)<commit_after>window.AutoloadCollectionOnTimestamp = {
  _loading: undefined,
  _timestamp: undefined,
  hasMore: true,

  updateTimestamp: function(){
    var lastModel = this.models[(this.length - 1) || 0];
    this._timestamp = (lastModel ? lastModel.get('timestamp') : undefined);
    console.info('updated timestamp to ', this._timestamp);
  },

  startLoading: function(){
    this._loading = true;
    this.trigger('startLoading',this);
  },

  stopLoading: function(){
    this._loading = false;
    this.trigger('stopLoading',this);
  },

  needsMore: function(){
    return this.hasMore && ! this._loading;
  },

  loadMore: function() {
    var prevlength;
    if( ! this.needsMore() ) {return;}
    
    prevlength = this.length;
    
    this.startLoading();
    this.fetch({
      add: true,
      data: {
        timestamp: this._timestamp
      },
      success: _.bind(function() {
        console.info('lange jan', this.length);
        this.updateTimestamp();
        if (prevlength === this.length){
          this.hasMore = false;
        }
        this.stopLoading();
      }, this),
      error: _.bind(function() {
        this.updateTimestamp();
        this.hasMore = false;
        this.stopLoading();
      }, this)
    });
  }
}
{'fraction_non_alphanumeric': 0.14506172839506173, 'fraction_numerical': 0.0015432098765432098, 'mean_word_length': 2.586445366528354, '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': '6718912', 'n_tokens_mistral': 769, 'n_tokens_neox': 750, 'n_words': 157}