api.md 5.5 KB

#ReactiveList Provides a simple reactive list interface

new ReactiveList([options], sort)  Anywhere

-

Arguments

  • options {object} (Optional)
  • sort {function}
    The sort algorithm to use

- Example:

  var list = new ReactiveList();
  list.insert(1, { text: 'Hello id: 1' });
  list.insert(2, { text: 'Hello id: 2' });
  list.insert(3, { text: 'Hello id: 3' });
  list.update(2, { text: 'Updated 2'});
  list.remove(1);
  
  list.forEach(function(value, key) {
    console.log('GOT: ' + value.text);
  }, true); // Set noneReactive = true, default behaviour is reactive
  // Return from Template:
  Template.hello.list = function() {
    return list.fetch();
  };

####Example of a sort algorithm Sort can be used to define the order of the list

  var list = new ReactiveList({
    sort: function(a, b) {
      // a and b are type of { key, value }
      // here we sort by the key:
      return a.key < b.key;
    }
  });

###Object chain

                   first                               last
  undefined -       obj       -       obj       -       obj       - undefined
             (prev value next) (prev value next) (prev value next)

ReactiveList = function(options) { ... reactive-list.js:46

-

reactivelist.length()  Anywhere

- This method length is defined in prototype of ReactiveList

Returns {number} (is reactive) Length of the reactive list

ReactiveList.prototype.length = function() { ... reactive-list.js:73

-

reactivelist.reset()  Anywhere

- This method reset is defined in prototype of ReactiveList

ReactiveList.prototype.reset = function() { ... reactive-list.js:83

-

reactivelist.update(key, value)  Anywhere

- This method update is defined in prototype of ReactiveList

Arguments

  • key {string|number}
    Key to update
  • value {any}
    Update with this value

-

ReactiveList.prototype.update = function(key, value) { ... reactive-list.js:102

-

reactivelist.insert(key, value)  Anywhere

- This method insert is defined in prototype of ReactiveList

Arguments

  • key {string|number}
    Key to insert
  • value {any}
    Insert item with this value

-

ReactiveList.prototype.insert = function(key, value) { ... reactive-list.js:118

-

reactivelist.remove(key)  Anywhere

- This method remove is defined in prototype of ReactiveList

Arguments

  • key {string|number}
    Key to remove

-

ReactiveList.prototype.remove = function(key) { ... reactive-list.js:180

-

reactivelist.getLastItem()  Anywhere

- This method getLastItem is defined in prototype of ReactiveList

Returns {any} Pops last item from the list - removes the item from the list

ReactiveList.prototype.getLastItem = function(first) { ... reactive-list.js:221

-

reactivelist.getFirstItem()  Anywhere

- This method getFirstItem is defined in prototype of ReactiveList

Returns {any} Pops first item from the list - removes the item from the list

ReactiveList.prototype.getFirstItem = function() { ... reactive-list.js:239

-

reactivelist.forEach(f, [noneReactive], [reverse])  Anywhere

- This method forEach is defined in prototype of ReactiveList

Arguments

  • f {function}
    Callback funciton(value, key)
  • noneReactive {boolean} (Optional = false) Set true if want to disable reactivity
  • reverse {boolean} (Optional = false) Set true to reverse iteration forEachReverse

-

ReactiveList.prototype.forEach = function(f, noneReactive, reverse) { ... reactive-list.js:249

-

reactivelist.forEachReverse(f, [noneReactive])  Anywhere

- This method forEachReverse is defined in prototype of ReactiveList

Arguments

  • f {function}
    Callback funciton(value, key)
  • noneReactive {boolean} (Optional = false) Set true if want to disable reactivity

-

ReactiveList.prototype.forEachReverse = function(f, noneReactive) { ... reactive-list.js:272

-

reactivelist.fetch([noneReactive])  Anywhere

- This method fetch is defined in prototype of ReactiveList

Arguments

  • noneReactive {boolean} (Optional = false) Set true if want to disable reactivity

-

Returns {array} (is reactive) List of items

ReactiveList.prototype.fetch = function(noneReactive) { ... reactive-list.js:282

-