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 beta] Ensure parentView includes yielding component. #11266

Merged
merged 1 commit into from
May 25, 2015
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
2 changes: 1 addition & 1 deletion packages/ember-htmlbars/lib/hooks/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function componentHook(renderNode, env, scope, _tagName, params,
}

var read = env.hooks.getValue;
var parentView = read(env.view);
var parentView = read(scope.view);

var manager = ComponentNodeManager.create(renderNode, env, {
tagName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,44 @@ QUnit.test("comopnent should rerender when a property is changed during children

});

QUnit.test("components in template of a yielding component should have the proper parentView", function() {
var outer, innerTemplate, innerLayout;

registry.register('component:x-outer', Component.extend({
init() {
this._super(...arguments);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact: This transpiles directly to:

this._super.apply(this, arguments);

Which is awesome. Elsewhere in ember we use (and I am far less crazy about):

registry.register('component:x-outer', Component.extend({
   init(...args) {
    this._super(...args);
    outer = this;
      }
 }));

Which builds an intermediate array of args before unrolling.

outer = this;
}
}));

registry.register('component:x-inner-in-template', Component.extend({
init() {
this._super(...arguments);
innerTemplate = this;
}
}));

registry.register('component:x-inner-in-layout', Component.extend({
init() {
this._super(...arguments);
innerLayout = this;
}
}));

registry.register('template:components/x-outer', compile('{{x-inner-in-layout}}{{yield}}'));

view = EmberView.extend({
template: compile('{{#x-outer}}{{x-inner-in-template}}{{/x-outer}}'),
container: container
}).create();

runAppend(view);

equal(innerTemplate.parentView, outer, 'receives the wrapping component as its parentView in template blocks');
equal(innerLayout.parentView, outer, 'receives the wrapping component as its parentView in layout');
equal(outer.parentView, view, 'x-outer receives the ambient scope as its parentView');
});

QUnit.test("comopnent should rerender when a property (with a default) is changed during children's rendering", function() {
expectDeprecation(/modified value twice in a single render/);

Expand Down