application.ts 995 B

123456789101112131415161718192021222324252627
  1. import { Store, Dispatch } from 'redux';
  2. import { StoreState } from 'app/types/store';
  3. import { ActionOf } from '../redux/actionCreatorFactory';
  4. import { toggleLogActions } from '../actions/application';
  5. export const toggleLogActionsMiddleware = (store: Store<StoreState>) => (next: Dispatch) => (action: ActionOf<any>) => {
  6. const isLogActionsAction = action.type === toggleLogActions.type;
  7. if (isLogActionsAction) {
  8. return next(action);
  9. }
  10. const logActionsTrue =
  11. window && window.location && window.location.search && window.location.search.indexOf('logActions=true') !== -1;
  12. const logActionsFalse =
  13. window && window.location && window.location.search && window.location.search.indexOf('logActions=false') !== -1;
  14. const logActions = store.getState().application.logActions;
  15. if (logActionsTrue && !logActions) {
  16. store.dispatch(toggleLogActions());
  17. }
  18. if (logActionsFalse && logActions) {
  19. store.dispatch(toggleLogActions());
  20. }
  21. return next(action);
  22. };