all files / documents/database/operations/internal/ -load.js

76.47% Statements 13/17
100% Branches 0/0
80% Functions 4/5
80% Lines 12/15
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                                                             
import Ember from 'ember';
import Operation from './operation';
 
const {
  RSVP: { resolve }
} = Ember;
 
export default class InternalDocumentBaseLoadOperation extends Operation {
 
  willLoad() {
    this.withPropertyChanges(changed => this.state.onLoading(changed));
  }
 
  load() {
    let id = this.internal.getId();
    return this.docs.load(id);
  }
 
  didLoad(json) {
    this.withPropertyChanges(changed => {
      this.internal.deserialize(json, 'document', changed);
      this.state.onLoaded(changed);
    });
    this.resolve();
  }
 
  loadDidFail(err) {
    this.withPropertyChanges(changed => {
      this.state.onError(err, changed);
    });
    this.reject(err);
  }
 
  _invoke() {
    return resolve()
      .then(() => this.willLoad())
      .then(() => this.load())
      .then(json => this.didLoad(json), err => this.loadDidFail(err));
  }
 
}