Skip to content

Commit

Permalink
Merge pull request #28 from thoov/arity
Browse files Browse the repository at this point in the history
Add initializer initialize arguments deprecation
  • Loading branch information
rwjblue committed Dec 13, 2017
2 parents 25b2b02 + 96c8ccf commit 5e6110c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module.exports = function(/* environment, appConfig */) {
_ENABLE_RESOLVER_FUNCTION_SUPPORT: true,
_ENABLE_DID_INIT_ATTRS_SUPPORT: true,
_ENABLE_RENDER_SUPPORT: true,
_ENABLE_REVERSED_OBSERVER_SUPPORT: true
_ENABLE_REVERSED_OBSERVER_SUPPORT: true,
_ENABLE_INITIALIZER_ARGUMENTS_SUPPORT: true
}
};
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ module.exports = {
this.import('vendor/enumerable-contains.js');
this.import('vendor/underscore-actions.js');
this.import('vendor/reversed-observer.js');
this.import('vendor/initializer-arity.js');
}
};
10 changes: 10 additions & 0 deletions tests/acceptance/arity-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';

moduleForAcceptance('Acceptance | Initializer Initialize is deprecated for 2 arguments');

test('that a deprecation is thrown when 2 arguments are present in the initializers initalize method', function(assert) {
assert.expectDeprecation('The `initialize` method for Application initializer \'arity\' should take only one argument - `App`, an instance of an `Application`');

visit('/');
});
9 changes: 9 additions & 0 deletions tests/dummy/app/initializers/arity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//eslint-disable-next-line no-unused-vars
export function initialize(container, application) {
// this is left blank
}

export default {
name: 'arity',
initialize: initialize
}
36 changes: 36 additions & 0 deletions vendor/initializer-arity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
(function() {
var _Ember;
if (typeof Ember !== 'undefined') {
_Ember = Ember;
} else {
_Ember = require('ember').default;
}

if (EmberENV && EmberENV._ENABLE_INITIALIZER_ARGUMENTS_SUPPORT !== true) {
return false;
}

_Ember.Engine.reopen({
/**
@private
@method runInitializers
*/
runInitializers() {
this._runInitializer('initializers', (name, initializer) => {
_Ember.assert(`No application initializer named '${name}'`, !!initializer);
if (initializer.initialize.length === 2) {
_Ember.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);
}
});
}
})
})();

0 comments on commit 5e6110c

Please sign in to comment.