all files / documents/document/ document.js

100% Statements 16/16
100% Branches 0/0
100% Functions 5/5
100% Lines 12/12
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                                        10× 10×                                  
import Ember from 'ember';
import DocumentObject from './object';
import StateMixin from './state-mixin';
 
const {
  computed
} = Ember;
 
const id = () => {
  return computed('_id', {
    get() {
      return this._internal.getId();
    },
    set(_, value) {
      return this._internal.setId(value);
    }
  });
};
 
const rev = () => computed('_rev', {
  get() {
    return this._internal.getRev();
  }
});
 
const database = () => computed(function() {
  return this._internal.database;
}).readOnly();
 
const promise = name => function() {
  let internal = this._internal;
  return internal[name].call(internal, ...arguments).then(() => this);
};
 
export default DocumentObject.extend(StateMixin, {
 
  id: id(),
  rev: rev(),
 
  database: database(),
 
  save:   promise('enqueueSave'),
  load:   promise('enqueueLoad'),
  reload: promise('enqueueReload'),
  delete: promise('enqueueDelete')
 
});