Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove debug -> metal cycle #15014

Merged
merged 2 commits into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ember-cli-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ function babelConfigFor(environment) {

plugins.push(applyFeatureFlags({
imports: [
{ module: 'ember-metal/features' },
{ module: 'ember-metal', name: 'isFeatureEnabled' },
{ module: 'ember-debug/features' },
{ module: 'ember-debug', name: 'isFeatureEnabled' },
],
features: features
}));
Expand All @@ -217,8 +217,8 @@ function babelConfigFor(environment) {
if (isProduction) {
includeDevHelpers = false;
plugins.push(filterImports({
'ember-metal/debug': ['assert', 'debug', 'deprecate', 'info', 'runInDebug', 'warn', 'debugSeal', 'debugFreeze'],
'ember-metal': ['assert', 'debug', 'deprecate', 'info', 'runInDebug', 'warn', 'debugSeal', 'debugFreeze']
'ember-debug/deprecate': ['deprecate'],
'ember-debug': ['assert', 'debug', 'deprecate', 'info', 'runInDebug', 'warn', 'debugSeal', 'debugFreeze']
}));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function(features) {
'ember-utils': { trees: null, requirements: [] },
'ember-console': { trees: null, requirements: [], skipTests: true },
'ember-metal': { trees: null, requirements: ['ember-environment', 'ember-utils'], vendorRequirements: ['backburner'] },
'ember-debug': { trees: null, requirements: ['ember-metal'], testing: true },
'ember-debug': { trees: null, requirements: [] },
'ember-runtime': { trees: null, vendorRequirements: ['rsvp'], requirements: ['container', 'ember-environment', 'ember-console', 'ember-metal'] },
'ember-views': { trees: null, requirements: ['ember-runtime'] },
'ember-extension-support': { trees: null, requirements: ['ember-application'] },
Expand Down
155 changes: 61 additions & 94 deletions packages/container/lib/container.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assert, deprecate, runInDebug, isFeatureEnabled } from 'ember-debug';
/* globals Proxy */
import {
dictionary,
Expand All @@ -9,12 +10,6 @@ import {
HAS_NATIVE_PROXY
} from 'ember-utils';
import { ENV } from 'ember-environment';
import {
assert,
deprecate,
runInDebug,
isFeatureEnabled
} from 'ember-metal';

const CONTAINER_OVERRIDE = symbol('CONTAINER_OVERRIDE');
export const FACTORY_FOR = symbol('FACTORY_FOR');
Expand Down Expand Up @@ -84,43 +79,30 @@ Container.prototype = {

/**
Given a fullName return a corresponding instance.

The default behaviour is for lookup to return a singleton instance.
The default behaviour is for lookup to return a singleton instance.
The singleton is scoped to the container, allowing multiple containers
to all have their own locally scoped singletons.

```javascript
```javascript
let registry = new Registry();
let container = registry.container();

registry.register('api:twitter', Twitter);

let twitter = container.lookup('api:twitter');

twitter instanceof Twitter; // => true

// by default the container will return singletons
registry.register('api:twitter', Twitter);
let twitter = container.lookup('api:twitter');
twitter instanceof Twitter; // => true
// by default the container will return singletons
let twitter2 = container.lookup('api:twitter');
twitter2 instanceof Twitter; // => true

twitter === twitter2; //=> true
twitter === twitter2; //=> true
```

If singletons are not wanted, an optional flag can be provided at lookup.

```javascript
If singletons are not wanted, an optional flag can be provided at lookup.
```javascript
let registry = new Registry();
let container = registry.container();

registry.register('api:twitter', Twitter);

let twitter = container.lookup('api:twitter', { singleton: false });
registry.register('api:twitter', Twitter);
let twitter = container.lookup('api:twitter', { singleton: false });
let twitter2 = container.lookup('api:twitter', { singleton: false });

twitter === twitter2; //=> false
twitter === twitter2; //=> false
```

@private
@private
@method lookup
@param {String} fullName
@param {Object} [options]
Expand All @@ -134,8 +116,7 @@ Container.prototype = {

/**
Given a fullName, return the corresponding factory.

@private
@private
@method lookupFactory
@param {String} fullName
@param {Object} [options]
Expand All @@ -145,11 +126,7 @@ Container.prototype = {
lookupFactory(fullName, options) {
assert('fullName must be a proper full name', this.registry.validateFullName(fullName));

deprecate(
'Using "_lookupFactory" is deprecated. Please use container.factoryFor instead.',
!isFeatureEnabled('ember-factory-for'),
{ id: 'container-lookupFactory', until: '2.13.0', url: 'http://emberjs.com/deprecations/v2.x/#toc_migrating-from-_lookupfactory-to-factoryfor' }
);
deprecate('Using "_lookupFactory" is deprecated. Please use container.factoryFor instead.', !isFeatureEnabled('ember-factory-for'), { id: 'container-lookupFactory', until: '2.13.0', url: 'http://emberjs.com/deprecations/v2.x/#toc_migrating-from-_lookupfactory-to-factoryfor' });

return deprecatedFactoryFor(this, this.registry.normalize(fullName), options);
},
Expand All @@ -175,7 +152,9 @@ Container.prototype = {
}
}
let factory = this[LOOKUP_FACTORY](fullName, options);
if (factory === undefined) { return; }
if (factory === undefined) {
return;
}
let manager = new DeprecatedFactoryManager(this, factory, fullName);

runInDebug(() => {
Expand All @@ -188,8 +167,7 @@ Container.prototype = {
/**
A depth first traversal, destroying the container, its descendant containers and all
their managed objects.

@private
@private
@method destroy
*/
destroy() {
Expand All @@ -204,8 +182,7 @@ Container.prototype = {

/**
Clear either the entire cache or just the cache for a particular key.

@private
@private
@method reset
@param {String} fullName optional key to reset; if missing, resets everything
*/
Expand All @@ -220,8 +197,7 @@ Container.prototype = {
/**
Returns an object that can be used to provide an owner to a
manually created instance.

@private
@private
@method ownerInjection
@returns { Object }
*/
Expand Down Expand Up @@ -272,8 +248,7 @@ if (isFeatureEnabled('ember-factory-for')) {
is responsible for the destruction of any factory instances, as there is no
way for the container to ensure instances are destroyed when it itself is
destroyed.

@public
@public
@method factoryFor
@param {String} fullName
@param {Object} [options]
Expand All @@ -288,7 +263,9 @@ if (isFeatureEnabled('ember-factory-for')) {
if (options.source) {
normalizedName = this.registry.expandLocalLookup(fullName, options);
// if expandLocalLookup returns falsey, we do not support local lookup
if (!normalizedName) { return; }
if (!normalizedName) {
return;
}
}

let cached = this.factoryManagerCache[normalizedName];
Expand Down Expand Up @@ -325,7 +302,9 @@ function lookup(container, fullName, options = {}) {
fullName = container.registry.expandLocalLookup(fullName, options);

// if expandLocalLookup returns falsey, we do not support local lookup
if (!fullName) { return; }
if (!fullName) {
return;
}
}

if (container.cache[fullName] !== undefined && options.singleton !== false) {
Expand All @@ -338,7 +317,9 @@ function lookup(container, fullName, options = {}) {
let factory = deprecatedFactoryFor(container, fullName);
let value = instantiate(factory, {}, container, fullName);

if (value === undefined) { return; }
if (value === undefined) {
return;
}

if (isSingleton(container, fullName) && options.singleton !== false) {
container.cache[fullName] = value;
Expand All @@ -349,29 +330,27 @@ function lookup(container, fullName, options = {}) {
}

function isSingletonClass(container, fullName, { instantiate, singleton }) {
return (singleton !== false && isSingleton(container, fullName)) &&
(!instantiate && !shouldInstantiate(container, fullName));
return singleton !== false && isSingleton(container, fullName) && !instantiate && !shouldInstantiate(container, fullName);
}

function isSingletonInstance(container, fullName, { instantiate, singleton }) {
return (singleton !== false && isSingleton(container, fullName)) &&
(instantiate !== false && shouldInstantiate(container, fullName));
return singleton !== false && isSingleton(container, fullName) && instantiate !== false && shouldInstantiate(container, fullName);
}

function isFactoryClass(container, fullname, { instantiate, singleton }) {
return (singleton === false || !isSingleton(container, fullname)) &&
(instantiate === false && !shouldInstantiate(container, fullname));
return (singleton === false || !isSingleton(container, fullname)) && instantiate === false && !shouldInstantiate(container, fullname);
}

function isFactoryInstance(container, fullName, { instantiate, singleton }) {
return (singleton !== false || isSingleton(container, fullName)) &&
(instantiate !== false && shouldInstantiate(container, fullName));
return (singleton !== false || isSingleton(container, fullName)) && instantiate !== false && shouldInstantiate(container, fullName);
}

function instantiateFactory(container, fullName, options) {
let factoryManager = container[FACTORY_FOR](fullName);

if (factoryManager === undefined) { return; }
if (factoryManager === undefined) {
return;
}

// SomeClass { singleton: true, instantiate: true } | { singleton: true } | { instantiate: true } | {}
// By default majority of objects fall into this case
Expand Down Expand Up @@ -400,7 +379,7 @@ function areInjectionsDynamic(injections) {
return !!injections._dynamic;
}

function buildInjections(/* container, ...injections */) {
function buildInjections() /* container, ...injections */{
let hash = {};

if (arguments.length > 1) {
Expand Down Expand Up @@ -436,18 +415,22 @@ function deprecatedFactoryFor(container, fullName, options = {}) {
if (options.source) {
fullName = registry.expandLocalLookup(fullName, options);
// if expandLocalLookup returns falsey, we do not support local lookup
if (!fullName) { return; }
if (!fullName) {
return;
}
}

let cache = container.factoryCache;
if (cache[fullName]) {
return cache[fullName];
}
let factory = registry.resolve(fullName);
if (factory === undefined) { return; }
if (factory === undefined) {
return;
}

let type = fullName.split(':')[0];
if (!factory || typeof factory.extend !== 'function' || (!ENV.MODEL_FACTORY_INJECTIONS && type === 'model')) {
if (!factory || typeof factory.extend !== 'function' || !ENV.MODEL_FACTORY_INJECTIONS && type === 'model') {
if (factory && typeof factory._onLookup === 'function') {
factory._onLookup(fullName);
}
Expand Down Expand Up @@ -486,9 +469,7 @@ function injectionsFor(container, fullName) {
let splitName = fullName.split(':');
let type = splitName[0];

let injections = buildInjections(container,
registry.getTypeInjections(type),
registry.getInjections(fullName));
let injections = buildInjections(container, registry.getTypeInjections(type), registry.getInjections(fullName));
injections._debugContainerKey = fullName;

setOwner(injections, container.owner);
Expand All @@ -507,8 +488,7 @@ function instantiate(factory, props, container, fullName) {

if (factory) {
if (typeof factory.create !== 'function') {
throw new Error(`Failed to create an instance of '${fullName}'. Most likely an improperly defined class or` +
` an invalid module export.`);
throw new Error(`Failed to create an instance of '${fullName}'. Most likely an improperly defined class or` + ` an invalid module export.`);
}

validationCache = container.validationCache;
Expand Down Expand Up @@ -558,9 +538,7 @@ function factoryInjectionsFor(container, fullName) {
let splitName = fullName.split(':');
let type = splitName[0];

let factoryInjections = buildInjections(container,
registry.getFactoryTypeInjections(type),
registry.getFactoryInjections(fullName));
let factoryInjections = buildInjections(container, registry.getFactoryTypeInjections(type), registry.getFactoryInjections(fullName));
factoryInjections._debugContainerKey = fullName;

return factoryInjections;
Expand All @@ -573,18 +551,12 @@ function injectDeprecatedContainer(object, container) {
configurable: true,
enumerable: false,
get() {
deprecate('Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.',
false,
{ id: 'ember-application.injected-container', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access' });
deprecate('Using the injected `container` is deprecated. Please use the `getOwner` helper instead to access the owner of this object.', false, { id: 'ember-application.injected-container', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access' });
return this[CONTAINER_OVERRIDE] || container;
},

set(value) {
deprecate(
`Providing the \`container\` property to ${this} is deprecated. Please use \`Ember.setOwner\` or \`owner.ownerInjection()\` instead to provide an owner to the instance being created.`,
false,
{ id: 'ember-application.injected-container', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access' }
);
deprecate(`Providing the \`container\` property to ${this} is deprecated. Please use \`Ember.setOwner\` or \`owner.ownerInjection()\` instead to provide an owner to the instance being created.`, false, { id: 'ember-application.injected-container', until: '3.0.0', url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access' });

this[CONTAINER_OVERRIDE] = value;

Expand All @@ -608,7 +580,7 @@ function eachDestroyable(container, callback) {
}

function resetCache(container) {
eachDestroyable(container, (value) => {
eachDestroyable(container, value => {
if (value.destroy) {
value.destroy();
}
Expand Down Expand Up @@ -646,16 +618,12 @@ export function buildFakeContainerWithDeprecations(container) {
}

function buildFakeContainerFunction(container, containerProperty, ownerProperty) {
return function() {
deprecate(
`Using the injected \`container\` is deprecated. Please use the \`getOwner\` helper to access the owner of this object and then call \`${ownerProperty}\` instead.`,
false,
{
id: 'ember-application.injected-container',
until: '3.0.0',
url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access'
}
);
return function () {
deprecate(`Using the injected \`container\` is deprecated. Please use the \`getOwner\` helper to access the owner of this object and then call \`${ownerProperty}\` instead.`, false, {
id: 'ember-application.injected-container',
until: '3.0.0',
url: 'http://emberjs.com/deprecations/v2.x#toc_injected-container-access'
});
return container[containerProperty](...arguments);
};
}
Expand Down Expand Up @@ -702,8 +670,7 @@ class FactoryManager {
});

if (!this.class.create) {
throw new Error(`Failed to create an instance of '${this.normalizedName}'. Most likely an improperly defined class or` +
` an invalid module export.`);
throw new Error(`Failed to create an instance of '${this.normalizedName}'. Most likely an improperly defined class or` + ` an invalid module export.`);
}

let prototype = this.class.prototype;
Expand All @@ -713,4 +680,4 @@ class FactoryManager {

return this.class.create(props);
}
}
}
2 changes: 1 addition & 1 deletion packages/container/lib/registry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dictionary, assign, intern } from 'ember-utils';
import { assert, deprecate } from 'ember-metal';
import { assert, deprecate } from 'ember-debug';
import Container from './container';

const VALID_FULL_NAME_REGEXP = /^[^:]+:[^:]+$/;
Expand Down
Loading