Last active
July 13, 2016 16:09
-
-
Save colinf/b15f8fb9bb32d3cf474a to your computer and use it in GitHub Desktop.
Standard Flux Store definition in ES5 ( See http://bit.ly/29RY6gq )
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 AppDispatcher = require('../dispatcher/AppDispatcher'); | |
var AppConstants = require('../constants/AppConstants'); | |
var EventEmitter = require('events').EventEmitter; | |
var assign = require('object-assign'); | |
var ActionTypes = AppConstants.ActionTypes; | |
var CHANGE_EVENT = 'change'; | |
var ExampleStore = assign({}, EventEmitter.prototype, { | |
emitChange: function() { | |
this.emit(CHANGE_EVENT); | |
}, | |
addChangeListener: function(callback) { | |
this.on(CHANGE_EVENT, callback); | |
}, | |
removeChangeListener: function(callback) { | |
this.removeListener(CHANGE_EVENT, callback); | |
}, | |
// define other Store methods to query data etc | |
}); | |
ExampleStore.dispatchToken = AppDispatcher.register(function(action) { | |
switch(action.type) { | |
case ActionTypes.CLICKED_IT: | |
// update the store based on this action; | |
this.emitChange(); | |
break; | |
// case statements for other actions relevant to this store | |
default: | |
// do nothing | |
} | |
}); | |
module.exports = ExampleStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment