List

API ReferenceList

Access it with:

const { List } = Neft;

Source


constructor()

Parameters
  • data — Arrayoptional

Creates a new list instance.

var list = new List([1, 2]);
list instanceof List; // true

Source


onChange()

Parameters
  • oldValue — Any
  • index — Integer
Type
Signal

Signal called on each value change.

Source


onInsert()

Parameters
  • value — Any
  • index — Integer
Type
Signal

Signal called when a value was added.

Source


onPop()

Parameters
  • oldValue — Any
  • index — Integer
Type
Signal

Signal called when a value was removed.

Source


length

Type
Integer
Read Only

Amount of values stored in the list.

var list = new List(['a', 'b']);
list.length; // 2

set()

Parameters
  • index — Integer
  • value — Any
Returns
Any

Sets the given value under the given index.

The index must exists in the list.

The value can't be an undefined. Use pop() instead.

Calls onChange() signal.

var types = new List(['fantasy', 'Thriller']);

types.onChange.connect(function(oldVal, i){
  console.log("element "+oldVal+" changed to "+this[i]);
});

types.set(0, 'Fantasy');
// element fantasy changed to Fantasy

types.set(0, 'Fantasy');
// nothing changed ...

Source


append()

Parameters
  • value — Any
Returns
Any

Adds the given value on the end on the list.

The value can't be an undefined.

Calls onInsert() signal.

var fridge = new List(['apple', 'milk']);

fridge.onInsert.connect(function(val, i){
  console.log(val+" appended!");
});

fridge.append('cheese');
// cheese appended!

console.log(fridge.items());
// apple, milk, cheese

Source


insert()

Parameters
  • index — Integer
  • value — Any
Returns
Any

Add the given value under the given index.

The index can't be greater than the list length.

The value can't be an undefined.

Calls onInsert() signal.

var list = new List(['a', 'b']);

list.onInsert.connect(function(val, i){
  console.log("new element "+val+" inserted at index "+i);
});

list.insert(1, 'c');
// new element c inserted at index 1

console.log(list.items());
// ['a', 'c', 'b']

Source


extend()

Parameters
  • items — Object
Returns
List

Appends all values stored in the given items into the list.

Calls onInsert() signal for each value.

Source


remove()

Parameters
  • value — Any
Returns
Any

Removes the given value from the list.

Calls onPop() signal.

var list = new List(['a', 'b']);
list[1]; // b

list.remove('b');
list[1]; // undefined

list; // ['a']

Source


pop()

Parameters
  • index — Integeroptional
Returns
Any

Removes the value stored in the list under the given index.

The index must exists in the list.

Calls onPop() signal.

var list = new List(['a', 'b']);
list[1]; // b

list.pop(1);
list[1]; // undefined

list; // ['a']

Source


clear()

Removes all values stored in the list.

Calls onPop() signal for each value.

var list = new List(['a', 'b']);

list.onPop.connect(function(oldVal, i){
  console.log("Element "+oldVal+" popped!");
});

console.log(list.items());
// ['a', 'b']

list.clear()
// Element b popped!
// Element a popped!

console.log(list);
// []

Source


index()

Parameters
  • value — Any
Returns
Integer

Returns the given value index in the list.

Returns -1 if the value doesn't exist in the list.

var list = new List(['a', 'b']);
list.index('b'); // 1
list.index('c'); // -1

Source


has()

Parameters
  • value — Any
Returns
Boolean

Returns true if the given value exists in the list.

var list = new List(['a', 'b']);
list.has('a'); // true
list.has('ab123'); // false

Source


toArray()

Returns
Array

Source

results matching ""

    No results matching ""