Last active
July 13, 2016 16:09
-
-
Save colinf/d773f640e96de0e7f745 to your computer and use it in GitHub Desktop.
Flux Store class in ES6 ( 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
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