Dict

API ReferenceDict

Access it with:

const { Dict } = Neft

Source


Dict.fromJSON()

Static method of
Dict
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


constructor()

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


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


onChange()

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


set()

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


has()

Parameters
  • key — String
Returns
Boolean

Returns true if the given key exists in this Dict.

Source


extend()

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


pop()

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


clear()

Removes all stored keys from this Dict.

Calls onChange() signal for each stored key.

Source


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


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


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

results matching ""

    No results matching ""