<commit_before>/**
 * Backbone - Pageable Collection. Simple paginator on top of Collection.
 * version 0.1.3
 * <NAME> [<EMAIL>] | https://github.com/KaneCohen
 * @preserve
 */
(function(root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['underscore', 'backbone'], factory);
  } else if (typeof exports === 'object') {
    module.exports = factory(_, Backbone);
  } else {
    root.returnExports = factory(_, Backbone);
  }
}(this, function(_, Backbone) {

  var PageableCollection = Backbone.PageableCollection = Backbone.Collection.extend({

    mode:        'server', // Modes: 'server', 'client'.
    style:       false,    // Force pagination style: 'pager', 'slider',  'infinite'.
                           // if not set, will be determinded either between pager or slider.
    headerState: false,    // If set to true, pager will use header data for state (if available).
    cache:       false,    // Keep loaded pages in cache. Used only for server/infinite mode.
    cachedPages: {},       // If cache is true, store cached pages in this object. Clear on sort/search.
    presenter:   null,
    linkUrl:     null,
    ajaxLoad:    true,     // Use collection fetch method to get data after clicking on a page.
    updateUrl:   true,     // Update url in address bar after ajax data fetch.
    state: {},
    // Defaults.
    defaultState: {
      currentPage: 1,
      firstPage:   1,
      lastPage:    0,
      perPage:     20,
      total:       0
    },

    params: {},
    // Defaults.
    defaultParams: {
      currentPage: 'page',   // Param name used to determine current page.
      offset:      false,    // Param name for offset to send on fetch.
      perPage:     false,    // Param telling server how many items should be per page.
      sortParam:   'sort',   // Param name containing details about sorting.
      sortBy:      false,    // Param telling which field to use for sorting.
      orderParam:  'order',  // Param name containing details about ordering.
      orderBy:     false     // Param indicating order for sorting (fasle/asc/desc).
    },

    constructor: function(models, options) {
      Backbone.Collection.apply(this, arguments);
      options || (options = {});
      if (options.url) this.url = options.url;
      if (options.model) this.model = options.model;
      if (typeof options.comparator !== 'undefined') this.comparator = options.comparator;
      this.state = _.extend({}, this.defaultState, this.state, options.state);
      this.params = _.extend({}, this.defaultParams, this.params, options.params);
      this.state.currentPage = this.getParam(this.params.currentPage, this.state.firstPage);
      this.mode = options.mode || this.mode;
      this.updateState();
      if (! this.presenter) {
        this.initPresenter();
      }
    },

    setState: function(state) {
      this.state = _.extend({}, this.state, state);
    },

    // Extension of core reset method with updateState.
    reset: function(models, options) {
      options || (options = {});
      for (var i = 0, l = this.models.length; i < l; i++) {
        this._removeReference(this.models[i]);
      }
      options.previousModels = this.models;
      this._reset();
      models = this.add(models, _.extend({silent: true}, options));
      this.updateState();
      if (!options.silent) this.trigger('reset', this, options);
      return models;
    },

    // Extension of core method. Deals with server data.
    parse: function(resp, options) {
      var items = resp;
      if (_.isObject(resp) && _.has(resp, 'state') && _.has(resp, 'items')) {<commit_msg>Update state after it has been set.<commit_after>/**
 * Backbone - Pageable Collection. Simple paginator on top of Collection.
 * version 0.1.3
 * <NAME> [<EMAIL>] | https://github.com/KaneCohen
 * @preserve
 */
(function(root, factory) {
  if (typeof define === 'function' && define.amd) {
    define(['underscore', 'backbone'], factory);
  } else if (typeof exports === 'object') {
    module.exports = factory(_, Backbone);
  } else {
    root.returnExports = factory(_, Backbone);
  }
}(this, function(_, Backbone) {

  var PageableCollection = Backbone.PageableCollection = Backbone.Collection.extend({

    mode:        'server', // Modes: 'server', 'client'.
    style:       false,    // Force pagination style: 'pager', 'slider',  'infinite'.
                           // if not set, will be determinded either between pager or slider.
    headerState: false,    // If set to true, pager will use header data for state (if available).
    cache:       false,    // Keep loaded pages in cache. Used only for server/infinite mode.
    cachedPages: {},       // If cache is true, store cached pages in this object. Clear on sort/search.
    presenter:   null,
    linkUrl:     null,
    ajaxLoad:    true,     // Use collection fetch method to get data after clicking on a page.
    updateUrl:   true,     // Update url in address bar after ajax data fetch.
    state: {},
    // Defaults.
    defaultState: {
      currentPage: 1,
      firstPage:   1,
      lastPage:    0,
      perPage:     20,
      total:       0
    },

    params: {},
    // Defaults.
    defaultParams: {
      currentPage: 'page',   // Param name used to determine current page.
      offset:      false,    // Param name for offset to send on fetch.
      perPage:     false,    // Param telling server how many items should be per page.
      sortParam:   'sort',   // Param name containing details about sorting.
      sortBy:      false,    // Param telling which field to use for sorting.
      orderParam:  'order',  // Param name containing details about ordering.
      orderBy:     false     // Param indicating order for sorting (fasle/asc/desc).
    },

    constructor: function(models, options) {
      Backbone.Collection.apply(this, arguments);
      options || (options = {});
      if (options.url) this.url = options.url;
      if (options.model) this.model = options.model;
      if (typeof options.comparator !== 'undefined') this.comparator = options.comparator;
      this.state = _.extend({}, this.defaultState, this.state, options.state);
      this.params = _.extend({}, this.defaultParams, this.params, options.params);
      this.state.currentPage = this.getParam(this.params.currentPage, this.state.firstPage);
      this.mode = options.mode || this.mode;
      this.updateState();
      if (! this.presenter) {
        this.initPresenter();
      }
    },

    setState: function(state) {
      this.state = _.extend({}, this.state, state);
      this.updateState();
    },

    // Extension of core reset method with updateState.
    reset: function(models, options) {
      options || (options = {});
      for (var i = 0, l = this.models.length; i < l; i++) {
        this._removeReference(this.models[i]);
      }
      options.previousModels = this.models;
      this._reset();
      models = this.add(models, _.extend({silent: true}, options));
      this.updateState();
      if (!options.silent) this.trigger('reset', this, options);
      return models;
    },

    // Extension of core method. Deals with server data.
    parse: function(resp, options) {
      var items = resp;
      if (_.isObject(resp) && _.has(resp, 'state') && _.has(resp, 'items')) {
{'fraction_non_alphanumeric': 0.13060722100656455, 'fraction_numerical': 0.002735229759299781, 'mean_word_length': 2.465876777251185, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '5078910', 'n_tokens_mistral': 2110, 'n_tokens_neox': 2089, 'n_words': 657}