Last active
August 29, 2015 14:20
-
-
Save cassiozen/56daa8c4d1ba07ef0077 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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