Reputation: 931
i'm studying ember.js by myself.
and i want to know exact role of Em.Controller.
when i make basic ember app, the only time i use Em.Controller is
App.ApplicationController = Em.Controller.extend();
but i don't know why it should be Em.Controller instead of Em.ArrayController or Em.ObjectController.
i know that ArrayController or ObjectController are used for dealing with model.
so i understand that i have to use ArrayController or ObjectController when i deal with Models.
but what about Em.Controller?
it exists only for an App's ApplicationController?
and it seems Em.ArrayController and Em.ObjectController aren't inherited from Em.Controller
then what is the relationship between them?
i'm soooo confused....
Upvotes: 4
Views: 552
Reputation: 10726
Ember.Controller
is the simplier controller class. As you can see in the Ember.Controller source code, it's just an object with a target (usually the router), and a store, and inherit Ember.ControllerMixin
.
Ember.ObjectController
is an ObjectProxy, as you can see in the ObjectController source code: when its content is set, all getters/setters are delegated to its content. So the ObjectController is used for manipulating one item.
Ember.ArrayController
acts like the ObjectController: its a proxy, but for an Array, as you can see in the ArrayController source code. So the ArrayController is used for manipulating an array of items.
Ember.ControllerMixin
just has few methods for handling view {{outlets}}
, as you again can see in the Ember.ControllerMixin source code (note that the code here reopens the ControllerMixin)
And you've right, Ember.ArrayController
and Ember.ObjectController
aren't inherited from Ember.Controller
, but they all extend the Ember.ControllerMixin
described above.
I suggest you to read Advice on & Instruction in the Use Of Ember.js by Trek, this article is not especially about controllers, but you'll learn a lot of thing, and understand how they work (outlets, for example).
Upvotes: 4