Dict

APIDict

Access it with:

const { Dict } = Neft

Source

Dict.fromJSON(json)

Parameters:
  • json — Object or String
Returns:
Dict

Returns a new Dict based on the given json.

Example:

const dict = Dict.fromJSON('{"param": "value"}');
dict.param; // value

Source

Dict::constructor(data)

Parameters:
  • data — Objectoptional

Creates a new dict instance.

The given data parameter determines default keys with their values.

Example:

var data = new Dict({
  name: 'xyz'
});
data.name; // xyz

Source

Dict::length

Type:
Integer
Read Only

Returns an amount of keys stored in this Dict.

This property cannot be changed manually.

Example:

var dict = Dict({ prop: 1 });
dict.length; // 1

Source

Dict::onChange(key, oldValue)

Parameters:
  • key — String
  • oldValue — Any
Type:
Signal

Signal called on each key value change.

Example:

var user = new Dict({
  country: 'Germany'
});

user.onChange.connect(function(key, oldVal){
  console.log(key + " property changed from " + oldVal + " to " + this[key]);
});

user.set('country', 'US');
// country property changed from Germany to US

Source

Dict::set(key, value)

Parameters:
  • key — String
  • value — Any
Returns:
Any

Sets the given value under the given key in this Dict.

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

Calls onChange() signal.

Example:

var links = new Dict({
  facebook: 'https://facebook.com/neft.io',
  twitter: 'https://twitter.com/neft_io'
});

links.onChange.connect(function(key, oldVal){
  console.log(key + " changed from " + oldVal + " to " + this[key]);
});

links.set('googlePlus', 'https://plus.google.com/+NeftIo-for-apps/');
// googlePlus changed from undefined to https://...

Source

Dict::has(key)

Parameters:
  • key — String
Returns:
Boolean

Returns true if the given key exists in this Dict.

Source

Dict::extend(object)

Parameters:
  • object — Dict or Object
Returns:
Dict

Sets all keys with their values from the given object into this Dict.

Calls onChange() signal for each given key.

Source

Dict::pop(key)

Parameters:
  • key — String
Returns:
Any

Removes the given key from this Dict.

The given key must exists.

Calls onChange() signal.

Example:

var data = new Dict;

data.set('name', 'John');

data.onChange.connect(function(key, oldVal){
  if (this[key] === undefined){
    console.log(key + " property has been removed");
  }
});

data.pop('name');
// name property has been removed

Source

Dict::clear()

Removes all stored keys from this Dict.

Calls onChange() signal for each stored key.

Source

Dict::keys()

Returns:
Array
Read Only

Returns an array of keys stored in this Dict.

Returned array is read only and cannot be modified.

Always returns the same array instance.

Example:

var data = new Dict({
  x: 10,
  y: 30
});
data.keys(); // ['x', 'y']

Source

Dict::values()

Returns:
Array

Returns an array of values stored in this Dict.

Returned array is read only and cannot be modified.

Always returns the same array instance.

Example:

var data = new Dict({
  x: 10,
  y: 30
});
data.values(); // [10, 30]

Source

Dict::items()

Returns:
Array

Returns an array of key-value pairs stored in this Dict.

Returned array is read only and cannot be modified.

Always returns the same array instance.

Example:

var data = new Dict({
  x: 10,
  y: 30
});
data.items(); // [['x', 10], ['y', 30]]

Source