Home Reference Source
import ARRAY from 'observabubble/props/Array.js'
public class | source

ARRAY

Extends:

PropEvents → ARRAY

The Observable ARRAY Class

Constructor Summary

Public Constructor
public

constructor(sourceSchema: Schema, options: Object)

Member Summary

Private Members
private

_name: *

private

_schema: *

private

_values: *[]

Method Summary

Public Methods
public
public

filter(method: function(item: Object): Boolean): Boolean

Returns an Array of the matching items found in the Array according to the provided method

public

find(method: function(item: Object): Boolean): Object

Finds a matching item in the Array according to the provided method

public

forEach(method: function(item: Object)): *

Loop through the Array

public

get(idx: Integer): Object

Returns the Observable Item by the Index

public

getLength(): Integer

Returns the length of the Array.

public

Determines if the provided item is in the Array

public

indexOf(item: Object): Integer

Returns the index of the provided Observable Item

public

map(method: function(item: Object): Object): Object[]

Returns a transposed Array

public

moveItem(indexes: Object, preventDefault: Boolean)

Moves an item from one index to another

public

pop(preventDefault: Boolean): Object

Removes the last item of the Array and returns that item

public

push(props: Object, preventDefault: Boolean)

Pushes an item onto the Array

public

remove(items: Object[], preventDefault: Boolean): Boolean

Removes any matching Items from the Array

public

reverse(preventDefault: Boolean): Object[]

Reverses the Array order

public

set(props: Object[], preventDefault: Boolean): Object[]

Sets the internal array of items

public

shift(preventDefault: Boolean): Object

Removes the first item of the Array and returns that item

public

slice(idxFrom: Integer, idxTo: Integer): Object[]

Returns a range of items from the Array

public

sort(sortMethod: function(a: Object, b: Object): Integer, preventDefault: Boolean): Object[]

Reorders the Array

public

splice(idx: Integer, toremove: Integer, props: Object[], preventDefault: Boolean): Object[]

Removes a range of items from the Array and returns them

public

toJSON(): Object[]

Returns the Array of Observable Items

public

Returns the Array of Objects

public

update(props: Object[], preventDefault: Boolean): Object[]

Update the items within the Array.

public

Returns an Array of the parsed values of each item

Private Methods
private
private

_assign(values: *)

private
private

_itemProp(): *

private

_newItem(props: *): *

Inherited Summary

From class PropEvents
public
public
public

parent: *

private

_event: {}

public

off(eventName: Event, callback: Function)

Unbinds an event listener

public

on(eventName: Event, callback: Function)

Bind an event listener

private

_bubble(eventName: Event, target: Prop)

Calls event bubbling on the parent Observable

private

async _processEvent(eventName: Event, target: Prop, additional: Object)

Calls the listeners for the Event triggered

Public Constructors

public constructor(sourceSchema: Schema, options: Object) source

Override:

PropEvents#constructor

Params:

NameTypeAttributeDescription
sourceSchema Schema

The Schema to be used as the shape of the items in the Array

options Object
options.values Object[]

The Array of initial values that will be consumed as Observables according to the Schema

options.parent Object

The Parent Object to which this Array is a member of

options.name String

The Name/key in the Parent Object to which this Array is assigned

Private Members

private _name: * source

private _schema: * source

private _values: *[] source

Public Methods

public [Symbol.iterator](): * source

Return:

*

public filter(method: function(item: Object): Boolean): Boolean source

Returns an Array of the matching items found in the Array according to the provided method

Params:

NameTypeAttributeDescription
method function(item: Object): Boolean

The predictate method for filtering the items

Return:

Boolean

success - True if any of the Items were found and removed

public find(method: function(item: Object): Boolean): Object source

Finds a matching item in the Array according to the provided method

Params:

NameTypeAttributeDescription
method function(item: Object): Boolean

The predictate method for matching the item

Return:

Object

item - The found Observable Item

public forEach(method: function(item: Object)): * source

Loop through the Array

Params:

NameTypeAttributeDescription
method function(item: Object)

The method to be run on each Item

Return:

*

public get(idx: Integer): Object source

Returns the Observable Item by the Index

Params:

NameTypeAttributeDescription
idx Integer
  • optional
  • default: null

The Index of the item to return (if null, all items are returned)

Return:

Object

item - The item found at the requested index

public getLength(): Integer source

Returns the length of the Array. Used by the virtual property length

Return:

Integer

length - The number of items in the Array

public includes(value: Object | String | Number | Boolean): Boolean source

