Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ember.js still support ObjectController? If not, what replaces it?

I'm trying to learn some Ember.js and while I realize everything is in flux and the moment, it seems that this bit of code from the Sproutcore 2 guides (which are linked to at the Ember.js github readme) doesn't work any longer:

   App.userController = SC.ObjectController.create({
        content: SC.Object.create({
        firstName: "Albert",
        lastName: "Hofmann",
        posts: 25,
        hobbies: "Riding bicycles"
      })
    });

Looking at the ember.js source, the only type of controller that seems to be supported is an arryay controller. Is there an established best practice for proxying between a single model object that is not part of an array/collection and a view? Or do people forego the proxying and simply set up bindings directly between the model and view objects? Thoughts?

like image 864
Sean O'Hara Avatar asked Dec 03 '22 00:12

Sean O'Hara


2 Answers

There are plans to bring back ObjectController/ObjectProxy. Peter and I have started working on it here, but we need to add some lower level functionality to Ember before it can be fully supported.

Until then, you can use Ember.Object with a content property. You'll have to explicitly reference the content property in property paths (eg. App.userController.content). When ObjectController is finished you'll be able to switch your controllers to inherit from it instead and you can update your property paths to not explicitly reference content.

like image 177
ebryn Avatar answered Dec 24 '22 22:12

ebryn


UPDATED: Yes, Ember.ObjectController is a first-class part of Ember and is most frequently used to proxy a model's properties for easy rendering by templates. See http://emberjs.com/api/classes/Ember.ObjectController.html for documentation.

like image 43
Luke Melia Avatar answered Dec 24 '22 22:12

Luke Melia