|
1 |
| -import { StoreEnhancer, Action, AnyAction, Reducer, createStore, StoreEnhancerStoreCreator, Store } from '../..' |
| 1 | +import { StoreEnhancer, Action, AnyAction, Reducer, createStore } from '../..' |
2 | 2 |
|
3 | 3 | interface State {
|
4 | 4 | someField: 'string'
|
@@ -327,3 +327,51 @@ function finalHelmersonExample() {
|
327 | 327 | // typings:expect-error
|
328 | 328 | newStore.getState().wrongField
|
329 | 329 | }
|
| 330 | + |
| 331 | +function composedEnhancers() { |
| 332 | + interface State { |
| 333 | + someState: string; |
| 334 | + } |
| 335 | + const reducer: Reducer<State> = null as any |
| 336 | + |
| 337 | + interface Ext1 { |
| 338 | + enhancer1: string; |
| 339 | + } |
| 340 | + interface Ext2 { |
| 341 | + enhancer2: number; |
| 342 | + } |
| 343 | + |
| 344 | + const enhancer1: StoreEnhancer<Ext1> = (createStore) => (reducer, preloadedState) => { |
| 345 | + function replaceReducer<NewState, NewActions extends Action>(nextReducer: Reducer<NewState, NewActions>) { |
| 346 | + store.replaceReducer(nextReducer) |
| 347 | + return newStore |
| 348 | + } |
| 349 | + const store = createStore(reducer, preloadedState) |
| 350 | + const newStore = { |
| 351 | + ...store, |
| 352 | + replaceReducer, |
| 353 | + enhancer1: 'foo' |
| 354 | + } |
| 355 | + return newStore |
| 356 | + } |
| 357 | + |
| 358 | + const enhancer2: StoreEnhancer<Ext2> = (createStore) => (reducer, preloadedState) => { |
| 359 | + function replaceReducer<NewState, NewActions extends Action>(nextReducer: Reducer<NewState, NewActions>) { |
| 360 | + store.replaceReducer(nextReducer) |
| 361 | + return newStore |
| 362 | + } |
| 363 | + const store = createStore(reducer, preloadedState) |
| 364 | + const newStore = { |
| 365 | + ...store, |
| 366 | + replaceReducer, |
| 367 | + enhancer2: 5 |
| 368 | + } |
| 369 | + return newStore |
| 370 | + } |
| 371 | + |
| 372 | + const enhancedStore = createStore(reducer, (createStore) => enhancer2(enhancer1(createStore))); |
| 373 | + enhancedStore.enhancer1 |
| 374 | + enhancedStore.enhancer2 |
| 375 | + // typings:expect-error |
| 376 | + enhancedStore.enhancer3 |
| 377 | +} |
0 commit comments