Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import { ActionPayload, AllActionsPayload, Constants, IActionMap } from './actionFactory';
  2.  
  3. type ReducerCase<P> = (state: IStore, payload: P) => IStore;
  4. type IReducer = { [P in keyof Record<Constants, ReducerCase<AllActionsPayload>>]: ReducerCase<IActionMap[P]> };
  5.  
  6. export const reducer: IReducer = {
  7.  
  8. ACTION_NAMESPACE: (state, payload) => {
  9. const { id, mode } = payload;
  10. return state
  11. },
  12. };
  13.  
  14. export const communicatorReducer = (reducers: Record<Constants, ReducerCase<AllActionsPayload>>) => (
  15. state = initialState,
  16. { type, payload }: ActionPayload<Constants, AllActionsPayload>
  17. ): IStore => (reducers[type] ? reducers[type](state, payload) : state);
  18.  
  19. export default communicatorReducer(reducer);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement