@@ -13,20 +13,15 @@ import {
1313import { asyncMiddleware } from './asyncMiddleware'
1414import './browserPolyfill'
1515
16- const devTools :StoreEnhancer = f =>
17- ( window as any ) . __REDUX_DEVTOOLS_EXTENSION__
18- ?( window as any ) . __REDUX_DEVTOOLS_EXTENSION__
19- :f
20-
21- export class StoreBuilder < StoreType > {
16+ export class StoreBuilder < StoreType extends { [ key :string ] :any } > {
2217private middlewares :Middleware [ ]
23- private reducers :ReducersMapObject
18+ private reducers :ReducersMapObject < StoreType >
2419private initialState :DeepPartial < StoreType >
2520private enhancer :StoreEnhancer
2621
2722constructor ( ) {
28- this . middlewares = [ ]
29- this . reducers = { }
23+ this . middlewares = [ asyncMiddleware ]
24+ this . reducers = { } as StoreType
3025this . initialState = { }
3126this . enhancer = f => f
3227}
@@ -41,7 +36,7 @@ export class StoreBuilder<StoreType> {
4136return this
4237}
4338
44- public withReducer < K = keyof StoreType > ( name :K , reducer :Reducer ) {
39+ public withReducer ( name :string , reducer :Reducer ) {
4540this . reducers [ name ] = reducer
4641return this
4742}
@@ -54,17 +49,23 @@ export class StoreBuilder<StoreType> {
5449}
5550
5651public withEnhancer ( enhancer :StoreEnhancer ) {
57- this . enhancer = f => enhancer ( this . enhancer ( f ) )
52+ const preEnhancer = this . enhancer
53+ this . enhancer = f => enhancer ( preEnhancer ( f ) )
5854return this
5955}
6056
6157public withDevTools ( ) {
62- this . withEnhancer ( devTools )
58+ this . withEnhancer (
59+ f =>
60+ ( window as any ) . __REDUX_DEVTOOLS_EXTENSION__
61+ ?( window as any ) . __REDUX_DEVTOOLS_EXTENSION__
62+ :f ,
63+ )
6364return this
6465}
6566
6667public build ( ) :Store < StoreType > {
67- const middlewares = applyMiddleware ( ...this . middlewares , asyncMiddleware )
68+ const middlewares = applyMiddleware ( ...this . middlewares )
6869const reducers = combineReducers < StoreType > ( this . reducers )
6970const composer = compose ( middlewares , this . enhancer ) ( createStore )
7071const store = composer ( reducers , this . initialState )