Skip to content

Instantly share code, notes, and snippets.

@captainill
Created May 14, 2015 22:14
Show Gist options
  • Save captainill/219a6ab940da49496fa5 to your computer and use it in GitHub Desktop.
Save captainill/219a6ab940da49496fa5 to your computer and use it in GitHub Desktop.
/**
*
*
*/
import BaseStore from 'fluxible/addons/BaseStore';
class ApplicationStore extends BaseStore{
static handlers = {
'CHANGE_ROUTE': 'handleNavigate',
'CHANGE_ROUTE_SUCCESS': 'handleSuccess'
}
constructor (dispatcher) {
super(dispatcher);
this.dispatcher = dispatcher; // Provides access to waitFor and getStore methods
}
initialize() {
this.currentRoute = null;
this.currentRouteName = null;
this.isLoading = false;
}
handleNavigate(route) {
if (this.currentRoute && route.path === this.currentRoute.path) {
return;
}
this.currentRoute = route;
this.currentRouteName = route.routes[route.routes.length - 1].name; //deepest route
this.isLoading = true;
this.emitChange();
}
handleSuccess(){
this.isLoading = false;
this.emitChange();
}
getState() {
return {
currentRoute: this.currentRoute,
currentRouteName: this.currentRouteName,
isLoading: this.isLoading
};
}
dehydrate() {
return this.getState();
}
rehydrate(state) {
this.currentRoute = state.route;
this.currentRouteName = state.currentRouteName;
this.isLoading = state.isLoading;
}
}
ApplicationStore.storeName = 'ApplicationStore';
module.exports = ApplicationStore;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment