Class ArrayProxy
public
Extends:
EmberObject
Uses:
MutableArray
Defined in:
packages/@ember/array/proxy.ts:59
Module:
@ember/array/proxy
import ArrayProxy from '@ember/array/proxy';
An ArrayProxy wraps any other object that implements Array
and/or
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:
import { A } from '@ember/array';
import ArrayProxy from '@ember/array/proxy';
let pets = ['dog', 'cat', 'fish'];
let ap = ArrayProxy.create({ content: 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
:
import { A } from '@ember/array';
import ArrayProxy from '@ember/array/proxy';
let pets = ['dog', 'cat', 'fish'];
let ap = ArrayProxy.create({
content: A(pets),
objectAtContent: function(idx) {
return this.get('content').objectAt(idx).toUpperCase();
}
});
ap.get('firstObject'); // . 'DOG'
When overriding this class, it is important to place the call to
_super
after setting content
so the internal observers have
a chance to fire properly:
import { A } from '@ember/array';
import ArrayProxy from '@ember/array/proxy';
export default ArrayProxy.extend({
init() {
this.set('content', A(['dog', 'cat', 'fish']));
this._super(...arguments);
}
});
Methods
- addObject
- addObjects
- addObserver
- any
- cacheFor
- clear
- compact
- decrementProperty
- destroy
- every
- filter
- filterBy
- find
- findBy
- forEach
- get
- getEach
- getProperties
- includes
- incrementProperty
- indexOf
- init
- insertAt
- invoke
- isAny
- isEvery
- lastIndexOf
- map
- mapBy
- notifyPropertyChange
- objectAt
- objectAtContent
- objectsAt
- popObject
- pushObject
- pushObjects
- reduce
- reject
- rejectBy
- removeAt
- removeObject
- removeObjects
- removeObserver
- replace
- replaceContent
- reverseObjects
- set
- setEach
- setObjects
- setProperties
- shiftObject
- slice
- sortBy
- toArray
- toString
- toggleProperty
- uniq
- uniqBy
- unshiftObject
- unshiftObjects
- willDestroy
- without
Properties
- []
- arrangedContent
- concatenatedProperties
- content
- firstObject
- isDestroyed
- isDestroying
- lastObject
- length
- mergedProperties
Events
No documented items