Class Ember.MutableEnumerable
This mixin defines the API for modifying generic enumerables. These methods can be applied to an object regardless of whether it is ordered or unordered.
Note that an Enumerable can change even if it does not implement this mixin. For example, a MappedEnumerable cannot be directly modified but if its underlying enumerable changes, it will change also.
Adding Objects
To add an object to an enumerable, use the addObject()
method. This
method will only add the object to the enumerable if the object is not
already present and is of a type supported by the enumerable.
1 |
set.addObject(contact); |
Removing Objects
To remove an object from an enumerable, use the removeObject()
method. This
will only remove the object if it is present in the enumerable, otherwise
this method has no effect.
1 |
set.removeObject(contact); |
Implementing In Your Own Code
If you are implementing an object and want to support this API, just include this mixin in your class and implement the required methods. In your unit tests, be sure to apply the Ember.MutableEnumerableTests to your object.
[]
Inherited from Ember.Enumerable packages/ember-runtime/lib/mixins/enumerable.js:818
- returns
- this
This property will trigger anytime the enumerable's content changes. You can observe this property to be notified of changes to the enumerables content.
For plain enumerables, this property is read only. Ember.Array
overrides
this method.
firstObject Object
Inherited from Ember.Enumerable packages/ember-runtime/lib/mixins/enumerable.js:109
- returns
- Object
- the object or undefined
Helper method returns the first object from a collection. This is usually used by bindings and other parts of the framework to extract a single object if the enumerable contains only one item.
If you override this method, you should implement it so that it will
always return the same value each time it is called. If your enumerable
contains only one object, this method should always return that object.
If your enumerable is empty, this method should return undefined
.
1 2 3 4 5 |
var arr = ["a", "b", "c"]; arr.get('firstObject'); // "a" var arr = []; arr.get('firstObject'); // undefined |
hasEnumerableObservers
Inherited from Ember.Enumerable packages/ember-runtime/lib/mixins/enumerable.js:879
Becomes true whenever the array currently has observers watching changes on the array.
lastObject Object
Inherited from Ember.Enumerable packages/ember-runtime/lib/mixins/enumerable.js:140
- returns
- Object
- the last object or undefined
Helper method returns the last object from a collection. If your enumerable
contains only one object, this method should always return that object.
If your enumerable is empty, this method should return undefined
.
1 2 3 4 5 |
var arr = ["a", "b", "c"]; arr.get('lastObject'); // "c" var arr = []; arr.get('lastObject'); // undefined |