How to delegate object properies


#1

Is there a way to delegate object’s attributes directly into a controller?

I really don’t know how to explain this, so here is an example:

I have an object:

App.Person = Ember.Object.extend({
  say: function(thing) {
    alert(thing);
  }
});

and a controller:

App.MyController = Ember.Controller.extend({
  myPerson: null,

 actions: {
    createPerson: function(){
       this.set('myPerson', App.Person.create({
                    name: "Tom Dale"
       }));
     }
  }
});

Now, when I want to access a ‘name’ attribute, I have to do it like this: this.get(‘person.name’) or this.get(‘person’).name

Is there a way to proxy (delegate?) all the attributes of Person object directly into the controller, so that I could call this.get(‘name’)? I am looking for something like {{#with}} in templates…

btw. I really care just about object’s attributes, functions dos not have to be proxied

thanks a lot


#2

This sounds exactly like Ember.ObjectController, which is deprecated in 1.11 and removed in 2.0+.

Besides all the reasons listed in the official post, proxying creates a complexity problem the only grow when the application gets bigger. When you’re accessing a proxied property from your template, how do you know if the property is defined on the controller or proxied model?