stephband / collection

An observable array-like object constructor.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

collection

An observable array-like object constructor.

Collection(array, options)

Returns an array-like object with a number of methods for managing a collection.

var collection = Collection();
collection.add(object)
collection.update(object)
collection.remove()

.remove() Removes all objects from the collection.

.remove(id) Removes object found via collection.find(id) from the collection.

.remove(object) Removes object found via collection.find(object) from the collection.

collection.find()

.find(id) returns the object in the collection with that id, or undefined.

.find(object) returns object if it is already in the collection. Otherwise if object has an id, that is used to .find(id) an object.

collection.query(queryObject)

Filters the collection by the properties of queryObject

collection.sort()

.sort() sorts the collection by object.id by default. Override the default by defining options.sort as a function.

.sort(fn) sorts the collection by the return value of fn, like array.sort(fn).

collection.sub(queryObject)

Creates a new collection that is bound to the current one, but filtered by queryObject.

collection.get(name)

If they all have the same value, returns value of property name of the objects in the collection. Otherwise returns undefined.

collection.set(name, value)

Sets property name of all objects in the collection to value.

collection.on()
collection.off()
collection.trigger()
collection.push()
collection.pop()
collection.splice()

Also, a Collection inherits the Array methods:

  • .map()
  • .reduce()
  • .concat()
  • .slice()
  • .some()
  • .indexOf()
  • .forEach()

About

An observable array-like object constructor.


Languages

Language:JavaScript 98.8%Language:HTML 1.2%