Skip to content

Commit

Permalink
Update to the proposal by @timdorr
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jan 28, 2016
1 parent f86ff2f commit f5fde8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
8 changes: 5 additions & 3 deletions examples/real-world/store/configureStore.dev.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createStore, applyMiddleware } from 'redux'
import { createStore, applyMiddleware, compose } from 'redux'
import { syncHistory } from 'react-router-redux'
import { browserHistory } from 'react-router'
import DevTools from '../containers/DevTools'
Expand All @@ -13,8 +13,10 @@ export default function configureStore(initialState) {
const store = createStore(
rootReducer,
initialState,
applyMiddleware(thunk, api, reduxRouterMiddleware, createLogger()),
DevTools.instrument()
compose(
applyMiddleware(thunk, api, reduxRouterMiddleware, createLogger()),
DevTools.instrument()
)
)

// Required for replaying actions from devtools to work
Expand Down
21 changes: 15 additions & 6 deletions src/createStore.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import isPlainObject from './utils/isPlainObject'
import compose from './compose'

/**
* These are private action types reserved by Redux.
Expand Down Expand Up @@ -28,16 +27,26 @@ export var ActionTypes = {
* If you use `combineReducers` to produce the root reducer function, this must be
* an object with the same shape as `combineReducers` keys.
*
* @param {Function} enhancer The store enhancer. You may optionally specify it
* to enhance the store with third-party capabilities such as the middleware,
* time travel, persistence, etc. The only store enhancer that ships with Redux
* is `applyMiddleware()`.
*
* @returns {Store} A Redux store that lets you read the state, dispatch actions
* and subscribe to changes.
*/
export default function createStore(reducer, initialState, ...enhancers) {
if (typeof initialState === 'function') {
enhancers.unshift(initialState)
export default function createStore(reducer, initialState, enhancer) {
if (typeof initialState === 'function' && typeof enhancer === 'undefined') {
enhancer = initialState
initialState = undefined
}
if (enhancers.length > 0) {
return compose(...enhancers)(createStore)(reducer, initialState)

if (typeof enhancer !== 'undefined') {
if (typeof enhancer !== 'function') {
throw new Error('Expected the enhancer to be a function.')
}

return enhancer(createStore)(reducer, initialState)
}

if (typeof reducer !== 'function') {
Expand Down

0 comments on commit f5fde8d

Please sign in to comment.