<commit_before>console.log('accounts.js');


/**
 * A single account the user has authorized
 */
window.Account = Backbone.Model.extend({


  url: 'https://alpha-api.app.net/stream/0/users/me',


  initialize: function() {
    // _.bindAll(this);
  },


  parse: function(response) {
    return response.data;
  }

});

/**
 * Collection of all accounts the user has authorized
 */
window.Accounts = Backbone.Collection.extend({


  /**
   * Convenience to know if chrome.storage values have been retrieved yet
   */
  ready: false,


  model: Account,


  initialize: function() {
    // Set up `this` to work in every method
    _.bindAll(this, 'getFromChrome', 'getFromChromeCallback', 'setChomeChangesToCollection');
    // Listen for changes to chrome.storage and propigate to model
    chrome.storage.onChanged.addListener(this.setChomeChangesToCollection);
    // Get current values from chrome.storage
    this.getFromChrome();
    // On change save new values to chrome.storage
    this.on('add', this.setCollectionChangesToChrome);
    this.on('remove', this.setCollectionChangesToChrome);
  },


  /**
   * Get accounts collection from chrome.storage.sync
   */
  getFromChrome: function() {
    console.log('accounts.getFromChrome');
    chrome.storage.sync.get('accounts', this.getFromChromeCallback);
  },


  /**
   * Set changes of chrome.storage.sync to accounts collection
   */
  getFromChromeCallback: function(items){
    console.log('accounts.getFromChromeCallback', items);
    if (items['accounts']){
      this.reset(items['accounts']);
    }
    this.ready = true;
    this.trigger('ready');
    return this;
  },


  /**
   * Set changes of chrome.storage.sync to accounts collection
   */
  setChomeChangesToCollection: function(changes, ns) {
    console.log('accounts.setChomeChangesToModel', changes, ns);
    // Ignore local changes
    if (ns != 'sync') {
      return this;
    }
    if (changes['accounts']) {
      console.log('accounts.setChomeChangesToCollection:set', changes['accounts']);
      this.reset(changes['accounts'].newValue);
    }
  },


  /**
   * Set changes of account collection to chrome.storage.sync
   *
   * Trigger at most once every five seconds
   */
   setCollectionChangesToChrome: _.debounce(function(model, collection, options) {
    console.log('accounts.setCollectionChangesToChrome', model, collection, options);
    chrome.storage.sync.set({'accounts': this.toJSON()});
  }, 5000),


});

window.accounts = new Accounts();<commit_msg>set debounce to 2 seconds for accounts<commit_after>console.log('accounts.js');


/**
 * A single account the user has authorized
 */
window.Account = Backbone.Model.extend({


  url: 'https://alpha-api.app.net/stream/0/users/me',


  initialize: function() {
    // _.bindAll(this);
  },


  parse: function(response) {
    return response.data;
  }

});

/**
 * Collection of all accounts the user has authorized
 */
window.Accounts = Backbone.Collection.extend({


  /**
   * Convenience to know if chrome.storage values have been retrieved yet
   */
  ready: false,


  model: Account,


  initialize: function() {
    // Set up `this` to work in every method
    _.bindAll(this, 'getFromChrome', 'getFromChromeCallback', 'setChomeChangesToCollection');
    // Listen for changes to chrome.storage and propigate to model
    chrome.storage.onChanged.addListener(this.setChomeChangesToCollection);
    // Get current values from chrome.storage
    this.getFromChrome();
    // On change save new values to chrome.storage
    this.on('add', this.setCollectionChangesToChrome);
    this.on('remove', this.setCollectionChangesToChrome);
  },


  /**
   * Get accounts collection from chrome.storage.sync
   */
  getFromChrome: function() {
    console.log('accounts.getFromChrome');
    chrome.storage.sync.get('accounts', this.getFromChromeCallback);
  },


  /**
   * Set changes of chrome.storage.sync to accounts collection
   */
  getFromChromeCallback: function(items){
    console.log('accounts.getFromChromeCallback', items);
    if (items['accounts']){
      this.reset(items['accounts']);
    }
    this.ready = true;
    this.trigger('ready');
    return this;
  },


  /**
   * Set changes of chrome.storage.sync to accounts collection
   */
  setChomeChangesToCollection: function(changes, ns) {
    console.log('accounts.setChomeChangesToModel', changes, ns);
    // Ignore local changes
    if (ns != 'sync') {
      return this;
    }
    if (changes['accounts']) {
      console.log('accounts.setChomeChangesToCollection:set', changes['accounts']);
      this.reset(changes['accounts'].newValue);
    }
  },


  /**
   * Set changes of account collection to chrome.storage.sync
   *
   * Trigger at most once every five seconds
   */
   setCollectionChangesToChrome: _.debounce(function(model, collection, options) {
    console.log('accounts.setCollectionChangesToChrome', model, collection, options);
    chrome.storage.sync.set({'accounts': this.toJSON()});
  }, 2000),


});

window.accounts = new Accounts();
{'fraction_non_alphanumeric': 0.1342601787487587, 'fraction_numerical': 0.0021847070506454814, 'mean_word_length': 3.5004468275245757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '306918', 'n_tokens_mistral': 1561, 'n_tokens_neox': 1481, 'n_words': 339}