# bindable-collection

> [![Build Status](https://travis-ci.org/mojo-js/bindable-collection.js.svg)](https://travis-ci.org/mojo-js/bindable-collection.js)

Latest version **0.0.2** (published 2014-10-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install bindable-collection
pnpm add bindable-collection
yarn add bindable-collection
bun add bindable-collection
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2014-10-27 |
| First published | 2014-10-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | architectd |

## Links

- npm: https://www.npmjs.com/package/bindable-collection
- Repository: https://github.com/mojo-js/bindable-collection.js
- Issues: https://github.com/mojo-js/bindable-collection.js/issues
- npm.io page: https://npm.io/package/bindable-collection

## Dependencies (1)

- [bindable-object](https://npm.io/package/bindable-object.md) 0.0.x

## Recent versions

- 0.0.2 (latest) — 2014-10-27
- 0.0.1 — 2014-10-27

## README

[![Build Status](https://travis-ci.org/mojo-js/bindable-collection.js.svg)](https://travis-ci.org/mojo-js/bindable-collection.js)

bindable.Collection operates like arrays, except they're watchable if anything changes.

### Installation

```
npm install bindable-collection --save-exact
```

#### Collection(source)

The constructor

```javascript
var BindableCollection = require("bindable-collection");
var items = new BindableCollection([1, 2, 3]);
console.log(items.at(0));
console.log(items.at(1));
console.log(items.at(2));
console.log(items.source);
```

#### source

The source of the collection. This is an array.

#### reset(source)

Resets the source of the collection. You can also do this by calling `set('source', array)`

```javascript
var BindableCollection = require("bindable-collection");
var items = new BindableCollection([1, 2, 3]);
console.log(items.source);
items.reset([4, 5, 6]);
console.log(items.source);
items.set("source", [7, 8, 9]);
console.log(items.source);
```


#### indexOf(item)

returns the index of an item

```javascript
var BindableCollection = require("bindable-collection");
var items = new BindableCollection([1, 2, 3]);
console.log(items.indexOf(1));
```

#### value at(index)

returns an item at the given index

#### each(fn)

iterates through the collection. similar to array.forEach.

#### push(values...)

pushes items to the end of the collection.

#### unshift(values...)

unshifts items to the beginning of the collection.

#### splice(index, count[, newValues...])

removes items from the collection

#### value pop()

pops the last item off the collection

#### value shift()

removes the first item from the collection

#### Events

- `insert` - emitted when items are inserted
- `update` - emitted when the collection is updated
- `reset` - emitted when the source has been reset
- `remove` - emitted when items have been removed

```javascript
var BindableCollection = require("bindable-collection");
var items = new BindableCollection([1, 2, 3]);

items.on("insert", function (result) {
  console.log("insert ", result);
});

items.on("remove", function (result) {
  console.log("remove ", result);
});

items.on("update", function (result) {
  console.log("update ", result);
});

items.on("reset", function (result) {
  console.log("reset ", result);
});

items.reset([2, 3, 4]);
items.splice(1, 2);
items.push(6);
items.pop();
items.shift();
```

---
_Source: https://npm.io/package/bindable-collection · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
