Skip to content

Instantly share code, notes, and snippets.

@cassiozen
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cassiozen/56daa8c4d1ba07ef0077 to your computer and use it in GitHub Desktop.
Save cassiozen/56daa8c4d1ba07ef0077 to your computer and use it in GitHub Desktop.
var contacts = {};
var handleAddContact = (action) => {
contacts.assign(contacts, action.contact);
ContactsStore.emitChange();
}
var handleRemoveContact = (action) => {
var updatedContacts = state.contacts.filter((contact) => {
return contact.id !== action.contact.id;
});
contacts = updatedContacts;
ContactsStore.emitChange();
}
var actions = {
[ActionTypes.ADD_CONTACT]: handleAddContact,
[ActionTypes.DELETE_CONTACT]: handleRemoveContact
}
var ContactsStore = assign({}, EventEmitter.prototype, {
emitChange() {
this.emit(StoreEvents.CHANGE);
},
getContacts() {
return contacts;
}
});
ContactsStore.dispatchToken = AppDispatcher.register((action) => {
actions[action.type] && actions[action.type].call(this,action)
});
module.exports = ContactsStore;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment