internal.api.md 5.7 KB

File: "reactive-list.js" Where: {client|server}

- #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)

-

#### <a name="ReactiveList.prototype.length"></a>*reactivelist*.length()&nbsp;&nbsp;<sub><i>Anywhere</i></sub> ####
-
*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](reactive-list.js#L73)

-

#### <a name="ReactiveList.prototype.reset"></a>*reactivelist*.reset()&nbsp;&nbsp;<sub><i>Anywhere</i></sub> ####
-
*This method __reset__ is defined in `prototype` of `ReactiveList`*
__TODO__
  • Check for memory leaks, if so we have to iterate over lookup and delete the items

    
    

    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

-