Commit e4b7763b authored by Imran Salam's avatar Imran Salam
Browse files

add global reducer/action for site-wide state

parent 544c7ccd
import { createAction } from 'typesafe-actions';
import { WidthType } from './globalState';
export const updateGlobalWidth = createAction(
'browser/update-global-width',
(resolve) => {
return (globalWidth: WidthType) => resolve(globalWidth);
}
);
import { ActionType, getType } from 'typesafe-actions';
import * as global from './globalActions';
import { GlobalState, defaultState } from './globalState';
export default function globalReducer(
state: GlobalState = defaultState,
action: ActionType<typeof global>
) {
switch (action.type) {
case getType(global.updateGlobalWidth):
return { ...state, globalWidth: action.payload };
default:
return state;
}
}
import { RootState } from './rootReducer';
import { WidthType } from './globalState';
export const getGlobalWidth = (state: RootState): WidthType =>
state.global.globalWidth;
export enum WidthType {
SMALL = 'small',
MEDIUM = 'medium',
LARGE = 'medium'
}
export type GlobalState = Readonly<{
globalWidth: WidthType;
}>;
export const defaultState: GlobalState = {
globalWidth: WidthType.LARGE
};
import { combineReducers } from 'redux';
import { StateType } from 'typesafe-actions';
import global from './globalReducer';
import header from './header/headerReducer';
import browser from './content/app/browser/browserReducer';
const rootReducer = combineReducers({ header, browser });
const rootReducer = combineReducers({ global, header, browser });
export type RootState = StateType<typeof rootReducer>;
export default rootReducer;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment