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

[WIP] Deprecate component lifecycle hook arguments #14711

Merged
merged 3 commits into from
Jan 9, 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
5 changes: 3 additions & 2 deletions packages/ember-glimmer/lib/syntax/curly-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
_instrumentStart
} from 'ember-metal';
import {
dispatchLifeCycleHook,
setViewElement
} from 'ember-views';
import {
Expand Down Expand Up @@ -342,8 +343,8 @@ class CurlyComponentManager {
component.setProperties(props);
component[IS_DISPATCHING_ATTRS] = false;

component.trigger('didUpdateAttrs', { oldAttrs, newAttrs });
component.trigger('didReceiveAttrs', { oldAttrs, newAttrs });
dispatchLifeCycleHook(component, 'didUpdateAttrs', oldAttrs, newAttrs);
dispatchLifeCycleHook(component, 'didReceiveAttrs', oldAttrs, newAttrs);
}

if (environment.isInteractive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2897,6 +2897,70 @@ moduleFor('Components test: curly components', class extends RenderingTest {
assert.strictEqual(barCopyDidChangeCount, 1, 'expected observer firing for: barCopy');
}

['@test overriding didReceiveAttrs does not trigger deprecation'](assert) {
this.registerComponent('foo-bar', {
ComponentClass: Component.extend({
didReceiveAttrs() {
assert.equal(1, this.get('foo'), 'expected attrs to have correct value')
}
}),

template: '{{foo}}-{{fooCopy}}-{{bar}}-{{barCopy}}'
});

this.render(`{{foo-bar foo=foo bar=bar}}`, { foo: 1, bar: 3 });
}

['@test can access didReceiveAttrs arguments [DEPRECATED]'](assert) {
expectDeprecation(/didReceiveAttrs.*stop taking arguments/);

this.registerComponent('foo-bar', {
ComponentClass: Component.extend({
didReceiveAttrs({ attrs }) {
assert.equal(1, attrs.foo.value, 'expected attrs to have correct value')
}
}),

template: '{{foo}}-{{fooCopy}}-{{bar}}-{{barCopy}}'
});

this.render(`{{foo-bar foo=foo bar=bar}}`, { foo: 1, bar: 3 });
}

['@test can access didUpdateAttrs arguments [DEPRECATED]'](assert) {
expectDeprecation(/didUpdateAttrs.*stop taking arguments/);

this.registerComponent('foo-bar', {
ComponentClass: Component.extend({
didUpdateAttrs({ newAttrs }) {
assert.equal(5, newAttrs.foo.value, "expected newAttrs to have new value");
}
}),

template: '{{foo}}-{{fooCopy}}-{{bar}}-{{barCopy}}'
});

this.render(`{{foo-bar foo=foo bar=bar}}`, { foo: 1, bar: 3 });

this.runTask(() => set(this.context, 'foo', 5));
}

['@test overriding didUpdateAttrs does not trigger deprecation'](assert) {
this.registerComponent('foo-bar', {
ComponentClass: Component.extend({
didUpdateAttrs() {
assert.equal(5, this.get('foo'), "expected newAttrs to have new value");
}
}),

template: '{{foo}}-{{fooCopy}}-{{bar}}-{{barCopy}}'
});

this.render(`{{foo-bar foo=foo bar=bar}}`, { foo: 1, bar: 3 });

this.runTask(() => set(this.context, 'foo', 5));
}

['@test returning `true` from an action does not bubble if `target` is not specified (GH#14275)'](assert) {
this.registerComponent('display-toggle', {
ComponentClass: Component.extend({
Expand Down
129 changes: 65 additions & 64 deletions packages/ember-glimmer/tests/integration/components/life-cycle-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,22 +307,22 @@ class LifeCycleHooksTest extends RenderingTest {
// Sync hooks

['the-top', 'init'],
['the-top', 'didInitAttrs', { attrs: topAttrs }],
['the-top', 'didReceiveAttrs', { newAttrs: topAttrs }],
['the-top', 'didInitAttrs', { attrs: topAttrs, newAttrs: topAttrs }],
['the-top', 'didReceiveAttrs', { attrs: topAttrs, newAttrs: topAttrs }],
['the-top', 'on(init)'],
['the-top', 'willRender'],
['the-top', 'willInsertElement'],

['the-middle', 'init'],
['the-middle', 'didInitAttrs', { attrs: middleAttrs }],
['the-middle', 'didReceiveAttrs', { newAttrs: middleAttrs }],
['the-middle', 'didInitAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }],
['the-middle', 'didReceiveAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }],
['the-middle', 'on(init)'],
['the-middle', 'willRender'],
['the-middle', 'willInsertElement'],

['the-bottom', 'init'],
['the-bottom', 'didInitAttrs', { attrs: bottomAttrs }],
['the-bottom', 'didReceiveAttrs', { newAttrs: bottomAttrs }],
['the-bottom', 'didInitAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }],
['the-bottom', 'didReceiveAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }],
['the-bottom', 'on(init)'],
['the-bottom', 'willRender'],
['the-bottom', 'willInsertElement'],
Expand All @@ -343,18 +343,18 @@ class LifeCycleHooksTest extends RenderingTest {
nonInteractive: [
// Sync hooks
['the-top', 'init'],
['the-top', 'didInitAttrs', { attrs: topAttrs }],
['the-top', 'didReceiveAttrs', { newAttrs: topAttrs }],
['the-top', 'didInitAttrs', { attrs: topAttrs, newAttrs: topAttrs }],
['the-top', 'didReceiveAttrs', { attrs: topAttrs, newAttrs: topAttrs }],
['the-top', 'on(init)'],

['the-middle', 'init'],
['the-middle', 'didInitAttrs', { attrs: middleAttrs }],
['the-middle', 'didReceiveAttrs', { newAttrs: middleAttrs }],
['the-middle', 'didInitAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }],
['the-middle', 'didReceiveAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }],
['the-middle', 'on(init)'],

['the-bottom', 'init'],
['the-bottom', 'didInitAttrs', { attrs: bottomAttrs }],
['the-bottom', 'didReceiveAttrs', { newAttrs: bottomAttrs }],
['the-bottom', 'didInitAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }],
['the-bottom', 'didReceiveAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }],
['the-bottom', 'on(init)']
]
});
Expand Down Expand Up @@ -452,7 +452,7 @@ class LifeCycleHooksTest extends RenderingTest {
// the new attribute to rerender itself imperatively, that would result
// in lifecycle hooks being invoked for the child.

topAttrs = { oldAttrs: { twitter: '@tomdale' }, newAttrs: { twitter: '@horsetomdale' } };
topAttrs = { attrs: { twitter: '@horsetomdale' }, oldAttrs: { twitter: '@tomdale' }, newAttrs: { twitter: '@horsetomdale' } };

this.assertHooks({
label: 'after update',
Expand Down Expand Up @@ -551,30 +551,30 @@ class LifeCycleHooksTest extends RenderingTest {
// Sync hooks

['the-parent', 'init'],
['the-parent', 'didInitAttrs', { attrs: parentAttrs }],
['the-parent', 'didReceiveAttrs', { newAttrs: parentAttrs }],
['the-parent', 'didInitAttrs', { attrs: parentAttrs, newAttrs: parentAttrs }],
['the-parent', 'didReceiveAttrs', { attrs: parentAttrs, newAttrs: parentAttrs }],
['the-parent', 'on(init)'],
['the-parent', 'willRender'],
['the-parent', 'willInsertElement'],


['the-first-child', 'init'],
['the-first-child', 'didInitAttrs', { attrs: firstAttrs }],
['the-first-child', 'didReceiveAttrs', { newAttrs: firstAttrs }],
['the-first-child', 'didInitAttrs', { attrs: firstAttrs, newAttrs: firstAttrs }],
['the-first-child', 'didReceiveAttrs', { attrs: firstAttrs, newAttrs: firstAttrs }],
['the-first-child', 'on(init)'],
['the-first-child', 'willRender'],
['the-first-child', 'willInsertElement'],

['the-second-child', 'init'],
['the-second-child', 'didInitAttrs', { attrs: secondAttrs }],
['the-second-child', 'didReceiveAttrs', { newAttrs: secondAttrs }],
['the-second-child', 'didInitAttrs', { attrs: secondAttrs, newAttrs: secondAttrs }],
['the-second-child', 'didReceiveAttrs', { attrs: secondAttrs, newAttrs: secondAttrs }],
['the-second-child', 'on(init)'],
['the-second-child', 'willRender'],
['the-second-child', 'willInsertElement'],

['the-last-child', 'init'],
['the-last-child', 'didInitAttrs', { attrs: lastAttrs }],
['the-last-child', 'didReceiveAttrs', { newAttrs: lastAttrs }],
['the-last-child', 'didInitAttrs', { attrs: lastAttrs, newAttrs: lastAttrs }],
['the-last-child', 'didReceiveAttrs', { attrs: lastAttrs, newAttrs: lastAttrs }],
['the-last-child', 'on(init)'],
['the-last-child', 'willRender'],
['the-last-child', 'willInsertElement'],
Expand All @@ -598,23 +598,23 @@ class LifeCycleHooksTest extends RenderingTest {
// Sync hooks

['the-parent', 'init'],
['the-parent', 'didInitAttrs', { attrs: parentAttrs }],
['the-parent', 'didReceiveAttrs', { newAttrs: parentAttrs }],
['the-parent', 'didInitAttrs', { attrs: parentAttrs, newAttrs: parentAttrs }],
['the-parent', 'didReceiveAttrs', { attrs: parentAttrs, newAttrs: parentAttrs }],
['the-parent', 'on(init)'],

['the-first-child', 'init'],
['the-first-child', 'didInitAttrs', { attrs: firstAttrs }],
['the-first-child', 'didReceiveAttrs', { newAttrs: firstAttrs }],
['the-first-child', 'didInitAttrs', { attrs: firstAttrs, newAttrs: firstAttrs }],
['the-first-child', 'didReceiveAttrs', { attrs: firstAttrs, newAttrs: firstAttrs }],
['the-first-child', 'on(init)'],

['the-second-child', 'init'],
['the-second-child', 'didInitAttrs', { attrs: secondAttrs }],
['the-second-child', 'didReceiveAttrs', { newAttrs: secondAttrs }],
['the-second-child', 'didInitAttrs', { attrs: secondAttrs, newAttrs: secondAttrs }],
['the-second-child', 'didReceiveAttrs', { attrs: secondAttrs, newAttrs: secondAttrs }],
['the-second-child', 'on(init)'],

['the-last-child', 'init'],
['the-last-child', 'didInitAttrs', { attrs: lastAttrs }],
['the-last-child', 'didReceiveAttrs', { newAttrs: lastAttrs }],
['the-last-child', 'didInitAttrs', { attrs: lastAttrs, newAttrs: lastAttrs }],
['the-last-child', 'didReceiveAttrs', { attrs: lastAttrs, newAttrs: lastAttrs }],
['the-last-child', 'on(init)']
]
});
Expand Down Expand Up @@ -734,12 +734,13 @@ class LifeCycleHooksTest extends RenderingTest {
this.assertText('Twitter: @horsetomdale|Name: Horse Tom Dale|Website: horsetomdale.net');

parentAttrs = {
attrs: { twitter: '@horsetomdale', name: 'Horse Tom Dale', website: 'horsetomdale.net' },
oldAttrs: { twitter: '@tomdale', name: 'Tom Dale', website: 'tomdale.net' },
newAttrs: { twitter: '@horsetomdale', name: 'Horse Tom Dale', website: 'horsetomdale.net' }
};
firstAttrs = { oldAttrs: { twitter: '@tomdale' }, newAttrs: { twitter: '@horsetomdale' } };
secondAttrs = { oldAttrs: { name: 'Tom Dale' }, newAttrs: { name: 'Horse Tom Dale' } };
lastAttrs = { oldAttrs: { website: 'tomdale.net' }, newAttrs: { website: 'horsetomdale.net' } };
firstAttrs = { attrs: { twitter: '@horsetomdale' }, oldAttrs: { twitter: '@tomdale' }, newAttrs: { twitter: '@horsetomdale' } };
secondAttrs = { attrs: { name: 'Horse Tom Dale' }, oldAttrs: { name: 'Tom Dale' }, newAttrs: { name: 'Horse Tom Dale' } };
lastAttrs = { attrs: { website: 'horsetomdale.net' }, oldAttrs: { website: 'tomdale.net' }, newAttrs: { website: 'horsetomdale.net' } };

this.assertHooks({
label: 'after update',
Expand Down Expand Up @@ -877,22 +878,22 @@ class LifeCycleHooksTest extends RenderingTest {
// Sync hooks

['the-top', 'init'],
['the-top', 'didInitAttrs', { attrs: topAttrs }],
['the-top', 'didReceiveAttrs', { newAttrs: topAttrs }],
['the-top', 'didInitAttrs', { attrs: topAttrs, newAttrs: topAttrs }],
['the-top', 'didReceiveAttrs', { attrs: topAttrs, newAttrs: topAttrs }],
['the-top', 'on(init)'],
['the-top', 'willRender'],
['the-top', 'willInsertElement'],

['the-middle', 'init'],
['the-middle', 'didInitAttrs', { attrs: middleAttrs }],
['the-middle', 'didReceiveAttrs', { newAttrs: middleAttrs }],
['the-middle', 'didInitAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }],
['the-middle', 'didReceiveAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }],
['the-middle', 'on(init)'],
['the-middle', 'willRender'],
['the-middle', 'willInsertElement'],

['the-bottom', 'init'],
['the-bottom', 'didInitAttrs', { attrs: bottomAttrs }],
['the-bottom', 'didReceiveAttrs', { newAttrs: bottomAttrs }],
['the-bottom', 'didInitAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }],
['the-bottom', 'didReceiveAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }],
['the-bottom', 'on(init)'],
['the-bottom', 'willRender'],
['the-bottom', 'willInsertElement'],
Expand All @@ -913,18 +914,18 @@ class LifeCycleHooksTest extends RenderingTest {
// Sync hooks

['the-top', 'init'],
['the-top', 'didInitAttrs', { attrs: topAttrs }],
['the-top', 'didReceiveAttrs', { newAttrs: topAttrs }],
['the-top', 'didInitAttrs', { attrs: topAttrs, newAttrs: topAttrs }],
['the-top', 'didReceiveAttrs', { attrs: topAttrs, newAttrs: topAttrs }],
['the-top', 'on(init)'],

['the-middle', 'init'],
['the-middle', 'didInitAttrs', { attrs: middleAttrs }],
['the-middle', 'didReceiveAttrs', { newAttrs: middleAttrs }],
['the-middle', 'didInitAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }],
['the-middle', 'didReceiveAttrs', { attrs: middleAttrs, newAttrs: middleAttrs }],
['the-middle', 'on(init)'],

['the-bottom', 'init'],
['the-bottom', 'didInitAttrs', { attrs: bottomAttrs }],
['the-bottom', 'didReceiveAttrs', { newAttrs: bottomAttrs }],
['the-bottom', 'didInitAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }],
['the-bottom', 'didReceiveAttrs', { attrs: bottomAttrs, newAttrs: bottomAttrs }],
['the-bottom', 'on(init)']
]
});
Expand All @@ -936,9 +937,9 @@ class LifeCycleHooksTest extends RenderingTest {
// Because the `twitter` attr is used by the all of the components,
// the lifecycle hooks are invoked for all components.

topAttrs = { oldAttrs: { twitter: '@tomdale' }, newAttrs: { twitter: '@horsetomdale' } };
middleAttrs = { oldAttrs: { twitterTop: '@tomdale' }, newAttrs: { twitterTop: '@horsetomdale' } };
bottomAttrs = { oldAttrs: { twitterMiddle: '@tomdale' }, newAttrs: { twitterMiddle: '@horsetomdale' } };
topAttrs = { attrs: { twitter: '@horsetomdale' }, oldAttrs: { twitter: '@tomdale' }, newAttrs: { twitter: '@horsetomdale' } };
middleAttrs = { attrs: { twitterTop: '@horsetomdale' }, oldAttrs: { twitterTop: '@tomdale' }, newAttrs: { twitterTop: '@horsetomdale' } };
bottomAttrs = { attrs: { twitterMiddle: '@horsetomdale' }, oldAttrs: { twitterMiddle: '@tomdale' }, newAttrs: { twitterMiddle: '@horsetomdale' } };

this.assertHooks({
label: 'after updating (root)',
Expand Down Expand Up @@ -996,9 +997,9 @@ class LifeCycleHooksTest extends RenderingTest {

// In this case, because the attrs are passed down, all child components are invoked.

topAttrs = { oldAttrs: { twitter: '@horsetomdale' }, newAttrs: { twitter: '@horsetomdale' } };
middleAttrs = { oldAttrs: { twitterTop: '@horsetomdale' }, newAttrs: { twitterTop: '@horsetomdale' } };
bottomAttrs = { oldAttrs: { twitterMiddle: '@horsetomdale' }, newAttrs: { twitterMiddle: '@horsetomdale' } };
topAttrs = { attrs: { twitter: '@horsetomdale' }, oldAttrs: { twitter: '@horsetomdale' }, newAttrs: { twitter: '@horsetomdale' } };
middleAttrs = { attrs: { twitterTop: '@horsetomdale' }, oldAttrs: { twitterTop: '@horsetomdale' }, newAttrs: { twitterTop: '@horsetomdale' } };
bottomAttrs = { attrs: { twitterMiddle: '@horsetomdale' }, oldAttrs: { twitterMiddle: '@horsetomdale' }, newAttrs: { twitterMiddle: '@horsetomdale' } };

this.assertHooks({
label: 'after no-op rernder (root)',
Expand Down Expand Up @@ -1065,8 +1066,8 @@ class LifeCycleHooksTest extends RenderingTest {
let initialHooks = (count) => {
let ret = [
['an-item', 'init'],
['an-item', 'didInitAttrs', { attrs: { count } }],
['an-item', 'didReceiveAttrs', { newAttrs: { count } }],
['an-item', 'didInitAttrs', { attrs: { count }, newAttrs: { count } }],
['an-item', 'didReceiveAttrs', { attrs: { count }, newAttrs: { count } }],
['an-item', 'on(init)']
];
if (this.isInteractive) {
Expand All @@ -1077,8 +1078,8 @@ class LifeCycleHooksTest extends RenderingTest {
}
ret.push(
['nested-item', 'init'],
['nested-item', 'didInitAttrs', { attrs: { } }],
['nested-item', 'didReceiveAttrs', { newAttrs: { } }],
['nested-item', 'didInitAttrs', { attrs: { }, newAttrs: { } }],
['nested-item', 'didReceiveAttrs', { attrs: { }, newAttrs: { } }],
['nested-item', 'on(init)']
);
if (this.isInteractive) {
Expand Down Expand Up @@ -1179,16 +1180,16 @@ class LifeCycleHooksTest extends RenderingTest {
['nested-item', 'willClearRender'],

['no-items', 'init'],
['no-items', 'didInitAttrs', { attrs: { } }],
['no-items', 'didReceiveAttrs', { newAttrs: { } }],
['no-items', 'didInitAttrs', { attrs: { }, newAttrs: { } }],
['no-items', 'didReceiveAttrs', { attrs: { }, newAttrs: { } }],
['no-items', 'on(init)'],
['no-items', 'willRender'],
['no-items', 'willInsertElement'],


['nested-item', 'init'],
['nested-item', 'didInitAttrs', { attrs: { } }],
['nested-item', 'didReceiveAttrs', { newAttrs: { } }],
['nested-item', 'didInitAttrs', { attrs: { }, newAttrs: { } }],
['nested-item', 'didReceiveAttrs', { attrs: { }, newAttrs: { } }],
['nested-item', 'on(init)'],
['nested-item', 'willRender'],
['nested-item', 'willInsertElement'],
Expand Down Expand Up @@ -1223,13 +1224,13 @@ class LifeCycleHooksTest extends RenderingTest {

nonInteractive: [
['no-items', 'init'],
['no-items', 'didInitAttrs', { attrs: { } }],
['no-items', 'didReceiveAttrs', { newAttrs: { } }],
['no-items', 'didInitAttrs', { attrs: { }, newAttrs: { } }],
['no-items', 'didReceiveAttrs', { attrs: { }, newAttrs: { } }],
['no-items', 'on(init)'],

['nested-item', 'init'],
['nested-item', 'didInitAttrs', { attrs: { } }],
['nested-item', 'didReceiveAttrs', { newAttrs: { } }],
['nested-item', 'didInitAttrs', { attrs: { }, newAttrs: { } }],
['nested-item', 'didReceiveAttrs', { attrs: { }, newAttrs: { } }],
['nested-item', 'on(init)'],

['an-item', 'willDestroy'],
Expand Down Expand Up @@ -1624,8 +1625,8 @@ function expr(value) {
return { isExpr: true, value };
}

function hook(name, hook, args) {
return { name, hook, args };
function hook(name, hook, { attrs, oldAttrs, newAttrs } = {}) {
return { name, hook, args: { attrs, oldAttrs, newAttrs } };
}

function json(serializable) {
Expand Down
Loading