all files / documents/store/ factory-cache.js

100% Statements 7/7
100% Branches 2/2
100% Functions 1/1
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                      298× 298× 298× 262× 262×   298×          
import Ember from 'ember';
import { object } from '../util/computed';
 
const {
  getOwner
} = Ember;
 
export default Ember.Mixin.create({
 
  _factoryCache: object().readOnly(),
 
  _factoryFor(factoryName) {
    let cache = this.get('_factoryCache');
    let Factory = cache[factoryName];
    if(!Factory) {
      Factory = getOwner(this).factoryFor(factoryName);
      cache[factoryName] = Factory;
    }
    return Factory;
  }
 
});