Skip to content

Commit

Permalink
Remove factory injections.
Browse files Browse the repository at this point in the history
These were only around to support `lookupFactory` semantics.
  • Loading branch information
rwjblue committed Apr 30, 2017
1 parent 077eace commit c6cd7c6
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 167 deletions.
2 changes: 1 addition & 1 deletion packages/container/lib/container.js
@@ -1,6 +1,6 @@
/* globals Proxy */
import { assert, deprecate } from 'ember-debug';
import { DEBUG } from 'ember-env-flags';
/* globals Proxy */
import {
dictionary,
symbol,
Expand Down
143 changes: 0 additions & 143 deletions packages/container/lib/registry.js
Expand Up @@ -32,8 +32,6 @@ export default function Registry(options) {

this._typeInjections = dictionary(null);
this._injections = dictionary(null);
this._factoryTypeInjections = dictionary(null);
this._factoryInjections = dictionary(null);

this._localLookupCache = Object.create(null);
this._normalizeCache = dictionary(null);
Expand Down Expand Up @@ -86,22 +84,6 @@ Registry.prototype = {
*/
_injections: null,

/**
@private
@property _factoryTypeInjections
@type InheritingDict
*/
_factoryTypeInjections: null,

/**
@private
@property _factoryInjections
@type InheritingDict
*/
_factoryInjections: null,

/**
@private
Expand Down Expand Up @@ -549,115 +531,6 @@ Registry.prototype = {
});
},


/**
Used only via `factoryInjection`.
Provides a specialized form of injection, specifically enabling
all factory of one type to be injected with a reference to another
object.
For example, provided each factory of type `model` needed a `store`.
one would do the following:
```javascript
let registry = new Registry();
registry.register('store:main', SomeStore);
registry.factoryTypeInjection('model', 'store', 'store:main');
let store = registry.lookup('store:main');
let UserFactory = registry.lookupFactory('model:user');
UserFactory.store instanceof SomeStore; //=> true
```
@private
@method factoryTypeInjection
@param {String} type
@param {String} property
@param {String} fullName
*/
factoryTypeInjection(type, property, fullName) {
let injections = this._factoryTypeInjections[type] ||
(this._factoryTypeInjections[type] = []);

injections.push({
property: property,
fullName: this.normalize(fullName)
});
},

/**
Defines factory injection rules.
Similar to regular injection rules, but are run against factories, via
`Registry#lookupFactory`.
These rules are used to inject objects onto factories when they
are looked up.
Two forms of injections are possible:
* Injecting one fullName on another fullName
* Injecting one fullName on a type
Example:
```javascript
let registry = new Registry();
let container = registry.container();
registry.register('store:main', Store);
registry.register('store:secondary', OtherStore);
registry.register('model:user', User);
registry.register('model:post', Post);
// injecting one fullName on another type
registry.factoryInjection('model', 'store', 'store:main');
// injecting one fullName on another fullName
registry.factoryInjection('model:post', 'secondaryStore', 'store:secondary');
let UserFactory = container.lookupFactory('model:user');
let PostFactory = container.lookupFactory('model:post');
let store = container.lookup('store:main');
UserFactory.store instanceof Store; //=> true
UserFactory.secondaryStore instanceof OtherStore; //=> false
PostFactory.store instanceof Store; //=> true
PostFactory.secondaryStore instanceof OtherStore; //=> true
// and both models share the same source instance
UserFactory.store === PostFactory.store; //=> true
```
@private
@method factoryInjection
@param {String} factoryName
@param {String} property
@param {String} injectionName
*/
factoryInjection(fullName, property, injectionName) {
let normalizedName = this.normalize(fullName);
let normalizedInjectionName = this.normalize(injectionName);

this.validateFullName(injectionName);

if (fullName.indexOf(':') === -1) {
return this.factoryTypeInjection(normalizedName, property, normalizedInjectionName);
}

let injections = this._factoryInjections[normalizedName] || (this._factoryInjections[normalizedName] = []);

injections.push({
property: property,
fullName: normalizedInjectionName
});
},

/**
@private
@method knownForType
Expand Down Expand Up @@ -743,22 +616,6 @@ Registry.prototype = {
injections = injections.concat(this.fallback.getTypeInjections(type));
}
return injections;
},

getFactoryInjections(fullName) {
let injections = this._factoryInjections[fullName] || [];
if (this.fallback) {
injections = injections.concat(this.fallback.getFactoryInjections(fullName));
}
return injections;
},

getFactoryTypeInjections(type) {
let injections = this._factoryTypeInjections[type] || [];
if (this.fallback) {
injections = injections.concat(this.fallback.getFactoryTypeInjections(type));
}
return injections;
}
};

Expand Down
23 changes: 0 additions & 23 deletions packages/container/tests/registry_test.js
Expand Up @@ -436,29 +436,6 @@ QUnit.test('`getTypeInjections` includes type injections from a fallback registr
equal(registry.getTypeInjections('model').length, 1, 'Injections from the fallback registry are merged');
});

QUnit.test('`getFactoryInjections` includes factory injections from a fallback registry', function() {
let fallback = new Registry();
let registry = new Registry({ fallback: fallback });

equal(registry.getFactoryInjections('model:user').length, 0, 'No factory injections in the primary registry');

fallback.factoryInjection('model:user', 'store', 'store:main');

equal(registry.getFactoryInjections('model:user').length, 1, 'Factory injections from the fallback registry are merged');
});


QUnit.test('`getFactoryTypeInjections` includes factory type injections from a fallback registry', function() {
let fallback = new Registry();
let registry = new Registry({ fallback: fallback });

equal(registry.getFactoryTypeInjections('model').length, 0, 'No factory type injections in the primary registry');

fallback.factoryInjection('model', 'store', 'store:main');

equal(registry.getFactoryTypeInjections('model').length, 1, 'Factory type injections from the fallback registry are merged');
});

QUnit.test('`knownForType` contains keys for each item of a given type', function() {
let registry = new Registry();

Expand Down

0 comments on commit c6cd7c6

Please sign in to comment.