<commit_before>import DS from 'ember-data';
import Ember from 'ember';

const {
  get,
  inject: { service }
} = Ember;

export default DS.Store.extend({
  hoodie: service(),
  adapter: 'hoodie',

  init() {
    this._super(...arguments);

    let update = (obj) => {
      let type = obj.type;
      let data = this.normalize(type, obj);
      // HACK: ugh... these change events were coming through
      // before the promise was resolving in the adapter. This
      // means the record was still in flight when we attempted
      // this push. Somehow we were ending up with two records
      // in the store with the same id. I think this is an ED
      // bug, but this works around it for now.
      //
      // Perhaps we should just check for inflight records before
      // pushing into the store?
      Ember.run.next(this, function(){
        Ember.run.next(this, function(){
          this.push(data);
        });
      });
    };

    let remove = (obj) => {
      let record = this.peekRecord(obj.type, obj.id);
      if (!get(record, 'isDeleted')) {
        record.unloadRecord();
      }
    };

    let reset = () => {
      this.unloadAll();
    };

    this.get('hoodie.store').on('add', update);
    this.get('hoodie.store').on('update', update);
    this.get('hoodie.store').on('remove', remove);
    this.get('hoodie.account').on('signout', reset);
  }
});<commit_msg>fix: do not try to get properties from already deleted records<commit_after>import DS from 'ember-data';
import Ember from 'ember';

const {
  get,
  inject: { service }
} = Ember;

export default DS.Store.extend({
  hoodie: service(),
  adapter: 'hoodie',

  init() {
    this._super(...arguments);

    let update = (obj) => {
      let type = obj.type;
      let data = this.normalize(type, obj);
      // HACK: ugh... these change events were coming through
      // before the promise was resolving in the adapter. This
      // means the record was still in flight when we attempted
      // this push. Somehow we were ending up with two records
      // in the store with the same id. I think this is an ED
      // bug, but this works around it for now.
      //
      // Perhaps we should just check for inflight records before
      // pushing into the store?
      Ember.run.next(this, function(){
        Ember.run.next(this, function(){
          this.push(data);
        });
      });
    };

    let remove = (obj) => {
      let record = this.peekRecord(obj.type, obj.id);
      if (record && !get(record, 'isDeleted')) {
        record.unloadRecord();
      }
    };

    let reset = () => {
      this.unloadAll();
    };

    this.get('hoodie.store').on('add', update);
    this.get('hoodie.store').on('update', update);
    this.get('hoodie.store').on('remove', remove);
    this.get('hoodie.account').on('signout', reset);
  }
});
{'fraction_non_alphanumeric': 0.14667604642982765, 'fraction_numerical': 0.0, 'mean_word_length': 2.3263157894736843, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4475972', 'n_tokens_mistral': 865, 'n_tokens_neox': 852, 'n_words': 271}