all files / documents/database/ internal-document-deserialize.js

100% Statements 22/22
100% Branches 2/2
100% Functions 5/5
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52                              13× 13× 13×   13× 13×       12× 12× 12×       16× 16×   16×   12×            
import Ember from 'ember';
 
const {
  assert
} = Ember;
 
export default Ember.Mixin.create({
 
  _deserializeDeletedInternal(internal, doc) {
    internal.withPropertyChanges(changed => {
      internal.deserializeDeleted({ id: doc._id, rev: doc._rev }, changed);
      internal.state.onDeleted(changed);
    }, true);
    this._storeDeletedInternalDocument(internal);
    return internal;
  },
 
  _deserializeDeleted(doc) {
    let id = doc._id;
    let internal = this._existingInternalDocument(id, { deleted: true, create: true });
    return this._deserializeDeletedInternal(internal, doc);
  },
 
  _deserializeSavedInternal(internal, doc) {
    internal.withPropertyChanges(changed => {
      internal.deserialize(doc, 'document', changed);
      internal.state.onLoaded(changed);
    }, true);
    this._storeLoadedInternalDocument(internal);
    return internal;
  },
 
  _deserializeSaved(doc) {
    let id = doc._id;
    let internal = this._existingInternalDocument(id, { deleted: true, create: true });
    return this._deserializeSavedInternal(internal, doc);
  },
 
  _deserialize(doc) {
    assert(`doc must be object`, typeof doc === 'object');
    assert(`doc._id must be string`, typeof doc._id === 'string');
 
    if(doc._deleted) {
      return this._deserializeDeleted(doc);
    } else {
      return this._deserializeSaved(doc);
    }
  }
 
});