Skip to content

Commit

Permalink
Merge pull request #13207 from stearagon/deprecate-did-init-attrs
Browse files Browse the repository at this point in the history
Show deprecation warning when using didInitAttrs
  • Loading branch information
rwjblue committed Mar 30, 2016
2 parents 3084885 + 3f7bc15 commit ad32d4a
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ styles.forEach(style => {
twitter: '@tomdale'
}).create();

runAppend(view);
expectDeprecation(() => {
runAppend(view);
}, /\[DEPRECATED\] didInitAttrs called in <\(subclass of Ember.Component\)\:ember[\d+]+>\./);

ok(component, 'The component was inserted');
equal(jQuery('#qunit-fixture').text(), 'Twitter: @tomdale Name: Tom Dale Website: tomdale.net');
Expand Down Expand Up @@ -285,7 +287,9 @@ styles.forEach(style => {
twitter: '@tomdale'
}).create();

runAppend(view);
expectDeprecation(() => {
runAppend(view);
}, /\[DEPRECATED\] didInitAttrs called in <\(subclass of Ember.Component\)\:ember[\d+]+>\./);

ok(component, 'The component was inserted');
equal(jQuery('#qunit-fixture').text(), 'Top: Middle: Bottom: @tomdale');
Expand Down Expand Up @@ -361,7 +365,9 @@ styles.forEach(style => {
});

QUnit.test('changing a component\'s displayed properties inside didInsertElement() is deprecated', function(assert) {
let component = style.class.extend({
let component;

component = style.class.extend({
[OWNER]: owner,
layout: compile('<div>{{handle}}</div>'),
handle: '@wycats',
Expand All @@ -382,6 +388,28 @@ styles.forEach(style => {
});
});

QUnit.test('DEPRECATED: didInitAttrs is deprecated', function(assert) {
let component;

let componentClass = style.class.extend({
[OWNER]: owner,
layout: compile('<div>{{handle}}</div>'),
handle: '@wycats',

didInitAttrs() {
this._super(...arguments);
}
});

expectDeprecation(() => {
component = componentClass.create();
}, /\[DEPRECATED\] didInitAttrs called in <\(subclass of Ember.Component\)\:ember[\d+]+>\./);

run(() => {
component.destroy();
});
});

QUnit.test('properties set during `init` are availabe in `didReceiveAttrs`', function(assert) {
assert.expect(1);

Expand Down
13 changes: 13 additions & 0 deletions packages/ember-metal/lib/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
applyStr
} from 'ember-metal/utils';
import { meta as metaFor, peekMeta } from 'ember-metal/meta';
import { deprecate } from 'ember-metal/debug';

import { ONCE, SUSPENDED } from 'ember-metal/meta_listeners';

Expand Down Expand Up @@ -84,6 +85,18 @@ export function accumulateListeners(obj, eventName, otherActions) {
export function addListener(obj, eventName, target, method, once) {
assert('You must pass at least an object and event name to Ember.addListener', !!obj && !!eventName);

if (eventName === 'didInitAttrs' && obj.isComponent) {
deprecate(
`[DEPRECATED] didInitAttrs called in ${obj.toString()}.`,
false,
{
id: 'ember-views.did-init-attrs',
until: '3.0.0',
url: 'http://emberjs.com/deprecations/v2.x#toc_ember-component-didinitattrs'
}
);
}

if (!method && 'function' === typeof target) {
method = target;
target = null;
Expand Down
9 changes: 9 additions & 0 deletions packages/ember-metal/tests/events_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Mixin } from 'ember-metal/mixin';
import { meta } from 'ember-metal/meta';
import Component from 'ember-views/components/component';

import {
on,
Expand Down Expand Up @@ -258,3 +259,11 @@ QUnit.test('a listener added as part of a mixin may be overridden', function() {
sendEvent(obj, 'baz');
equal(triggered, 1, 'should invoke from subclass property');
});

QUnit.test('DEPRECATED: adding didInitAttrs as a listener is deprecated', function() {
var obj = Component.create();

expectDeprecation(() => {
addListener(obj, 'didInitAttrs');
}, /\[DEPRECATED\] didInitAttrs called in <\Ember.Component\:ember[\d+]+>\./);
});
12 changes: 12 additions & 0 deletions packages/ember-views/lib/mixins/view_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,18 @@ export default Mixin.create({

this[INIT_WAS_CALLED] = true;

if (typeof(this.didInitAttrs) === 'function') {
deprecate(
`[DEPRECATED] didInitAttrs called in ${this.toString()}.`,
false,
{
id: 'ember-views.did-init-attrs',
until: '3.0.0',
url: 'http://emberjs.com/deprecations/v2.x#toc_ember-component-didinitattrs'
}
);
}

assert(
'Using a custom `.render` function is no longer supported.',
!this.render
Expand Down

0 comments on commit ad32d4a

Please sign in to comment.