Last active
August 23, 2018 15:50
-
-
Save matthew-gerstman/2094e725ecbda01342b8ec973f240f58 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// redux-utils/store.ts | |
import { combineReducers, createStore, Store } from "redux"; | |
import { ReducerMap, StoreShape } from "./types"; | |
let reducerMap: ReducerMap = {}; | |
const store = createStore(combineReducers(reducerMap)); | |
export function getStore() { | |
return store; | |
} | |
export function registerReducer(newReducers: ReducerMap): Store<StoreShape> { | |
reducerMap = { ...reducerMap, ...newReducers }; | |
// We probably want to validate we're not replacing reducers that already | |
// exist here but that exercise is left up to the reader. | |
store.replaceReducer(combineReducers(reducerMap)); | |
return store; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment