I’ve got an ArrayController
whose content is a collection of Ember.Model
objects, I’m using itemController
, so each item is wrapped in an ObjectController
.
At some point I want to save an item:
...
doAThing: function() {
var item = this.firstObject();
item.set("foo", "bar");
item.save();
}
...
(Obviously I could also send the item to the router to handle, but the save happens somewhere).
This now blows up because item
at this point is an ObjectController
, not an Ember.Model
object, so doesn’t have a save
method.
I could do item.get("content").save()
, but I then have to be sure of what kind of object I’m dealing with and that it’s definitely only one level deep and not in another ObjectProxy
for whatever reason.
It would be nice if ObjectProxy
automagically forwarded undefined methods to its underlying object, but I don’t think that’s possible until we have proxy objects in ES6.
Instead, ObjectProxy
could have a send
method which forwards to its content, calling send
on an Ember.Object
would just be the same as calling the method directly.
The above then becomes item.send("save")
and we don’t have to care whether we’ve got the actual item, an ObjectController
or other ObjectProxy
.