observ-varlist
An observable list that can grow negatively or positively
Install
$ npm install --save observ-varlist
Usage
var ObservList = var toArray = var list = list list // => -1list // => 3 // => {from: -1, count: 3, '-1': 'a', 0: 'b', 1: 'c'} // => ObservArray(['a', 'b', 'c']) // => ['a', 'b', 'c']
API
ObservList([initial], [constructor])
-> observList
initial
Optional
Type: object|array
Either an array, or an object containing from: Number
, count: Number
, and optional indices containing data between from
and from + count
.
constructor
Optional
Type: function
Every item put into the list will go through this constructor. Whatever the constructor returns will be stored in the list.
observList
Instance
Returned from the ObservList constructor, this is an observable with the following methods:
list.prepend(item)
- Expands the list backwards and inserts the item. Can go into negative indexes.
list.append(item)
- Expands the list forwards and inserts the item.
list.reset(data)
Resets the list. Data is either an array or an object containing from: Number
, count: Number
, and optional indices containing data between from
and from + count
.
list.forEach, list.map, list.filter, list.find
Convenience functions that are like the array methods.
License
MIT © Andrew Joslin