0.3.4 • Published 9 years ago

collectionjs v0.3.4

Weekly downloads
6
License
MIT
Repository
github
Last release
9 years ago

collectionjs

How to use?

// create new instance
var CL = new Collection('Collection Name');

// add objects to collection
var a = {x: 1};
var b = {x: 2};

CL.add(a); // returns true
CL.add(a); // returns fase, item already exists

// remove from collection
CL.remove(a); // returns true
CL.remove(b); // returns false

// check existing
CL.exists(b); // returns false

CL.add(b); // returns true
CL.exists(b); // returns true

// get items list
var CL1 = new Collection('Collection 1 Name');
var CL2 = new Collection('Collection 2 Name');

CL1.add(a); // returns true
CL1.add(b); // returns true

CL2.add(b); // returns true

CL1.list(); // returns [{x: 1}, {x: 2}]
CL2.list(); // returns [{x: 2}]

Methods

  • indexed(key): return array of objects indexed by key
  • each(callback): for each object
  • add(object): add object to collection, return boolean
  • remove(object): remove object from collection, return deleted object
  • get(): get some object from collection
  • exists(object): check object existing in collection
  • contains(object): alias for exists method
  • list(): return array of objects
  • count(): return count of collection objects
  • on(eventName, callback): add event listner

Events

  • Event add (obj)
  • Event remove (obj)
  • Event change (obj, boolean isAdd)
CL.on('add', function (obj) {
	console.log(obj);
});
0.3.4

9 years ago

0.3.3

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.4

9 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.0.1

10 years ago