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

Fix multiplicative observation of controllers in views #12414

Merged
merged 2 commits into from
Oct 1, 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
10 changes: 0 additions & 10 deletions packages/ember-views/lib/mixins/legacy_view_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,6 @@ var LegacyViewSupport = Mixin.create({

afterRender(buffer) {},

walkChildViews(callback) {
var childViews = this.childViews.slice();

while (childViews.length) {
var view = childViews.pop();
callback(view);
childViews.push(...view.childViews);
}
},

mutateChildViews(callback) {
var childViews = get(this, 'childViews');
var idx = childViews.length;
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-views/lib/mixins/view_context_support.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var ViewContextSupport = Mixin.create(LegacyViewSupport, {
}),

_legacyControllerDidChange: observer('controller', function() {
this.walkChildViews(view => view.notifyPropertyChange('controller'));
this.childViews.forEach(view => view.notifyPropertyChange('controller'));
}),

_notifyControllerChange: on('parentViewDidChange', function() {
Expand Down
42 changes: 42 additions & 0 deletions packages/ember-views/tests/views/view/controller_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,45 @@ QUnit.test('controller property should be inherited from nearest ancestor with c
grandchild.destroy();
});
});

QUnit.test('controller changes are passed to descendants', function() {
var grandparent = ContainerView.create();
var parent = ContainerView.create();
var child = ContainerView.create();
var grandchild = ContainerView.create();

run(function() {
grandparent.set('controller', {});

grandparent.pushObject(parent);
parent.pushObject(child);
child.pushObject(grandchild);
});

var parentCount = 0;
var childCount = 0;
var grandchildCount = 0;

parent.addObserver('controller', parent, function() { parentCount++; });
child.addObserver('controller', child, function() { childCount++; });
grandchild.addObserver('controller', grandchild, function() { grandchildCount++; });

run(function() { grandparent.set('controller', {}); });

equal(parentCount, 1);
equal(childCount, 1);
equal(grandchildCount, 1);

run(function() { grandparent.set('controller', {}); });

equal(parentCount, 2);
equal(childCount, 2);
equal(grandchildCount, 2);

run(function() {
grandparent.destroy();
parent.destroy();
child.destroy();
grandchild.destroy();
});
});