* Replaces the reducer currently used by the store to calculate the state. * * You might need this if your app implements code splitting and you want to * load some of the reducers dynamically. You might also need this if you * implement a hot reloading mechanism for Redux. * * @pa
(nextReducer: Reducer<S, A>)
| 319 | * @param nextReducer The reducer for the store to use instead. |
| 320 | */ |
| 321 | function replaceReducer(nextReducer: Reducer<S, A>): void { |
| 322 | if (typeof nextReducer !== 'function') { |
| 323 | throw new Error( |
| 324 | `Expected the nextReducer to be a function. Instead, received: '${kindOf( |
| 325 | nextReducer |
| 326 | )}` |
| 327 | ) |
| 328 | } |
| 329 | |
| 330 | currentReducer = nextReducer as unknown as Reducer<S, A, PreloadedState> |
| 331 | |
| 332 | // This action has a similar effect to ActionTypes.INIT. |
| 333 | // Any reducers that existed in both the new and old rootReducer |
| 334 | // will receive the previous state. This effectively populates |
| 335 | // the new state tree with any relevant data from the old one. |
| 336 | dispatch({ type: ActionTypes.REPLACE } as A) |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Interoperability point for observable/reactive libraries. |