Created
April 29, 2015 10:16
-
-
Save cassiozen/6ed695e2bcc03e769918 to your computer and use it in GitHub Desktop.
This file contains 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 events = new EventEmitter(); | |
var CHANGE_EVENT = 'CHANGE'; | |
var todos = {}; | |
var TodoStore = { | |
addChangeListener: function(callback) { | |
events.addListener(CHANGE_EVENT, callback); | |
}, | |
removeChangeListener: function(callback) { | |
events.removeListener(CHANGE_EVENT, callback); | |
} | |
/* | |
* In this case, do not provide emitChange as | |
* a publicly available method in your store | |
emitChange: function() { | |
this.emit(StoreConstants.CHANGE); | |
}, | |
*/ | |
}; | |
TodoStore.dispatchToken = AppDispatcher.register((action) => { | |
if (action.type === ActionTypes.TODOS_LOADED) { | |
todos = action.todos | |
events.emit(CHANGE_EVENT); | |
} | |
}); | |
module.exports = TodoStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment