SHARE
TWEET

Untitled

a guest Jun 25th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top