UNPKG

trc-client-core

Version:
33 lines (30 loc) 1.1 kB
import Reflux from 'reflux'; import _ from 'lodash'; import RouterContainer from 'trc-client-core/src/global/RouterContainer'; import ImmutableStoreMixin from 'reflux-immutable/ImmutableStoreMixin'; import NavigationActions from 'trc-client-core/src/global/NavigationActions'; import UrlStore from 'bd-stampy/utils/UrlStore'; var NavigationStore = Reflux.createStore({ listenables: NavigationActions, mixins: [ImmutableStoreMixin], localStorageKey: 'Navigation', init: function () { this.setState({ query: UrlStore.getQueryParams() }); }, onSetQuery: function(query) { var routerState = this.state.toJS(); var router = RouterContainer.get(); var routeName = _.last(routerState.routes).name; var newQuery = (query) ? _.defaults(query, routerState.query) : null; this.setState({ query: newQuery }); router.replaceWith(routeName, routerState.params, newQuery); }, onRouteChange: function(state) { this.setState(state); } }) module.exports = NavigationStore;