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 arity check from initializer #15886

Merged
merged 1 commit into from
Dec 20, 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
17 changes: 3 additions & 14 deletions packages/ember-application/lib/system/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
privatize as P
} from 'container';
import DAG from 'dag-map';
import { assert, deprecate } from 'ember-debug';
import { assert } from 'ember-debug';
import { get, set } from 'ember-metal';
import DefaultResolver from './resolver';
import EngineInstance from './engine-instance';
Expand Down Expand Up @@ -124,18 +124,7 @@ const Engine = Namespace.extend(RegistryProxyMixin, {
runInitializers() {
this._runInitializer('initializers', (name, initializer) => {
assert(`No application initializer named '${name}'`, !!initializer);
if (initializer.initialize.length === 2) {
deprecate(`The \`initialize\` method for Application initializer '${name}' should take only one argument - \`App\`, an instance of an \`Application\`.`,
false, {
id: 'ember-application.app-initializer-initialize-arguments',
until: '3.0.0',
url: 'https://emberjs.com/deprecations/v2.x/#toc_initializer-arity'
});

initializer.initialize(this.__registry__, this);
} else {
initializer.initialize(this);
}
initializer.initialize(this);
});
},

Expand Down Expand Up @@ -474,7 +463,7 @@ function resolverFor(namespace) {
}

function buildInitializerMethod(bucketName, humanName) {
return function(initializer) {
return function (initializer) {
// If this is the first initializer being added to a subclass, we are going to reopen the class
// to make sure we have a new `initializers` object, which extends from the parent class' using
// prototypal inheritance. Without this, attempting to add initializers to the subclass would
Expand Down
26 changes: 5 additions & 21 deletions packages/ember-application/tests/system/initializers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ moduleFor('Ember.Application initializers', class extends AutobootApplicationTes
});
}

createSecondApplication(options, MyApplication=Application) {
createSecondApplication(options, MyApplication = Application) {
let myOptions = assign(this.applicationOptions, {
rootElement: '#two'
}, options);
Expand All @@ -42,7 +42,7 @@ moduleFor('Ember.Application initializers', class extends AutobootApplicationTes
});

expectAssertion(() => {
MyApplication.initializer({ initialize() {} });
MyApplication.initializer({ initialize() { } });
});
}

Expand Down Expand Up @@ -329,20 +329,20 @@ moduleFor('Ember.Application initializers', class extends AutobootApplicationTes

FirstApp.initializer({
name: 'abc',
initialize() {}
initialize() { }
});

expectAssertion(() => {
FirstApp.initializer({
name: 'abc',
initialize() {}
initialize() { }
});
});

let SecondApp = Application.extend();
SecondApp.instanceInitializer({
name: 'abc',
initialize() {}
initialize() { }
});

assert.ok(true, 'Two apps can have initializers named the same.');
Expand All @@ -362,20 +362,4 @@ moduleFor('Ember.Application initializers', class extends AutobootApplicationTes

this.runTask(() => this.createApplication({}, MyApplication));
}

[`@test initializers throw a deprecation warning when receiving a second argument`](assert) {
assert.expect(1);

let MyApplication = Application.extend();

MyApplication.initializer({
name: 'deprecated',
initialize(registry, application) { // eslint-disable-line no-unused-vars
}
});

expectDeprecation(() => {
this.runTask(() => this.createApplication({}, MyApplication));
}, /The `initialize` method for Application initializer 'deprecated' should take only one argument - `App`, an instance of an `Application`./);
}
});