Skip to content

Commit

Permalink
[FEATURE factory-for] Add symboled methods to container proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
chadhietala committed Dec 18, 2016
1 parent bac3a08 commit 54a5c15
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
16 changes: 9 additions & 7 deletions packages/container/lib/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import {
setOwner,
OWNER,
assign,
NAME_KEY
NAME_KEY,
HAS_NATIVE_PROXY
} from 'ember-utils';
import { ENV } from 'ember-environment';
import { assert, deprecate, runInDebug, isFeatureEnabled } from 'ember-metal';
import {
assert,
deprecate,
runInDebug,
isFeatureEnabled
} from 'ember-metal';

const CONTAINER_OVERRIDE = symbol('CONTAINER_OVERRIDE');
const HAS_PROXY = typeof Proxy === 'function';
export const FACTORY_FOR = symbol('FACTORY_FOR');
export const LOOKUP_FACTORY = symbol('LOOKUP_FACTORY');

Expand Down Expand Up @@ -39,9 +44,6 @@ export default function Container(registry, options) {
this.isDestroyed = false;
}

Container.__FACTORY_FOR__ = FACTORY_FOR;
Container.__LOOKUP_FACTORY__ = LOOKUP_FACTORY;

Container.prototype = {
/**
@private
Expand Down Expand Up @@ -232,7 +234,7 @@ Container.prototype = {
* set on the manager.
*/
function wrapManagerInDeprecationProxy(manager) {
if (HAS_PROXY) {
if (HAS_NATIVE_PROXY) {
let validator = {
get(obj, prop) {
if (prop !== 'class' && prop !== 'create') {
Expand Down
10 changes: 1 addition & 9 deletions packages/ember-application/lib/system/engine-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
RegistryProxyMixin,
RSVP
} from 'ember-runtime';
import { Error as EmberError, assert, run, isFeatureEnabled } from 'ember-metal';
import { Error as EmberError, assert, run } from 'ember-metal';
import { Registry, FACTORY_FOR, LOOKUP_FACTORY, privatize as P } from 'container';
import { getEngineParent, setEngineParent } from './engine-parent';

Expand Down Expand Up @@ -205,14 +205,6 @@ const EngineInstance = EmberObject.extend(RegistryProxyMixin, ContainerProxyMixi
}
});

if (isFeatureEnabled('ember-factory-for')) {
EngineInstance.reopen({
factoryFor(fullName, options) {
return this.__container__.factoryFor(fullName, options);
}
});
}

EngineInstance.reopenClass({
/**
@private
Expand Down
3 changes: 3 additions & 0 deletions packages/ember-glimmer/lib/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ export default class Environment extends GlimmerEnvironment {
if (helperFactory.class.isHelperInstance) {
return (vm, args) => SimpleHelperReference.create(helperFactory.class.compute, args);
} else if (helperFactory.class.isHelperFactory) {
if (!isFeatureEnabled('ember-no-double-extend')) {
helperFactory = helperFactory.create();
}
return (vm, args) => ClassBasedHelperReference.create(helperFactory, vm, args);
} else {
throw new Error(`${nameParts} is not a helper`);
Expand Down
16 changes: 16 additions & 0 deletions packages/ember-runtime/lib/mixins/container_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
Mixin,
run
} from 'ember-metal';
import {
FACTORY_FOR,
LOOKUP_FACTORY
} from 'container';

/**
ContainerProxyMixin is used to provide public access to specific
Expand Down Expand Up @@ -106,6 +110,14 @@ export default Mixin.create({
return this.__container__.lookupFactory(fullName, options);
},

[FACTORY_FOR]() {
return this.__container__[FACTORY_FOR](...arguments);
},

[LOOKUP_FACTORY]() {
return this.__container__[LOOKUP_FACTORY](...arguments);
},

/**
Given a name and a source path, resolve the fullName
Expand All @@ -130,5 +142,9 @@ export default Mixin.create({
if (this.__container__) {
run(this.__container__, 'destroy');
}
},

factoryFor(fullName, options = {}) {
return this.__container__.factoryFor(fullName, options);
}
});
1 change: 1 addition & 0 deletions packages/ember-utils/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export { default as applyStr } from './apply-str';
export { default as NAME_KEY } from './name';
export { default as toString } from './to-string';
export { HAS_NATIVE_WEAKMAP } from './weak-map-utils';
export { HAS_NATIVE_PROXY } from './proxy-utils';
1 change: 1 addition & 0 deletions packages/ember-utils/lib/proxy-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const HAS_NATIVE_PROXY = typeof Proxy === 'function';
11 changes: 1 addition & 10 deletions tests/node/helpers/build-owner.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
module.exports = function buildOwner(Ember, resolver) {
var FACTORY_FOR = Ember.Container.__FACTORY_FOR__;
var LOOKUP_FACTORY = Ember.Container.__LOOKUP_FACTORY__;
var Owner = Ember.Object.extend(Ember._RegistryProxyMixin, Ember._ContainerProxyMixin, {
[FACTORY_FOR]() {
return this.__container__[FACTORY_FOR](...arguments);
},
[LOOKUP_FACTORY]() {
return this.__container__[LOOKUP_FACTORY](...arguments);
}
});
var Owner = Ember.Object.extend(Ember._RegistryProxyMixin, Ember._ContainerProxyMixin);

var namespace = Ember.Object.create({
Resolver: { create: function() { return resolver; } }
Expand Down

0 comments on commit 54a5c15

Please sign in to comment.