bindable.Collection operates like arrays, except they're watchable if anything changes.
npm install bindable-collection --save-exact
The constructor
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);
The source of the collection. This is an array.
Resets the source of the collection. You can also do this by calling set('source', array)
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);
returns the index of an item
var BindableCollection = require("bindable-collection");
var items = new BindableCollection([1, 2, 3]);
console.log(items.indexOf(1));
returns an item at the given index
iterates through the collection. similar to array.forEach.
pushes items to the end of the collection.
unshifts items to the beginning of the collection.
removes items from the collection
pops the last item off the collection
removes the first item from the collection
-
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
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();