Skip to content

Commit

Permalink
Merge branch 'master' into empty-object
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanpenner authored Mar 14, 2017
2 parents 48410cb + 5a36a7d commit 0098bb0
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
8 changes: 5 additions & 3 deletions packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ function instantiate(factory, props, container, fullName) {
obj = factory.create(assign({}, injections, props));

// TODO - remove when Ember reaches v3.0.0
if (!Object.isFrozen(obj) && 'container' in obj) {
if (!Object.isFrozen(obj)) {
injectDeprecatedContainer(obj, container);
}
}
Expand All @@ -559,6 +559,7 @@ function factoryInjectionsFor(container, fullName) {

// TODO - remove when Ember reaches v3.0.0
function injectDeprecatedContainer(object, container) {
if ('container' in object) { return; }
Object.defineProperty(object, 'container', {
configurable: true,
enumerable: false,
Expand Down Expand Up @@ -695,8 +696,9 @@ class FactoryManager {
` an invalid module export.`);
}

if (this.class.prototype) {
injectDeprecatedContainer(this.class.prototype, this.container);
let prototype = this.class.prototype;
if (prototype) {
injectDeprecatedContainer(prototype, this.container);
}

return this.class.create(props);
Expand Down
14 changes: 9 additions & 5 deletions packages/ember-metal/lib/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,26 +276,30 @@ export class Meta {

_forEachIn(key, subkey, fn) {
let pointer = this;
let seen = Object.create(null);
let calls = [];
let seen;
let calls;
while (pointer !== undefined) {
let map = pointer[key];
if (map) {
seen = seen || new EmptyObject();
let innerMap = map[subkey];
if (innerMap) {
for (let innerKey in innerMap) {
if (!seen[innerKey]) {
seen[innerKey] = true;
calls = calls || [];
calls.push([innerKey, innerMap[innerKey]]);
}
}
}
}
pointer = pointer.parent;
}
for (let i = 0; i < calls.length; i++) {
let [innerKey, value] = calls[i];
fn(innerKey, value);
if (calls) {
for (let i = 0; i < calls.length; i++) {
let [innerKey, value] = calls[i];
fn(innerKey, value);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ember-routing/lib/system/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -1701,7 +1701,7 @@ let Route = EmberObject.extend(ActionHandler, Evented, {
`_super`:
```app/routes/photos.js
import Ember from 'ebmer';
import Ember from 'ember';
export default Ember.Route.extend({
model() {
Expand Down
38 changes: 38 additions & 0 deletions packages/ember-runtime/lib/mixins/container_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,44 @@ let containerProxyMixin = {
};

if (isFeatureEnabled('ember-factory-for')) {
/**
Given a fullName return a factory manager.
This method returns a manager which can be used for introspection of the
factory's class or for the creation of factory instances with initial
properties. The manager is an object with the following properties:
* `class` - The registered or resolved class.
* `create` - A function that will create an instance of the class with
any dependencies injected.
For example:
```javascript
let owner = Ember.getOwner(otherInstance);
// the owner is commonly the `applicationInstance`, and can be accessed via
// an instance initializer.
let factory = owner.factoryFor('service:bespoke');
factory.class;
// The registered or resolved class. For example when used with an Ember-CLI
// app, this would be the default export from `app/services/bespoke.js`.
let instance = factory.create({
someProperty: 'an initial property value'
});
// Create an instance with any injections and the passed options as
// initial properties.
```
@public
@class ContainerProxyMixin
@method factoryFor
@param {String} fullName
@param {Object} options
@return {FactoryManager}
*/
containerProxyMixin.factoryFor = function ContainerProxyMixin_factoryFor(fullName, options = {}) {
return this.__container__.factoryFor(fullName, options);
};
Expand Down

0 comments on commit 0098bb0

Please sign in to comment.