Class Ember.ObjectController

Ember.ObjectController is part of Ember's Controller layer. It is intended to wrap a single object, proxying unhandled attempts to get and set to the underlying content object, and to forward unhandled action attempts to its target.

Ember.ObjectController derives this functionality from its superclass Ember.ObjectProxy and the Ember.ControllerMixin mixin.

Show:

Module: ember

Defines the properties that will be concatenated from the superclass (instead of overridden).

By default, when you extend an Ember class a property defined in the subclass overrides a property with the same name that is defined in the superclass. However, there are some cases where it is preferable to build up a property's value by combining the superclass' property value with the subclass' value. An example of this in use within Ember is the classNames property of Ember.View.

Here is some sample code showing the difference between a concatenated property and a normal one:

1
2
3
4
5
6
7
8
9
10
11
12
13
App.BarView = Ember.View.extend({
  someNonConcatenatedProperty: ['bar'],
  classNames: ['bar']
});

App.FooBarView = App.BarView.extend({
  someNonConcatenatedProperty: ['foo'],
  classNames: ['foo'],
});

var fooBarView = App.FooBarView.create();
fooBarView.get('someNonConcatenatedProperty'); // ['foo']
fooBarView.get('classNames'); // ['ember-view', 'bar', 'foo']

This behavior extends to object creation as well. Continuing the above example:

1
2
3
4
5
6
var view = App.FooBarView.create({
  someNonConcatenatedProperty: ['baz'],
  classNames: ['baz']
})
view.get('someNonConcatenatedProperty'); // ['baz']
view.get('classNames'); // ['ember-view', 'bar', 'foo', 'baz']

Adding a single property that is not an array will just add it in the array:

1
2
3
4
var view = App.FooBarView.create({
  classNames: 'baz'
})
view.get('classNames'); // ['ember-view', 'bar', 'foo', 'baz']

Using the concatenatedProperties property, we can tell to Ember that mix the content of the properties.

In Ember.View the classNameBindings and attributeBindings properties are also concatenated, in addition to classNames.

This feature is available for you to use throughout the Ember object model, although typical app developers are likely to use it infrequently.

Module: ember

The object whose properties will be forwarded.

Module: ember

Stores the instances of other controllers available from within this controller. Any controller listed by name in the needs property will be accessible by name through this property.

1
2
3
4
5
6
7
App.CommentsController = Ember.ArrayController.extend({
  needs: ['post'],
  postTitle: function(){
    var currentPost = this.get('controllers.post'); // instance of App.PostController
    return currentPost.get('title');
  }.property('controllers.post.title')
});
Module: ember

Destroyed object property flag.

if this property is true the observers and bindings were already removed by the effect of calling the destroy() method.

Module: ember

Destruction scheduled flag. The destroy() method has been called.

The object stays intact until the end of the run loop at which point the isDestroyed flag is set.

Module: ember

An array of other controller objects available inside instances of this controller via the controllers property:

For example, when you define a controller:

1
2
3
App.CommentsController = Ember.ArrayController.extend({
  needs: ['post']
});

The application's single instance of these other controllers are accessible by name through the controllers property:

1
this.get('controllers.post'); // instance of App.PostController

This is only available for singleton controllers.

Module: ember

The object to which actions from the view should be sent.

For example, when a Handlebars template uses the {{action}} helper, it will attempt to send the action to the view's controller's target.

By default, a controller's target is set to the router after it is instantiated by Ember.Application#initialize.