Class ArrayProxy

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.

addArrayObserver
(target, opts)
EmberArraypublic

Optional hash of configuration options including
`willChange` and `didChange` option.

returns

EmberArray

receiver

Adds an array observer to the receiving array. The array observer object
normally must implement two methods:

willChange(observedObj, start, removeCount, addCount) - This method will be
called just before the array is modified.

didChange(observedObj, start, removeCount, addCount) - This method will be
called just after the array is modified.

Both callbacks will be passed the observed object, starting index of the
change as well as a count of the items to be removed and added. You can use
these callbacks to optionally inspect the array during the change, clear
caches, or do any other bookkeeping necessary.

In addition to passing a target, you can also include an options hash
which you can use to override the method names that will be invoked on the
target.

Once you call this method, any time the key's value is set, your observer
will be notified. Note that the observers are triggered any time the
value is set, regardless of whether it has actually changed. Your
observer should be prepared to handle that.

There are two common invocation patterns for .addObserver():

Passing two arguments:

the name of the property to observe (as a string)

the function to invoke (an actual function)

Passing three arguments:

the name of the property to observe (as a string)

the target object (will be used to look up and invoke a
function on)

the name of the function to invoke on the target object
(as a string).

The sender is the object that changed. The key is the property that
changes. The value property is currently reserved and unused. The rev
is the last property revision of the object when it changed, which you can
use to detect if the key value has really changed or not.

Usually you will not need the value or revision parameters at
the end. In this case, it is common to write observer methods that take
only a sender and key value as parameters or, if you aren't interested in
any of these values, to write an observer that has no parameters at all.

Returns true if the passed function returns true for any item in the
enumeration.

The callback method you provide should have the following signature (all
parameters are optional):

1

function(item, index, array);

item is the current item in the iteration.

index is the current index in the iteration.

array is the array object itself.

It must return a truthy value (i.e. true) to include an item in the
results. Any non-truthy return value will discard the item from the
results.

Note that in addition to a callback, you can also pass an optional target
object that will be set as this on the context. This is a good way
to give your iterator function access to the current object.

If you are implementing an object that supports EmberArray, call this
method just after the array content changes to notify any observers and
invalidate any related properties. Pass the starting index of the change
as well as a delta of the amounts to change.

arrayContentWillChange
(startIdx, removeAmt, addAmt)
EmberArraypublic

The number of items that will be removed. If you
pass `null` assumes 0

addAmt

Number

The number of items that will be added. If you
pass `null` assumes 0.

returns

EmberArray

receiver

If you are implementing an object that supports EmberArray, call this
method just before the array content changes to notify any observers and
invalidate any related properties. Pass the starting index of the change
as well as a delta of the amounts to change.

every
(callback, target)
Booleanpublic

Returns true if the passed function returns true for every item in the
enumeration. This corresponds with the every() method in JavaScript 1.6.

The callback method you provide should have the following signature (all
parameters are optional):

1

function(item, index, array);

item is the current item in the iteration.

index is the current index in the iteration.

array is the array itself.

It should return the true or false.

Note that in addition to a callback, you can also pass an optional target
object that will be set as this on the context. This is a good way
to give your iterator function access to the current object.

Returns an array with all of the items in the enumeration that the passed
function returns true for. This method corresponds to filter() defined in
JavaScript 1.6.

The callback method you provide should have the following signature (all
parameters are optional):

1

function(item, index, array);

item is the current item in the iteration.

index is the current index in the iteration.

array is the array itself.

It should return true to include the item in the results, false
otherwise.

Note that in addition to a callback, you can also pass an optional target
object that will be set as this on the context. This is a good way
to give your iterator function access to the current object.

Returns the first item in the array for which the callback returns true.
This method is similar to the find() method defined in ECMAScript 2015.

The callback method you provide should have the following signature (all
parameters are optional):

1

function(item, index, array);

item is the current item in the iteration.

index is the current index in the iteration.

array is the array itself.

It should return the true to include the item in the results, false
otherwise.

Note that in addition to a callback, you can also pass an optional target
object that will be set as this on the context. This is a good way
to give your iterator function access to the current object.

forEach
(callback, target)
Objectpublic

Iterates through the array, calling the passed function on each
item. This method corresponds to the forEach() method defined in
JavaScript 1.6.

The callback method you provide should have the following signature (all
parameters are optional):

1

function(item, index, array);

item is the current item in the iteration.

