all files / couch/ couches.js

100% Statements 12/12
50% Branches 1/2
100% Functions 4/4
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                        120× 120×       120× 120× 120× 120× 120×   120×       120×       120× 120×          
import Ember from 'ember';
import { object } from './util/computed';
import { destroyObject } from './util/destroy';
 
const {
  getOwner
} = Ember;
 
export default Ember.Service.extend({
 
  openCouches: object().readOnly(),
 
  createCouch(url) {
    let couches = this;
    return getOwner(this).factoryFor('couch:couch').create({ couches, url });
  },
 
  couch({ url }) {
    let open = this.get('openCouches');
    let couch = open[url];
    Eif(!couch) {
      couch = this.createCouch(url);
      open[url] = couch;
    }
    return couch;
  },
 
  _destroyOpenCouches() {
    destroyObject(this.get('openCouches'));
  },
 
  willDestroy() {
    this._destroyOpenCouches();
    this._super();
  }
 
});