https://github.com/digitaledgeit/js-observable-collection
Ann `Array` wrapper that emits events when the `Array` is modified.
https://github.com/digitaledgeit/js-observable-collection
Last synced: 6 months ago
JSON representation
Ann `Array` wrapper that emits events when the `Array` is modified.
- Host: GitHub
- URL: https://github.com/digitaledgeit/js-observable-collection
- Owner: digitaledgeit
- Created: 2015-04-08T02:31:37.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-04-19T15:14:47.000Z (about 11 years ago)
- Last Synced: 2025-04-19T12:34:43.400Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 148 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# observable-collection
An `Array` wrapper that emits events when the underlying `Array` is modified.
## Installation
$ npm install --save digitaledgeit-observable-collection
## Usage
var collection = require('digitaledgeit-observable-collection');
function update(item, index) {
//update the view
}
collection()
.on('added', update)
.on('removed', update)
.on('emptied', update)
.append({name: 'Bill'})
.append({name: 'Mark'})
.prepend({name: 'Steve'})
.each(function(item) {
console.log(item);
})
;
## API
### new Collection()
Create a new collection.
### Properties
#### .first : *
Get the first item in the collection.
#### .last : *
Get the last item in the collection.
#### .empty : boolean
Check whether the collection is empty.
#### .length : number
Get the length of the collection.
### Methods
#### .at(index : number) : *
#### .contains(item : *) : boolean
#### .indexOf(item : *) : number
#### .prepend(item : *)
#### .append(item : *)
#### .remove(item : *)
#### .removeAt(index : number)
#### .removeAll()
#### .each(fn : function)
#### .find(fn : function) : *
#### .toArray() : Array
#### .toString() : string
### Events
#### #added
- item
- index
#### #removed
- item
- index
#### #emptied