Skip to content

Commit a876af2

Browse files
committed
Update to the proposal by @timdorr
1 parent 6b5c756 commit a876af2

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

examples/real-world/store/configureStore.dev.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createStore, applyMiddleware } from 'redux'
1+
import { createStore, applyMiddleware, compose } from 'redux'
22
import { syncHistory } from 'react-router-redux'
33
import { browserHistory } from 'react-router'
44
import DevTools from '../containers/DevTools'
@@ -13,8 +13,10 @@ export default function configureStore(initialState) {
1313
const store = createStore(
1414
rootReducer,
1515
initialState,
16-
applyMiddleware(thunk, api, reduxRouterMiddleware, createLogger()),
17-
DevTools.instrument()
16+
compose(
17+
applyMiddleware(thunk, api, reduxRouterMiddleware, createLogger()),
18+
DevTools.instrument()
19+
)
1820
)
1921

2022
// Required for replaying actions from devtools to work

src/createStore.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import isPlainObject from './utils/isPlainObject'
2-
import compose from './compose'
32

43
/**
54
* These are private action types reserved by Redux.
@@ -28,16 +27,26 @@ export var ActionTypes = {
2827
* If you use `combineReducers` to produce the root reducer function, this must be
2928
* an object with the same shape as `combineReducers` keys.
3029
*
30+
* @param {Function} enhancer The store enhancer. You may optionally specify it
31+
* to enhance the store with third-party capabilities such as the middleware,
32+
* time travel, persistence, etc. The only store enhancer that ships with Redux
33+
* is `applyMiddleware()`.
34+
*
3135
* @returns {Store} A Redux store that lets you read the state, dispatch actions
3236
* and subscribe to changes.
3337
*/
34-
export default function createStore(reducer, initialState, ...enhancers) {
35-
if (typeof initialState === 'function') {
36-
enhancers.unshift(initialState)
38+
export default function createStore(reducer, initialState, enhancer) {
39+
if (typeof initialState === 'function' && typeof enhancer === 'undefined') {
40+
enhancer = initialState
3741
initialState = undefined
3842
}
39-
if (enhancers.length > 0) {
40-
return compose(...enhancers)(createStore)(reducer, initialState)
43+
44+
if (typeof enhancer !== 'undefined') {
45+
if (typeof enhancer !== 'function') {
46+
throw new Error('Expected the enhancer to be a function.')
47+
}
48+
49+
return enhancer(createStore)(reducer, initialState)
4150
}
4251

4352
if (typeof reducer !== 'function') {

0 commit comments

Comments
 (0)