ProAct.Array Class
Creates a wrapper around a plain JavaScript array that is capable of tracking changes on the array and notifying listeners.
It has a ProAct.ArrayCore which it uses to observe the array for changes or to update the array on changes.
ProAct.Array
is array-like object, it has all the methods defined in the JavaScript Array class, length property and indices.
ProAct.Array
is part of the proact-arrays
module of ProAct.js.
Constructor
ProAct.Array
-
[...]
Parameters:
-
[...]
Object optionalI can take an array as a parameter and it becomes reactive wrapper around it. It can take a list of arguments which become the wrapped array. If nothing is passed it becomes wrapper arround an empty array.
Item Index
Methods
Properties
Methods
concat
-
[...]
The concat() method returns a new array comprised of this array joined with other array(s) and/or value(s).
The result ProAct.Array
is dependent on this, so if this changes, the concatenation resut will be updated.
If the argument passed is another ProAct.Array
the result array is dependent on it too.
Parameters:
-
[...]
Object optionalArrays and/or values to concatenate to the resulting array.
Returns:
A new ProAct.Array
consisting of the elements in the this object on which it is called, followed in order by,
for each argument, the elements of that argument (if the argument is an array) or the argument itself (if the argument is not an array).
every
-
callback
-
thisArg
The every() method tests whether all elements in the ProAct.Array
pass the test implemented by the provided function.
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
Parameters:
Returns:
True if all the elements in the this ProAct.Array pass the test implemented by the callback, false otherwise.
filter
-
fun
-
thisArg
The filter() method creates a new ProAct.Array
with all elements that pass the test implemented by the provided function.
The result ProAct.Array
is dependent on this, so if this changes, the filtered resut will be updated.
Parameters:
Returns:
A new ProAct.Array
consisting of the elements in this ProAct.Array
that pass the test implemented by fun.
forEach
-
fun
-
thisArg
The forEach() method executes a provided function once per array element.
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
indexOf
-
searchElement
-
fromIndex
The indexOf() method returns the first index at which a given element can be found in the ProAct.Array, or -1 if it is not present.
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
Parameters:
-
searchElement
ObjectElement to locate in the ProAct.Array.
-
fromIndex
NumberDefault: 0 (Entire array is searched)
The index to start the search at. If the index is greater than or equal to the
ProAct.Array
's length, -1 is returned, which means the array will not be searched. If the provided index value is a negative number, it is taken as the offset from the end of theProAct.Array
.Note: if the provided index is negative, the
ProAct.Array
is still searched from front to back. If the calculated index is less than 0, then the wholeProAct.Array
will be searched.
Returns:
The index of the searched element or '-1' if it is not found in this ProAct.Array
.
join
-
separator
The join() method joins all elements of an ProAct.Array
into a string.
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
Parameters:
-
separator
StringSpecifies a string to separate each element of the
ProAct
. The separator is converted to a string if necessary.If omitted, the ProAct.Array elements are separated with a comma.
Returns:
A string representation of all the elements in this ProAct.Array
, separated by the provided separator.
lastIndexOf
-
searchElement
-
fromIndex
The lastIndexOf() method returns the last index at which a given element can be found in the ProAct.Array
, or -1 if it is not present.
The ProAct.Array is searched backwards, starting at fromIndex.
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
Parameters:
-
searchElement
ObjectElement to locate in the ProAct.Array.
-
fromIndex
NumberThe index at which to start searching backwards. Defaults to the ProAct.Array's length, i.e. the whole array will be searched. If the index is greater than or equal to the length of the
ProAct.Array
, the wholeProAct.Array
will be searched. If negative, it is taken as the offset from the end of theProAct.Array
.Note that even when the index is negative, the ProAct.Array is still searched from back to front. If the calculated index is less than 0, -1 is returned, i.e. the
ProAct.Array
will not be searched.
Returns:
The index of the searched backwards element or '-1' if it is not found in this ProAct.Array
.
map
-
fun
-
thisArg
The map() method creates a new ProAct.Array
with the results of calling a provided function on every element in this ProAct.Array
.
The result ProAct.Array
is dependent on this, so if this changes, the mapped resut will be updated.
Parameters:
-
fun
FunctionFunction that produces an element of the new
ProAct.Array
, taking three arguments:- currentValue : The current element being processed in the array.
- index : The index of the current element being processed in the array.
- array : The array map was called upon.
-
thisArg
ObjectValue to use as this when executing fun.
Returns:
A new ProAct.Array
consisting of the elements in this ProAct.Array
transformed by fun.
pevery
-
fun
-
thisArg
Does the same as the every method, but the result is a ProAct.Property depending on changes on the array.
Parameters:
Returns:
ProAct.Property with value of true if all the elements in this ProAct.Array
pass the test implemented by the fun, false otherwise.
pindexOf
-
searchElement
-
fromIndex
Does the same as the indexOf method, but the result is a ProAct.Property depending on changes on this ProAct.Array
.
Parameters:
-
searchElement
ObjectElement to locate in the
ProAct.Array
. -
fromIndex
NumberDefault: 0 (Entire array is searched)
The index to start the search at. If the index is greater than or equal to the
ProAct.Array
's length, -1 is returned, which means the array will not be searched. If the provided index value is a negative number, it is taken as the offset from the end of theProAct.Array
.Note: if the provided index is negative, the
ProAct.Array
is still searched from front to back. If the calculated index is less than 0, then the whole ProAct.Array will be searched.
Returns:
A ProAct.Property instance with value, the index of the searched element or '-1' if it is not found in this ProAct.Array
.
pjoin
-
separator
Does the same as the join method, but the result is a ProAct.Property depending on changes on this ProAct.Array
.
Parameters:
-
separator
StringSpecifies a string to separate each element of the
ProAct
. The separator is converted to a string if necessary.If omitted, the ProAct.Array elements are separated with a comma.
Returns:
A ProAct.Property instance with value : string representation of all the elements in this ProAct.Array
, separated by the provided separator.
plastindexOf
-
searchElement
-
fromIndex
Does the same as the lastIndexOf method, but the result is a ProAct.Property depending on changes on this ProAct.Array
.
Parameters:
-
searchElement
ObjectElement to locate in the
ProAct.Array
. -
fromIndex
NumberThe index at which to start searching backwards. Defaults to the
ProAct.Array
's length, i.e. the whole array will be searched. If the index is greater than or equal to the length of theProAct.Array
, the whole ProAct.Array will be searched. If negative, it is taken as the offset from the end of theProAct.Array
.Note that even when the index is negative, the ProAct.Array is still searched from back to front. If the calculated index is less than 0, -1 is returned, i.e. the
ProAct.Array
will not be searched.
Returns:
A ProAct.Property instance with value, the index of the backwards searched element or '-1' if it is not found in this ProAct.Array
.
pop
()
Object
The pop() method removes the last element from an ProAct.Array
and returns that element.
This method notifies the 'length' listeners, attached to this' ProAct.ArrayCore.
This method removes the special index accessor of the deleted element's index - the last index.
Returns:
The removed element. If this ProAct.Array
is empty the result is undefined.
preduce
-
fun
-
initialValue
Does the same as the reduce method, but the result is a ProAct.Property depending on changes on this ProAct.Array
.
Parameters:
-
fun
FunctionFunction to execute on each value in the array, taking four arguments:
- previousValue : The value previously returned in the last invocation of the fun, or initialValue, if supplied.
- currentValue : The current element being processed in the
ProAct.Array
. - index : The index of the current element being processed in the
ProAct.Array
. - array : The array reduce was called upon.
-
initialValue
ObjectObject to use as the first argument to the first call of the fun .
Returns:
ProAct.Property with value of the last fun invocation.
preduceRight
-
fun
-
initialValue
Does the same as the reduceRight method, but the result is a ProAct.Property depending on changes on this ProAct.Array
.
Parameters:
-
fun
FunctionFunction to execute on each value in the array, taking four arguments:
- previousValue : The value previously returned in the last invocation of the fun, or initialValue, if supplied.
- currentValue : The current element being processed in the
ProAct.Array
. - index : The index of the current element being processed in the
ProAct.Array
. - array : The array reduce was called upon.
-
initialValue
ObjectObject to use as the first argument to the first call of the fun .
Returns:
ProAct.Property with value of the last fun invocation.
psome
-
fun
-
thisArg
Does the same as the some method, but the result is a ProAct.Property depending on changes on the array.
Parameters:
Returns:
ProAct.Property with value of true if one or more of the elements in this ProAct.Array
pass the test implemented by the fun, false otherwise.
push
-
[...]
The push() method adds one or more elements to the end of an ProAct.Array
and returns the new length of the ProAct.Array
.
This method notifies the 'length' listeners, attached to this' ProAct.ArrayCore.
This method defines new index accessors for the elements on the new indexes. So these indexes can be set and read, and will attatch listeners to the ProAct.ArrayCore or update them.
Parameters:
-
[...]
Object optionalelement1, ..., elementN : The elements to add to the end of the array.
Returns:
The new length property of the this.
reduce
-
fun
-
initialValue
The reduce() method applies a function against an accumulator and each value of the ProAct.Array
(from left-to-right) has to reduce it to a single value.
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
Parameters:
-
fun
FunctionFunction to execute on each value in the array, taking four arguments:
- previousValue : The value previously returned in the last invocation of the fun, or initialValue, if supplied.
- currentValue : The current element being processed in the
ProAct.Array
. - index : The index of the current element being processed in the
ProAct.Array
. - array : The array reduce was called upon.
-
initialValue
ObjectObject to use as the first argument to the first call of the fun .
Returns:
The value of the last fun invocation.
reduceRight
-
fun
-
initialValue
The reduceRight() method applies a function against an accumulator and each value of the ProAct.Array
(from right-to-left) as to reduce it to a single value.
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
Parameters:
-
fun
FunctionFunction to execute on each value in the array, taking four arguments:
- previousValue : The value previously returned in the last invocation of the fun, or initialValue, if supplied.
- currentValue : The current element being processed in the
ProAct.Array
. - index : The index of the current element being processed in the
ProAct.Array
. - array : The array reduce was called upon.
-
initialValue
ObjectObject to use as the first argument to the first call of the fun .
Returns:
The value of the last fun invocation.
reverse
()
The reverse() method reverses an ProAct.Array
in place. The first array element becomes the last and the last becomes the first.
This method notifies the 'index' listeners attached to this' ProAct.ArrayCore.
shift
()
Object
The shift() method removes the first element from an ProAct.Array
and returns that element. This method changes the length of the ProAct.Array
.
This method notifies the 'length' listeners, attached to this' ProAct.ArrayCore.
This method removes the special index accessor of the deleted element's index - the zero index.
Returns:
The removed element. If this ProAct.Array
is empty the result is undefined.
slice
-
begin
-
end
The slice() method returns a shallow copy of a portion of this ProAct.Array
into a new ProAct.Array
object.
The result ProAct.Array
is dependent on this, so if this changes, the slice resut will be updated.
Parameters:
-
begin
NumberZero-based index at which to begin extraction. As a negative index, begin indicates an offset from the end of the sequence. slice(-2) extracts the last two elements in the sequence. If begin is omitted, slice begins from index 0.
-
end
NumberZero-based index at which to end extraction. slice extracts up to but not including end. slice(1,4) extracts the second element up to the fourth element (elements indexed 1, 2, and 3). As a negative index, end indicates an offset from the end of the sequence. slice(2,-1) extracts the third element through the second-to-last element in the sequence. If end is omitted, slice extracts to the end of the sequence.
Returns:
A portion of this ProAct.Array
, dependent on it.
some
-
callback
-
thisArg
The some() method tests whether some element in the array passes the test implemented by the provided function.
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
Parameters:
Returns:
True if one or more of the elements in this ProAct.Array
pass the test implemented by the callback, false otherwise.
sort
()
ProAct.Array
The sort() method sorts the elements of this ProAct.Array
in place and returns the this. The sort is not necessarily stable.
The default sort order is according to string Unicode code points.
This method notifies the 'index' listeners attached to this' ProAct.ArrayCore.
Returns:
this
splice
-
index
-
howMany
-
[...]
The splice() method changes the content of this ProAct.Array
, adding new elements while removing old elements.
This method may notify the 'index' listeners or the 'length' listeners, or even the both types of listeners, attached to this' ProAct.ArrayCore, depending on what the splicing does - removing, adding or changing elements (removing and adding).
Parameters:
-
index
NumberIndex at which to start changing the
ProAct.Array
. If greater than the length of theProAct.Array
, actual starting index will be set to the length of the this. If negative, will begin that many elements from the end. -
howMany
NumberAn integer indicating the number of old
ProAct.Array
elements to remove. If howMany is 0, no elements are removed. In this case, you should specify at least one new element. If howMany is greater than the number of elements left in the ProAct.Array starting at index, then all of the elements through the end of the ProAct.Array will be deleted. -
[...]
Object optionalelement1, ..., elementN:
The elements to add to the
ProAct.Array
. If you don't specify any elements, splice simply removes elements from theProAct.Array
.
Returns:
An ProAct.Array
containing the removed elements.
If only one element is removed, an ProAct.Array
of one element is returned.
If no elements are removed, an empty ProAct.Array
is returned.
toArray
()
Array
Generates an plain array representation of this.
The returned array is shallow copy of this' content, so if modified with methods like 'push' or 'pop', this content will not be modified
Returns:
An plain JavaScript array representation of this.
toJSON
()
String
Generates a JSON representation of this.
Returns:
A JSON array representing this.
toLocaleString
()
String
The toLocaleString() method returns a string representing the elements of the ProAct.Array. The elements are converted to Strings using their toLocaleString methods and these Strings are separated by a locale-specific String (such as a comma ",").
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
Returns:
Locale-specific string representing the elements of this ProAct.Array.
toString
()
String
The toString() method returns a string representing the specified ProAct.Array
and its elements.
The elements are converted to Strings using their toLocaleString methods and these Strings are separated by a locale-specific String (such as a comma ",").
This method adds the currentCaller as a listener to both 'index' type and 'length' type of changes.
Returns:
A string representing the elements of this ProAct.Array
.
unshift
-
[...]
The unshift() method adds one or more elements to the beginning of an ProAct.Array
and returns the new length of the ProAct.Array
.
This method notifies the 'length' listeners, attached to this' ProAct.ArrayCore.
This method defines new index accessors for the elements on the new indexes. So these indexes can be set and read, and will attatch listeners to the ProAct.ArrayCore or update them.
Parameters:
-
[...]
Object optionalelement1, ..., elementN : The elements to add to the front of the array.
Returns:
The new length property of the this.