Skip to content

Instantly share code, notes, and snippets.

@colinf
Last active July 13, 2016 16:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colinf/d773f640e96de0e7f745 to your computer and use it in GitHub Desktop.
Save colinf/d773f640e96de0e7f745 to your computer and use it in GitHub Desktop.
Flux Store class in ES6 ( See http://bit.ly/29RY6gq )
import FluxStore from './FluxStore';
import AppDispatcher from '../dispatcher/AppDispatcher';
import {ActionTypes} from '../constants/AppConstants';
let appState;
function reset() {
appState = {};
}
class AppStore extends FluxStore {
constructor() {
super();
}
getState() {
return appState;
}
}
let appStoreInstance = new AppStore();
appStoreInstance.dispatchToken = AppDispatcher.register(action => {
switch(action.type) {
case ActionTypes.APP_INITIALIZED:
reset();
/* falls through */
case ActionTypes.PAGE_SWITCHED:
appState.page = action.page;
appState.path = action.path;
break;
// case ActionTypes.APP_RESET:
// reset();
// break;
// case ActionTypes.POUCH_ERROR:
// appState.message = 'Local database error: ' + action.error.message;
// break;
default:
return;
}
appStoreInstance.emitChange();
});
export default appStoreInstance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment