import { createStore , combineReducers } from 'redux' ; import { getState , onStoreInit , onStoreUpdate } from 'stook' ; export class devtools { static init ( ) { const INITIAL_STOOK_REDUCER = ( state = 0 ) => state ; const args = [ ] ; if ( typeof window !== 'undefined' ) { args . push ( ( window as any ) . __REDUX_DEVTOOLS_EXTENSION__ && ( window as any ) . __REDUX_DEVTOOLS_EXTENSION__ ( ) ) ; } const store = createStore ( combineReducers ( { INITIAL_STOOK_REDUCER } ) , ... args ) ; const reducers = { } as any ; param key function createReducers ( key ) { const initialState = getState ( key ) || null ; reducers [ key ] = ( state = initialState , action ) => { if ( action . type !== key ) return state ; return action . nextState ; } ; return reducers ; } onStoreInit ( key => { const reducers = createReducers ( key ) ; const newReducer = combineReducers ( reducers ) ; store . replaceReducer ( newReducer ) ; } ) ; onStoreUpdate ( ( { key , nextState } ) => { store . dispatch ( { type : key , nextState } ) ; } ) ; } }