/**
 * npm modules
 */
var assign            = require('object-assign');
var EventEmitterProto = require('events').EventEmitter.prototype;

/**
 * local modules
 */
var dispatcher = require('../dispatcher');




var CHANGE_EVENT = 'CHANGE';
var storeMethods = {

	init: function(){return this;}, 

	set: function(arr){
		var currIds 	= this._data.map(function(item){ return item.cid }),
			uniqueItems = arr.filter(function(item){ return currIds.indexOf(item.cid) === -1; });

		uniqueItems.forEach(this.add.bind(this));
		return this;
	},

	add: function(item){
		this._data.push(item);
		return this;
	},

	getAll: function(){
		return this._data;
	},

	getById: function(id){
		return this._data.filter(function(item){ return item.cid === id })[0];
	},

	addChangeListener: function(callback){
		this.on(CHANGE_EVENT, callback);
		return this;
	},

	removeChangeListener: function(callback){
		this.removeListener(CHANGE_EVENT, callback);
		return this;
	},

	emitChange: function() {
		this.emit(CHANGE_EVENT);
		return this;
	},

	bind: function(actionType, actionCallback) {
		if(!this.actions[actionType]) this.actions[actionType] = [];
		this.actions[actionType].push(actionCallback);
		return this;
	}
};

exports.extend = function(methods){
	var store = {
		_data   : [],
		actions : {}
	};

	/**
	 * Extends the class methods
	 */
	assign(store, EventEmitterProto, storeMethods, methods);
	
	/**
	 * Class constructor
	 */
	store.init();

	/**
	 * Any action dispatched will past here.
	 * Verify if is any compatible action binded in the store, and call it.
	 */
	dispatcher.register(function(action){
		console.log("2) Dispatcher triggered -> Store listening: " + store.instanceOf);
		var bindedAction = store.actions[action.actionType];
		
		if(!bindedAction) return this;

		bindedAction.forEach(function(callback){
			console.log("3) Store binded action -> " + action.actionType + ": " + store.instanceOf + ":" + (callback.name ? callback.name : callback.toString()));
			callback.call(store, action.data);
		});
	});

	return store;
};
@@ -291,16 +291,128 @@
 is;%7D, %0A%0A
+%09/**%0A%09 * Save a list of uniques items, %0A%09 * each item must contains a cid property%0A%09 * @param %7Barray%7D list%0A%09 */%0A
 %09set: fu
@@ -418,19 +418,20 @@
 unction(
-arr
+list
 )%7B%0A%09%09var
@@ -510,19 +510,20 @@
 Items = 
-arr
+list
 .filter(
@@ -644,24 +644,83 @@
  this;%0A%09%7D,%0A%0A
+%09/**%0A%09 * Save a single item%0A%09 * @param %7Bobject%7D item %0A%09 */%0A
 %09add: functi
@@ -779,250 +779,617 @@
 ,%0A%0A%09
-getAll: function()%7B%0A%09%09return this._data;%0A%09%7D,%0A%0A%09getById: function(id)%7B%0A%09%09return this._data.filter(function(item)%7B return item.cid === id %7D)%5B0%5D;%0A%09%7D,%0A%0A%09addChangeListener: function(callback)%7B%0A%09%09this.on(CHANGE_EVENT, callback);%0A%09%09return this;%0A%09%7D,%0A
+/**%0A%09 * Returns all saved items%0A%09 * @return %7Barray%7D %0A%09 */%0A%09getAll: function()%7B%0A%09%09return this._data;%0A%09%7D,%0A%0A%09/**%0A%09 * Returns a item that matchs id%0A%09 * @param  %7Bnumber%7D id%0A%09 * @return %7Bobject%7D    %0A%09 */%0A%09getById: function(id)%7B%0A%09%09return this._data.filter(function(item)%7B return item.cid === id %7D)%5B0%5D;%0A%09%7D,%0A%0A%09/**%0A%09 * Registers a function interested in state changes%0A%09 * @param %7Bfunction%7D callback %0A%09 */%0A%09addChangeListener: function(callback)%7B%0A%09%09this.on(CHANGE_EVENT, callback);%0A%09%09return this;%0A%09%7D,%0A%09/**%0A%09 * Unregisters a function that is not any longer interested in state changes%0A%09 * @param  %7Bfunction%7D callback %0A%09 */
 %0A%09re
@@ -1495,16 +1495,77 @@
 s;%0A%09%7D,%0A%0A
+%09/**%0A%09 * Informs all the interested in the state change%0A%09 */%0A
 %09emitCha
@@ -1629,16 +1629,137 @@
 s;%0A%09%7D,%0A%0A
+%09/**%0A%09 * Binds actions to state changes%0A%09 * @param  %7Bstring%7D actionType     %0A%09 * @param  %7Bfunction%7D actionCallback %0A%09 */%0A
 %09bind: f

add some doc.