File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 1- import { createStore , applyMiddleware } from 'redux'
1+ import { createStore , applyMiddleware , compose } from 'redux'
22import thunk from 'redux-thunk'
33import reducer from '../reducers'
44
55//applyMiddleware来自redux可以包装 store 的 dispatch
66//thunk作用是使被 dispatch 的 function 会接收 dispatch 作为参数,并且可以异步调用它
7- const createStoreWithMiddleware = applyMiddleware (
8- thunk
7+ const createStoreWithMiddleware = compose (
8+ applyMiddleware (
9+ thunk
10+ ) ,
11+ window . devToolsExtension ? window . devToolsExtension ( ) : f => f
912) ( createStore )
1013
1114export default function configureStore ( initialState ) {
Original file line number Diff line number Diff line change 1- import { createStore } from 'redux'
1+ import { createStore , compose } from 'redux'
22import rootReducer from '../reducers'
33
4+ const finalCreateStore = compose (
5+ window . devToolsExtension ? window . devToolsExtension ( ) : f => f
6+ ) ( createStore ) ;
7+
48export default function configureStore ( initialState ) {
5- const store = createStore ( rootReducer , initialState )
9+ const store = finalCreateStore ( rootReducer , initialState ) ;
610
711 if ( module . hot ) {
812 // Enable Webpack hot module replacement for reducers
You can’t perform that action at this time.
0 commit comments