Skip to content

Commit

Permalink
[BUGFIX] MODEL_FACTORY_INJECTIONS is now always false.
Browse files Browse the repository at this point in the history
Double extend means this flag no longer means what it once did. To ensure ember-data functions correctly, we should now force it to always be false.
  • Loading branch information
stefanpenner committed May 4, 2017
1 parent 21d8d28 commit 59ad983
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 35 deletions.
13 changes: 1 addition & 12 deletions packages/container/tests/container_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,7 @@ import { get } from 'ember-metal';
import { Registry } from '..';
import { factory } from 'internal-test-helpers';

let originalModelInjections;

QUnit.module('Container', {
setup() {
originalModelInjections = ENV.MODEL_FACTORY_INJECTIONS;
},
teardown() {
ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections;
}
});
QUnit.module('Container');

QUnit.test('A registered factory returns the same instance each time', function() {
let registry = new Registry();
Expand Down Expand Up @@ -166,8 +157,6 @@ QUnit.test('An invalid factory throws an error', function() {
});

QUnit.test('Injecting a failed lookup raises an error', function() {
ENV.MODEL_FACTORY_INJECTIONS = true;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import Application from '../../../system/application';
import { Object as EmberObject } from 'ember-runtime';
import DefaultResolver from '../../../system/resolver';

let originalLookup, App, originalModelInjections;
let originalLookup, App;

QUnit.module('Ember.Application Dependency Injection – toString', {
setup() {
originalModelInjections = ENV.MODEL_FACTORY_INJECTIONS;
ENV.MODEL_FACTORY_INJECTIONS = true;

originalLookup = context.lookup;

run(() => {
Expand All @@ -27,7 +24,6 @@ QUnit.module('Ember.Application Dependency Injection – toString', {
teardown() {
context.lookup = originalLookup;
run(App, 'destroy');
ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections;
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import Application from '../../system/application';
let EmberApplication = Application;

let originalLookup = context.lookup;
let registry, locator, application, originalModelInjections;
let registry, locator, application;

QUnit.module('Ember.Application Dependency Injection', {
setup() {
originalModelInjections = ENV.MODEL_FACTORY_INJECTIONS;
ENV.MODEL_FACTORY_INJECTIONS = true;

application = run(EmberApplication, 'create');

application.Person = EmberObject.extend({});
Expand All @@ -36,7 +33,6 @@ QUnit.module('Ember.Application Dependency Injection', {
run(application, 'destroy');
application = locator = null;
context.lookup = originalLookup;
ENV.MODEL_FACTORY_INJECTIONS = originalModelInjections;
}
});

Expand Down
6 changes: 4 additions & 2 deletions packages/ember-environment/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ ENV.LOG_STACKTRACE_ON_DEPRECATION = defaultTrue(ENV.LOG_STACKTRACE_ON_DEPRECATIO
*/
ENV.LOG_VERSION = defaultTrue(ENV.LOG_VERSION);

// default false
ENV.MODEL_FACTORY_INJECTIONS = defaultFalse(ENV.MODEL_FACTORY_INJECTIONS);
// always false
Object.defineProperty(ENV, 'MODEL_FACTORY_INJECTIONS', {
get() { return false; }
});

/**
Debug parameter you can turn on. This will log all bindings that fire to
Expand Down
1 change: 0 additions & 1 deletion packages/ember-extension-support/lib/data_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ export default EmberObject.extend({
if (!namespace.hasOwnProperty(key)) { continue; }
// Even though we will filter again in `getModelTypes`,
// we should not call `lookupFactory` on non-models
// (especially when `EmberENV.MODEL_FACTORY_INJECTIONS` is `true`)
if (!this.detect(namespace[key])) { continue; }
let name = StringUtils.dasherize(key);
types.push(name);
Expand Down
5 changes: 0 additions & 5 deletions packages/ember-runtime/lib/mixins/registry_proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,6 @@ export default Mixin.create({
directly (via `create` or `new`) bypasses the dependency injection
system.
**Note:** Ember-Data instantiates its models in a unique manner, and consequently
injections onto models (or all models) will not work as expected. Injections
on models can be enabled by setting `EmberENV.MODEL_FACTORY_INJECTIONS`
to `true`.
@public
@method inject
@param factoryNameOrType {String}
Expand Down
24 changes: 19 additions & 5 deletions packages/ember/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,25 @@ Object.defineProperty(Ember, 'LOG_VERSION', {
enumerable: false
});

Object.defineProperty(Ember, 'MODEL_FACTORY_INJECTIONS', {
get() { return ENV.MODEL_FACTORY_INJECTIONS; },
set(value) { ENV.MODEL_FACTORY_INJECTIONS = !!value; },
enumerable: false
});
if (DEBUG) {
Object.defineProperty(Ember, 'MODEL_FACTORY_INJECTIONS', {
get() { return false; },
set(value) {

deprecate(
'Ember.MODEL_FACTORY_INJECTIONS is no longer required',
false,
{
id: 'ember-metal.model_factory_injections',
until: '3.0.0',
url: 'http://emberjs.com/deprecations/v2.x#toc_code-ember-model-factory-injections'
}
);
Ember.logger.warn('As of 2.13.x MODEL_FACTORY_INJECTIONS has no power, feel free to remove it from app/app.js');
},
enumerable: false
});
}

Object.defineProperty(Ember, 'LOG_BINDINGS', {
get() { return ENV.LOG_BINDINGS; },
Expand Down

0 comments on commit 59ad983

Please sign in to comment.