Skip to content

Commit

Permalink
Remove arity check from initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
locks committed Dec 20, 2017
1 parent 5e373fc commit 40bc56c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 35 deletions.
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`./);
}
});

0 comments on commit 40bc56c

Please sign in to comment.