List

APIList

Access it with:

const { List } = Neft;

Source

List::constructor(data)

Parameters:
  • data — Arrayoptional

Creates a new list instance.

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

Source

List::onChange(oldValue, index)

Parameters:
  • oldValue — Any
  • index — Integer
Type:
Signal

Signal called on each value change.

Source

List::onInsert(value, index)

Parameters:
  • value — Any
  • index — Integer
Type:
Signal

Signal called when a value was added.

Source

List::onPop(oldValue, index)

Parameters:
  • oldValue — Any
  • index — Integer
Type:
Signal

Signal called when a value was removed.

Source

List::length

Type:
Integer
Read Only

Amount of values stored in the list.

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

List::set(index, value)

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

List::append(value)

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

List::insert(index, value)

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

List::extend(items)

Parameters:
  • items — Object
Returns:
List

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

Calls onInsert() signal for each value.

Source

List::remove(value)

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

List::pop(index)

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

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

List::index(value)

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

List::has(value)

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

List::toArray()

Returns:
Array

Source