ArrayProxy
Ember.ArrayProxy Class
PUBLIC
Extends: Ember.Object
Uses: Ember.MutableArray
Defined in: packages/ember-runtime/lib/system/array_proxy.js:35
Module: ember-runtime
An ArrayProxy wraps any other object that implements Ember.Array
and/or Ember.MutableArray,
forwarding all requests. This makes it very useful for a number of binding use cases or other cases where being able to swap out the underlying array is useful.
A simple example of usage:
let pets = ['dog', 'cat', 'fish']; let ap = Ember.ArrayProxy.create({ content: Ember.A(pets) }); ap.get('firstObject'); // 'dog' ap.set('content', ['amoeba', 'paramecium']); ap.get('firstObject'); // 'amoeba'
This class can also be useful as a layer to transform the contents of an array, as they are accessed. This can be done by overriding objectAtContent
:
let pets = ['dog', 'cat', 'fish']; let ap = Ember.ArrayProxy.create({ content: Ember.A(pets), objectAtContent: function(idx) { return this.get('content').objectAt(idx).toUpperCase(); } }); ap.get('firstObject'); // . 'DOG'
_contentDidChangeprivate
Invoked when the content property changes. Notifies observers that the entire array content has changed.
_contentWillChangeprivate
Invoked when the content property is about to change. Notifies observers that the entire array content will change.
contentArrayDidChange (contentArray, start, removeCount, addCount) private
Override to implement content array didChange
observer.
Parameters:
-
contentArray
Ember-Array
- the content array
-
start
Number
- starting index of the change
-
removeCount
Number
- count of items removed
-
addCount
Number
- count of items added
contentArrayWillChange (contentArray, start, removeCount, addCount) private
Override to implement content array willChange
observer.
Parameters:
-
contentArray
Ember-Array
- the content array
-
start
Number
- starting index of the change
-
removeCount
Number
- count of items removed
-
addCount
Number
- count of items added
objectAtContent (idx) Object
public
Should actually retrieve the object at the specified index from the content. You can override this method in subclasses to transform the content item to something new.
This method will only be called if content is non-null
.
Parameters:
-
idx
Number
- The index to retrieve.
Returns:
-
Object
- the value or undefined if none found
replaceContent (idx, amt, objects) Void
private
Should actually replace the specified objects on the content array. You can override this method in subclasses to transform the content item into something new.
This method will only be called if content is non-null
.
Parameters:
-
idx
Number
- The starting index
-
amt
Number
- The number of items to remove from the content.
-
objects
Array
- Optional array of objects to insert or null if no objects.
Returns:
-
Void
arrangedContentprivate
The array that the proxy pretends to be. In the default ArrayProxy
implementation, this and content
are the same. Subclasses of ArrayProxy
can override this property to provide things like sorting and filtering.
contentEmber-Array
private
The content array. Must be an object that implements Ember.Array
and/or Ember.MutableArray.
© 2017 Yehuda Katz, Tom Dale and Ember.js contributors
Licensed under the MIT License.
https://emberjs.com/api/classes/Ember.ArrayProxy.html