index is the current index in the iteration.

array is the array itself.

Note that in addition to a callback, you can also pass an optional target
object that will be set as this on the context. This is a good way
to give your iterator function access to the current object.

When you call get on a computed property, the function will be
called and the return value will be returned instead of the function
itself.

Unknown Properties

Likewise, if you try to call get on a property whose value is
undefined, the unknownProperty() method will be called on the object.
If this method returns any value other than undefined, it will be returned
instead. This allows you to implement "virtual" properties that are
not defined upfront.

Returns true if the passed object can be found in the array.
This method is a Polyfill for ES 2016 Array.includes.
If no startAt argument is given, the starting location to
search is 0. If it's negative, searches from the index of
this.length + startAt by asc.

Returns the index of the given object's first occurrence.
If no startAt argument is given, the starting location to
search is 0. If it's negative, will count backward from
the end of the array. Returns -1 if no match is found.

NOTE: If you do override init for a framework class like Ember.View,
be sure to call this._super(...arguments) in your
init declaration! If you don't, Ember may not have an opportunity to
do important setup work, and you'll see strange behavior in your
application.

Returns the index of the given object's last occurrence.
If no startAt argument is given, the search starts from
the last position. If it's negative, will count backward
from the end of the array. Returns -1 if no match is found.

Note that in addition to a callback, you can also pass an optional target
object that will be set as this on the context. This is a good way
to give your iterator function access to the current object.

Sometimes you need to change a value directly or indirectly without
actually calling get() or set() on it. In this case, you can use this
method instead. Calling this method will notify all observers that the
property has potentially changed value.

objectAt
(idx)
*public

Returns the object at the given index. If the given index is negative
or is greater or equal than the array length, returns undefined.

This is one of the primitives you must implement to support EmberArray.
If your object supports retrieving the value of an array item using get()
(i.e. myArray.get(0)), then you do not need to implement this method
yourself.

This will combine the values of the enumerator into a single value. It
is a useful way to collect a summary value from an enumeration. This
corresponds to the reduce() method defined in JavaScript 1.8.

The callback method you provide should have the following signature (all
parameters are optional):

1

function(previousValue, item, index, array);

previousValue is the value returned by the last call to the iterator.

item is the current item in the iteration.

index is the current index in the iteration.

array is the array itself.

Return the new cumulative value.

In addition to the callback you can also pass an initialValue. An error
will be raised if you do not pass an initial value and the enumerator is
empty.

Note that unlike the other methods, this method does not allow you to
pass a target object to set as this for the callback. It's part of the
spec. Sorry.

Returns an array with all of the items in the enumeration where the passed
function returns false. This method is the inverse of filter().

The callback method you provide should have the following signature (all
parameters are optional):

1

function(item, index, array);

item is the current item in the iteration.

index is the current index in the iteration

array is the array itself.

It should return a falsey value to include the item in the results.

Note that in addition to a callback, you can also pass an optional target
object that will be set as "this" on the context. This is a good way
to give your iterator function access to the current object.

This method is generally very similar to calling object["key"] = value or
object.key = value, except that it provides support for computed
properties, the setUnknownProperty() method and property observers.

Computed Properties

If you try to set a value on a key that has a computed property handler
defined (see the get() method for an example), then set() will call
that method, passing both the value and key instead of simply changing
the value itself. This is useful for those times when you need to
implement a property that is composed of one or more member
properties.

Unknown Properties

If you try to set a value on a key that is undefined in the target
object, then the setUnknownProperty() handler will be called instead. This
gives you an opportunity to implement complex "virtual" properties that
are not predefined on the object. If setUnknownProperty() returns
undefined, then set() will simply set the value on the object.

Property Observers

In addition to changing the property, set() will also register a property
change with the object. Unless you have placed this call inside of a
beginPropertyChanges() and endPropertyChanges(), any "local" observers
(i.e. observer methods declared on the same object), will be called
immediately. Any "remote" observers (i.e. observer methods declared on
another object) will be placed in a queue and called at a later time in a
coalesced manner.

setEach
(key, value)
Objectpublic

Sets the value on the named property for each member. This is more
ergonomic than using other methods defined on this helper. If the object
implements Observable, the value will be changed to set(), otherwise
it will be set directly. null objects are skipped.

without
(value)
EmberArraypublic

Returns a new array that excludes the passed value. The default
implementation returns an array regardless of the receiver type.
If the receiver does not contain the value it returns the original array.