<commit_before>import Ember from 'ember';
import DS from 'ember-data';
const { Mixin, $, on, assert, computed, get, isPresent, run } = Ember;

export default Mixin.create({
  isOffline: computed.not('isOnline'),

  store: computed({
    get() {
      return this.container.lookup('store:main');
    }
  }),
  _workingQueue: computed('queue', {
    get() {
      if (isPresent(get(this, 'queue'))) {
        return get(this, 'queue');
      } else {
        return get(this, 'store.queue');
      }
    }
  }),

  /*
   * `find()`
   * `createRecord()`
   * `updateRecord()`
   * `deleteRecord()`
   * `findAll()` -- done some
   * `findQuery()`
   */

  findAll: function(store, type, ...others) {
    if (this.get('isOnline')) {
      let adapterResp = this._super.apply(this, arguments);
      let typeClass = type.modelName;
      let adapter = this;
      let isPopulated = this.get('isPopulated');

      if (!isPopulated) {
        run.once(() => {
          console.log("Populate offline store")
          adapterResp.then(records => {
            let serializer = store.serializerFor(type.modelName);
            // TODO let serializedRecords = records[serializer.modelNameFromPayloadKey(typeClass)];
            for (var prop in records) {
              var modelName = prop;
              let array = records[modelName];
              array.forEach(record => {
                let storeRecord = store.createRecord(typeClass, record);
                let snapshot = new DS.Snapshot(storeRecord);

                adapter.get('offlineAdapter').createRecord(store, type, snapshot);
              });
            }
            this.set('isPopulated', true);
          });
        });
      }
      return adapterResp;
    } else {
      return this.get('offlineAdapter').findAll(arguments);
    }
  },

  assertRunner: on('init', function() {
    assert('[ember-data-offline] You should set offline adapter', get(this, 'offlineAdapter'));
  }),

  setup: on('init', function() {
    $(window).on('online', () => {<commit_msg>some refactor offline populate method<commit_after>import Ember from 'ember';
import DS from 'ember-data';
const { Mixin, $, on, assert, computed, get, isPresent, run } = Ember;

export default Mixin.create({
  isOffline: computed.not('isOnline'),

  store: computed({
    get() {
      return this.container.lookup('store:main');
    }
  }),
  _workingQueue: computed('queue', {
    get() {
      if (isPresent(get(this, 'queue'))) {
        return get(this, 'queue');
      } else {
        return get(this, 'store.queue');
      }
    }
  }),

  /*
   * `find()`
   * `createRecord()`
   * `updateRecord()`
   * `deleteRecord()`
   * `findAll()` -- done some
   * `findQuery()`
   */

  findAll: function(store, typeClass, sinceToken) {
    if (this.get('isOnline')) {
      let adapterResp = this._super.apply(this, arguments);
      let isPopulated = this.get('isPopulated');
      let adapter = this;

      if (!isPopulated) {
        run.once(() => {
          adapterResp.then(records => {
            adapter.get('offlineAdapter').persistData(typeClass, records);
            this.set('isPopulated', true);
          });
        });
      }
      return adapterResp;
    } else {
      return this.get('offlineAdapter').findAll(store, typeClass, sinceToken);
    }
  },

  assertRunner: on('init', function() {
    assert('[ember-data-offline] You should set offline adapter', get(this, 'offlineAdapter'));
  }),

  setup: on('init', function() {
    $(window).on('online', () => {
{'fraction_non_alphanumeric': 0.16240772288472458, 'fraction_numerical': 0.0, 'mean_word_length': 2.508964143426295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '7424804', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1033, 'n_words': 224}