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

[BUGFIX release-1-13] Do not require _super in didRecieveAttrs. #12138

Merged
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
37 changes: 37 additions & 0 deletions packages/ember-htmlbars/tests/integration/attrs_lookup_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ComponentLookup from 'ember-views/component_lookup';
import Component from 'ember-views/components/component';
import { runAppend, runDestroy } from 'ember-runtime/tests/utils';
import EmberView from 'ember-views/views/view';
import run from 'ember-metal/run_loop';

var registry, container, view;

Expand Down Expand Up @@ -108,3 +109,39 @@ QUnit.test('should be able to access unspecified attr #12035', function() {
// equal(view.$().text(), 'FIRST ATTR', 'template lookup uses local state');
equal(component.get('woot'), 'yes', 'component found attr');
});

QUnit.test('should not need to call _super in `didReceiveAttrs` (GH #11992)', function() {
expect(12);
var firstValue = 'first';
var secondValue = 'second';

registry.register('component:foo-bar', Component.extend({
didReceiveAttrs() {
let rootFirst = this.get('first');
let rootSecond = this.get('second');
let attrFirst = this.getAttr('first');
let attrSecond = this.getAttr('second');

equal(rootFirst, attrFirst, 'root property matches attrs value');
equal(rootSecond, attrSecond, 'root property matches attrs value');

equal(rootFirst, firstValue, 'matches known value');
equal(rootSecond, secondValue, 'matches known value');
}
}));

view = EmberView.extend({
first: firstValue,
second: secondValue,
template: compile('{{foo-bar first=view.first second=view.second}}'),
container: container
}).create();

runAppend(view);

firstValue = 'asdf';
run(view, 'set', 'first', firstValue);

secondValue = 'jkl;';
run(view, 'set', 'second', secondValue);
});
4 changes: 4 additions & 0 deletions packages/ember-metal-views/lib/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ Renderer.prototype.setAttrs = function (view, attrs) {
}; // set attrs the first time

Renderer.prototype.componentInitAttrs = function (component, attrs) {
// for attrs-proxy support
component.trigger('_internalDidReceiveAttrs');
component.trigger('didInitAttrs', { attrs });
component.trigger('didReceiveAttrs', { newAttrs: attrs });
}; // set attrs the first time
Expand Down Expand Up @@ -181,6 +183,8 @@ Renderer.prototype.componentUpdateAttrs = function (component, newAttrs) {
set(component, 'attrs', newAttrs);
}

// for attrs-proxy support
component.trigger('_internalDidReceiveAttrs');
component.trigger('didUpdateAttrs', { oldAttrs, newAttrs });
component.trigger('didReceiveAttrs', { oldAttrs, newAttrs });
};
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-views/lib/compat/attrs-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let AttrsProxyMixin = {
this._isDispatchingAttrs = false;
}),

didReceiveAttrs() {
_internalDidReceiveAttrs() {
this._super();
this._isDispatchingAttrs = true;
this._propagateAttrsToThis();
Expand Down