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] Settable layout cp #10920

Merged
merged 1 commit into from
Apr 22, 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
18 changes: 12 additions & 6 deletions packages/ember-views/lib/views/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,14 +763,20 @@ var View = CoreView.extend(

@property layout
@type Function
*/
layout: computed('layoutName', function(key) {
var layoutName = get(this, 'layoutName');
var layout = this.templateForName(layoutName, 'layout');
*/
layout: computed('layoutName', {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we also add defaultLayout to the dependent keys?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe so. I am not sure why defaultLayout still exists, maybe it should be on the chopping block.

Regardless I don't believe a scenario exists where one would invalidate defaultLayout instead of just setting to layout directly or changing layoutName. If some actual use-case does exist, maybe my above statement needs to be taken into re-evaluate. If not, I would prefer not fixing something that serves no purpose and should likely just be removed.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, thank you for clarifying. 😄

get(key) {
var layoutName = get(this, 'layoutName');
var layout = this.templateForName(layoutName, 'layout');

Ember.assert("You specified the layoutName " + layoutName + " for " + this + ", but it did not exist.", !layoutName || !!layout);

Ember.assert("You specified the layoutName " + layoutName + " for " + this + ", but it did not exist.", !layoutName || !!layout);
return layout || get(this, 'defaultLayout');
},

return layout || get(this, 'defaultLayout');
set(key, value) {
return value;
}
}),

_yield(context, options, morph) {
Expand Down
53 changes: 53 additions & 0 deletions packages/ember-views/tests/views/view/layout_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,59 @@ QUnit.test("should call the function of the associated layout", function() {
equal(layoutCalled, 1, "layout is called when layout is present");
});

QUnit.test("changing layoutName after setting layoutName continous to work", function() {
var layoutCalled = 0;
var otherLayoutCalled = 0;

registry.register('template:layout', function() { layoutCalled++; });
registry.register('template:other-layout', function() { otherLayoutCalled++; });

view = EmberView.create({
container: container,
layoutName: 'layout'
});

run(view, 'createElement');
equal(layoutCalled, 1, "layout is called when layout is present");
equal(otherLayoutCalled, 0, "otherLayout is not yet called");

run(() => {
view.set('layoutName', 'other-layout');
view.rerender();
});

equal(layoutCalled, 1, "layout is called when layout is present");
equal(otherLayoutCalled, 1, "otherLayoutis called when layoutName changes, and explicit rerender occurs");
});

QUnit.test("changing layoutName after setting layout CP continous to work", function() {
var layoutCalled = 0;
var otherLayoutCalled = 0;
function otherLayout() {
otherLayoutCalled++;
}

registry.register('template:other-layout', otherLayout);

view = EmberView.create({
container: container,
layout() {
layoutCalled++;
}
});

run(view, 'createElement');
run(() => {
view.set('layoutName', 'other-layout');
view.rerender();
});

equal(view.get('layout'), otherLayout);

equal(layoutCalled, 1, "layout is called when layout is present");
equal(otherLayoutCalled, 1, "otherLayoutis called when layoutName changes, and explicit rerender occurs");
});

QUnit.test("should call the function of the associated template with itself as the context", function() {
registry.register('template:testTemplate', function(dataSource) {
return "<h1 id='twas-called'>template was called for " + get(dataSource, 'personName') + "</h1>";
Expand Down