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

Show deprecation warning when using didInitAttrs #13207

Merged
merged 1 commit into from
Mar 30, 2016
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
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