Determines if the provided item is in the Array

Params:

NameTypeAttributeDescription
value Object | String | Number | Boolean

The value of an item (according to the Schema) to check for

Return:

Boolean

found - True if the item/value has been found

public indexOf(item: Object): Integer source

Returns the index of the provided Observable Item

Params:

NameTypeAttributeDescription
item Object

The Observable Item to return the index of

Return:

Integer

index - The index of the found Observable Item

public map(method: function(item: Object): Object): Object[] source

Returns a transposed Array

Params:

NameTypeAttributeDescription
method function(item: Object): Object

The transposing method applied to each item in the Array

Return:

Object[]

items - The Array of transposed Items

public moveItem(indexes: Object, preventDefault: Boolean) source

Moves an item from one index to another

Params:

NameTypeAttributeDescription
indexes Object
indexes.from Integer

The index of the item to move

indexes.to Integer

The index in the Array to move the item to

preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

public pop(preventDefault: Boolean): Object source

Removes the last item of the Array and returns that item

Params:

NameTypeAttributeDescription
preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

Return:

Object

item - The Observalbe Object of the item removed from the array

public push(props: Object, preventDefault: Boolean) source

Pushes an item onto the Array

Params:

NameTypeAttributeDescription
props Object

The Object of values that obeys the item Schema

preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

public remove(items: Object[], preventDefault: Boolean): Boolean source

Removes any matching Items from the Array

Params:

NameTypeAttributeDescription
items Object[]

An Array of Observable Objects/Items to be removed

preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

Return:

Boolean

success - True if any of the Items were found and removed

public reverse(preventDefault: Boolean): Object[] source

Reverses the Array order

Params:

NameTypeAttributeDescription
preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

Return:

Object[]

items - The new reversed Array of Items

public set(props: Object[], preventDefault: Boolean): Object[] source

Sets the internal array of items

Params:

NameTypeAttributeDescription
props Object[]
  • optional
  • default: []

The array of objects to construct the Observable Items (according to the Schema)

preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

Return:

Object[]

items - The new array of Observable Items

public shift(preventDefault: Boolean): Object source

Removes the first item of the Array and returns that item

Params:

NameTypeAttributeDescription
preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

Return:

Object

item - The Observalbe Object of the item removed from the array

public slice(idxFrom: Integer, idxTo: Integer): Object[] source

Returns a range of items from the Array

Params:

NameTypeAttributeDescription
idxFrom Integer

The index of the first item to be selected

idxTo Integer

The index of the last item to be selected

Return:

Object[]

items - The Observalbe Objects of the items selected from the array

public sort(sortMethod: function(a: Object, b: Object): Integer, preventDefault: Boolean): Object[] source

Reorders the Array

Params:

NameTypeAttributeDescription
sortMethod function(a: Object, b: Object): Integer

The sort method that determines whether items a and b swap places

preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

Return:

Object[]

items - The new array of Observable Items

public splice(idx: Integer, toremove: Integer, props: Object[], preventDefault: Boolean): Object[] source

Removes a range of items from the Array and returns them

Params:

NameTypeAttributeDescription
idx Integer

The index of the first item to be removed

toremove Integer

The number of items to be removed

props Object[]
  • optional
  • default: []

The array of objects (obeying the Schema) to inserted in the resulting gap

preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

Return:

Object[]

items - The Observalbe Objects of the items removed from the array

public toJSON(): Object[] source

Returns the Array of Observable Items

Return:

Object[]

items - Array of Observable Items

public toObject(): Object[] source

Returns the Array of Objects

Return:

Object[]

objects - Array of Objects

public update(props: Object[], preventDefault: Boolean): Object[] source

Update the items within the Array. If an item has the same prop _id, then the item reference is preserved and the props are updated

Params:

NameTypeAttributeDescription
props Object[]
  • optional
  • default: []

The array of objects to construct the Observable Items (according to the Schema)

preventDefault Boolean
  • optional
  • default: false

If true then the Change event is not fired

Return:

Object[]

items - The new array of Observable Items

public valueOf(): Object[] source

Returns an Array of the parsed values of each item

Return:

Object[]

values - Array of primitive item values

Private Methods

private _arrayState(): * source

Return:

*

private _assign(values: *) source

Params:

NameTypeAttributeDescription
values *

private _changed() source

private _itemProp(): * source

Return:

*

private _newItem(props: *): * source

Params:

NameTypeAttributeDescription
props *

Return:

*