Skip to content

Commit

Permalink
subController’s parentController & target properties are now set to t…
Browse files Browse the repository at this point in the history
…he concrete parentController.
  • Loading branch information
stefanpenner committed May 16, 2014
1 parent 3a608a4 commit 5036f4d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,15 @@ export default ArrayProxy.extend(ControllerMixin, SortableMixin, {
if (!container.has(fullName)) {
throw new EmberError('Could not resolve itemController: "' + controllerClass + '"');
}
var parentController;

if (this._isVirtual) {
parentController = get(this, 'parentController');
} else {
parentController = this;
}
parentController = parentController || this;

subController = container.lookupFactory(fullName).create({
target: this,
target: parentController,
parentController: parentController,
model: object
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,35 @@ test("if `lookupItemController` returns a string, it must be resolvable by the c
"`lookupItemController` must return either null or a valid controller name");
});

test("target and parentController are set to the concrete parentController", function() {
var parent = ArrayController.create({

});

// typically controller created for {{each itemController="foo"}}
var virtual = ArrayController.create({
itemController: 'Item',
container: container,
target: parent,
parentController: parent,
_isVirtual: true,
model: Ember.A([
{ name: 'kris seldenator' }
])
});

var itemController = virtual.objectAtContent(0);

equal(itemController.get('parentController'), parent);
equal(itemController.get('target'), parent);

Ember.run(function() {
parent.destroy();
virtual.destroy();
});

});

test("array observers can invoke `objectAt` without overwriting existing item controllers", function() {
createArrayController();

Expand Down

0 comments on commit 5036f4d

Please sign in to comment.