What is the role of Em.Controller in Ember.js

I myself study ember.js.

and I want to know the exact role of Em.Controller.


when I make the base ember application, the only time I use Em.Controller,

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 to work with the model.

so I understand that I have to use ArrayController or ObjectController when I am working with Models.

but what about em.controller?

Does it exist only for ApplicationController?


and it seems that Em.ArrayController and Em.ObjectController are not inherited from Em.Controller

then what is the relationship between them?

I am embarrassed....

+4
source share
1 answer
  • Ember.Controller is a simpler controller class. As you can see in the source code of Ember.Controller , it is just an object with a target (usually a router), as well as a repository and inheritance of Ember.ControllerMixin .

  • Ember.ObjectController is an ObjectProxy object, as you can see in the source code of the ObjectController : when its contents are set, all recipients / setters are delegated to its contents. Thus, an ObjectController is used to control a single element.

  • Ember.ArrayController acts like an ObjectController: its proxy, but for an array, as you can see in the source code of the ArrayController . Thus, an ArrayController is used to control an array of elements.

  • Ember.ControllerMixin just a few of the methods for processing the view {{outlets}} , since you can see Ember.ControllerMixin in the source code again (note that here the code opens ControllerMixin again)

And you're right, Ember.ArrayController and Ember.ObjectController not inherited from Ember.Controller , but they all extend the Ember.ControllerMixin described above.

I suggest you read the Tips and Instructions for Using Ember.js by Trek ", this article is not particularly relevant to controllers, but you will learn a lot of things and understand how they work (outputs, for example).

+4
source

Source: https://habr.com/ru/post/1437937/


All Articles