Show:
Extends Array
Module: proact-arrays

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 optional

    I 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.

Methods

concat

(
  • [...]
)
ProAct.Array

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 optional

    Arrays and/or values to concatenate to the resulting array.

Returns:

ProAct.Array:

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
)
Boolean

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:

  • callback Function

    Function to test for each element.

  • thisArg Object

    Value to use as this when executing callback.

Returns:

Boolean:

True if all the elements in the this ProAct.Array pass the test implemented by the callback, false otherwise.

filter

(
  • fun
  • thisArg
)
ProAct.Array

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:

  • fun Function

    Function to test for each element.

  • thisArg Object

    Value to use as this when executing fun.

Returns:

ProAct.Array:

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.

Parameters:

  • fun Function

    Function to execute for each element.

  • thisArg Object

    Value to use as this when executing callback.

indexOf

(
  • searchElement
  • fromIndex
)
Number

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 Object

    Element to locate in the ProAct.Array.

  • fromIndex Number

    Default: 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 the ProAct.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:

Number:

The index of the searched element or '-1' if it is not found in this ProAct.Array.

join

(
  • separator
)
String

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 String

    Specifies 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:

String:

A string representation of all the elements in this ProAct.Array, separated by the provided separator.

lastIndexOf

(
  • searchElement
  • fromIndex
)
Number

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 Object

    Element to locate in the ProAct.Array.

  • fromIndex Number

    The 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 whole ProAct.Array will be searched. If negative, it is taken as the offset from the end of the ProAct.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:

Number:

The index of the searched backwards element or '-1' if it is not found in this ProAct.Array.

map

(
  • fun
  • thisArg
)
ProAct.Array

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 Function

    Function that produces an element of the new ProAct.Array, taking three arguments:

    1. currentValue : The current element being processed in the array.
    2. index : The index of the current element being processed in the array.
    3. array : The array map was called upon.

  • thisArg Object

    Value to use as this when executing fun.

Returns:

ProAct.Array:

A new ProAct.Array consisting of the elements in this ProAct.Array transformed by fun.

pevery

(
  • fun
  • thisArg
)
ProAct.Property

Does the same as the every method, but the result is a ProAct.Property depending on changes on the array.

Parameters:

  • fun Function

    Function to test for each element.

  • thisArg Object

    Value to use as this when executing callback.

Returns:

ProAct.Property:

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
)
ProAct.Property

Does the same as the indexOf method, but the result is a ProAct.Property depending on changes on this ProAct.Array.

Parameters:

  • searchElement Object

    Element to locate in the ProAct.Array.

  • fromIndex Number

    Default: 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 the ProAct.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:

ProAct.Property:

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
)
ProAct.Property

Does the same as the join method, but the result is a ProAct.Property depending on changes on this ProAct.Array.

Parameters:

  • separator String

    Specifies 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:

ProAct.Property:

A ProAct.Property instance with value : string representation of all the elements in this ProAct.Array, separated by the provided separator.

plastindexOf

(
  • searchElement
  • fromIndex
)
ProAct.Property

Does the same as the lastIndexOf method, but the result is a ProAct.Property depending on changes on this ProAct.Array.

Parameters:

  • searchElement Object

    Element to locate in the ProAct.Array.

  • fromIndex Number

    The 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 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:

ProAct.Property:

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:

Object:

The removed element. If this ProAct.Array is empty the result is undefined.

preduce

(
  • fun
  • initialValue
)
ProAct.Property

Does the same as the reduce method, but the result is a ProAct.Property depending on changes on this ProAct.Array.

Parameters:

  • fun Function

    Function to execute on each value in the array, taking four arguments:

    1. previousValue : The value previously returned in the last invocation of the fun, or initialValue, if supplied.
    2. currentValue : The current element being processed in the ProAct.Array.
    3. index : The index of the current element being processed in the ProAct.Array.
    4. array : The array reduce was called upon.

  • initialValue Object

    Object to use as the first argument to the first call of the fun .

Returns:

ProAct.Property:

ProAct.Property with value of the last fun invocation.

preduceRight

(
  • fun
  • initialValue
)
ProAct.Property

Does the same as the reduceRight method, but the result is a ProAct.Property depending on changes on this ProAct.Array.

Parameters:

  • fun Function

    Function to execute on each value in the array, taking four arguments:

    1. previousValue : The value previously returned in the last invocation of the fun, or initialValue, if supplied.
    2. currentValue : The current element being processed in the ProAct.Array.
    3. index : The index of the current element being processed in the ProAct.Array.
    4. array : The array reduce was called upon.

  • initialValue Object

    Object to use as the first argument to the first call of the fun .

Returns:

ProAct.Property:

ProAct.Property with value of the last fun invocation.

psome

(
  • fun
  • thisArg
)
ProAct.Property

Does the same as the some method, but the result is a ProAct.Property depending on changes on the array.

Parameters:

  • fun Function

    Function to test for each element.

  • thisArg Object

    Value to use as this when executing callback.

Returns:

ProAct.Property:

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

(
  • [...]
)
Object

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 optional

    element1, ..., elementN : The elements to add to the end of the array.

Returns:

Object:

The new length property of the this.

reduce

(
  • fun
  • initialValue
)
Object

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 Function

    Function to execute on each value in the array, taking four arguments:

    1. previousValue : The value previously returned in the last invocation of the fun, or initialValue, if supplied.
    2. currentValue : The current element being processed in the ProAct.Array.
    3. index : The index of the current element being processed in the ProAct.Array.
    4. array : The array reduce was called upon.

  • initialValue Object

    Object to use as the first argument to the first call of the fun .

Returns:

Object:

The value of the last fun invocation.

reduceRight

(
  • fun
  • initialValue
)
Object

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 Function

    Function to execute on each value in the array, taking four arguments:

    1. previousValue : The value previously returned in the last invocation of the fun, or initialValue, if supplied.
    2. currentValue : The current element being processed in the ProAct.Array.
    3. index : The index of the current element being processed in the ProAct.Array.
    4. array : The array reduce was called upon.

  • initialValue Object

    Object to use as the first argument to the first call of the fun .

Returns:

Object:

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:

Object:

The removed element. If this ProAct.Array is empty the result is undefined.

slice

(
  • begin
  • end
)
ProAct.Array

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 Number

    Zero-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 Number

    Zero-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:

ProAct.Array:

A portion of this ProAct.Array, dependent on it.

some

(
  • callback
  • thisArg
)
Boolean

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:

  • callback Function

    Function to test for each element.

  • thisArg Object

    Value to use as this when executing callback.

Returns:

Boolean:

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:

ProAct.Array:

this

splice

(
  • index
  • howMany
  • [...]
)
ProAct.Array

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 Number

    Index at which to start changing the ProAct.Array. If greater than the length of the ProAct.Array, actual starting index will be set to the length of the this. If negative, will begin that many elements from the end.

  • howMany Number

    An 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 optional

    element1, ..., elementN:

    The elements to add to the ProAct.Array. If you don't specify any elements, splice simply removes elements from the ProAct.Array.

Returns:

ProAct.Array:

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:

Array:

An plain JavaScript array representation of this.

toJSON

() String

Generates a JSON representation of this.

Returns:

String:

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:

String:

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:

String:

A string representing the elements of this ProAct.Array.

unshift

(
  • [...]
)
Object

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 optional

    element1, ..., elementN : The elements to add to the front of the array.

Returns:

Object:

The new length property of the this.

valueOf

() Array

Returns the result of toArray.

Returns:

Array:

This ProAct.Array converted to plain JavaScript array.

Properties

constructor

ProAct.Array final

Reference to the constructor of this object.