{"action":"created","issue":{"url":"https://api.github.com/repos/rackt/redux/issues/678","labels_url":"https://api.github.com/repos/rackt/redux/issues/678/labels{/name}","comments_url":"https://api.github.com/repos/rackt/redux/issues/678/comments","events_url":"https://api.github.com/repos/rackt/redux/issues/678/events","html_url":"https://github.com/rackt/redux/issues/678","id":104585117,"number":678,"title":"How to add a reducer in a store enhancer?","user":{"login":"Agamennon","id":1093997,"avatar_url":"https://avatars.githubusercontent.com/u/1093997?v=3","gravatar_id":"","url":"https://api.github.com/users/Agamennon","html_url":"https://github.com/Agamennon","followers_url":"https://api.github.com/users/Agamennon/followers","following_url":"https://api.github.com/users/Agamennon/following{/other_user}","gists_url":"https://api.github.com/users/Agamennon/gists{/gist_id}","starred_url":"https://api.github.com/users/Agamennon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Agamennon/subscriptions","organizations_url":"https://api.github.com/users/Agamennon/orgs","repos_url":"https://api.github.com/users/Agamennon/repos","events_url":"https://api.github.com/users/Agamennon/events{/privacy}","received_events_url":"https://api.github.com/users/Agamennon/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rackt/redux/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-09-02T22:31:48Z","updated_at":"2015-09-03T04:28:19Z","closed_at":null,"body":"This is my version of applyMiddleware in use in [redux-tiny-router](https://github.com/Agamennon/redux-tiny-router) \r\n\r\n```javascript\r\n\r\nfunction compose(...funcs) {\r\n    return funcs.reduceRight((composed, f) => f(composed));\r\n}\r\n\r\nfunction is_server() {\r\n    return ! (typeof window != 'undefined' && window.document);\r\n}\r\n\r\nexport function applyMiddleware(...middlewares) {\r\n    return (next) => (reducer, initialState) => {\r\n\r\n        function reducerEnhancer (state,action){\r\n            //need to find a way to stick my reducer in here and allow client to call combineReducers\r\n            Object.assign(reducer,tinyReducer,reducer);\r\n            var res = combineReducers(reducer);\r\n            return res(state,action);\r\n        }\r\n\r\n        var store = next(reducerEnhancer, initialState);\r\n\r\n        middlewares.push(tinyMiddleware);\r\n\r\n        if (__UNIVERSAL__ && !__CLIENT__){\r\n            middlewares.unshift(tinyUniversal);\r\n        }\r\n\r\n        var dispatch = store.dispatch;\r\n        var chain = [];\r\n\r\n        var middlewareAPI = {\r\n            getState: store.getState,\r\n            dispatch: (action) => dispatch(action)\r\n        };\r\n        chain = middlewares.map(middleware => middleware(middlewareAPI));\r\n        dispatch = compose(...chain, store.dispatch);\r\n\r\n        var result = {\r\n            ...store,\r\n            dispatch\r\n        };\r\n\r\n        if (__CLIENT__){\r\n            init(result);\r\n       }\r\n\r\n        return result;\r\n\r\n\r\n    };\r\n}\r\n\r\n```\r\n\r\nit works for adding my custom middleware but i need to add my custom reducer in there too, in my failure to do that, i did this above: \r\n\r\n```javascript\r\n    function reducerEnhancer (state,action){\r\n            //need to find a way to stick my reducer in here and allow client to call combineReducers\r\n            Object.assign(reducer,tinyReducer,reducer);\r\n            var res = combineReducers(reducer);\r\n            return res(state,action);\r\n\r\n        }\r\n        var store = next(reducerEnhancer, initialState);\r\n```\r\n\r\nso users can't combineReducers, they just pass in the object and my enhancer will combine for them, but i want to allow them to pass the combined reducers and just add on mine, how do i do that?\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/rackt/redux/issues/comments/137328371","html_url":"https://github.com/rackt/redux/issues/678#issuecomment-137328371","issue_url":"https://api.github.com/repos/rackt/redux/issues/678","id":137328371,"user":{"login":"timdorr","id":17882,"avatar_url":"https://avatars.githubusercontent.com/u/17882?v=3","gravatar_id":"","url":"https://api.github.com/users/timdorr","html_url":"https://github.com/timdorr","followers_url":"https://api.github.com/users/timdorr/followers","following_url":"https://api.github.com/users/timdorr/following{/other_user}","gists_url":"https://api.github.com/users/timdorr/gists{/gist_id}","starred_url":"https://api.github.com/users/timdorr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timdorr/subscriptions","organizations_url":"https://api.github.com/users/timdorr/orgs","repos_url":"https://api.github.com/users/timdorr/repos","events_url":"https://api.github.com/users/timdorr/events{/privacy}","received_events_url":"https://api.github.com/users/timdorr/received_events","type":"User","site_admin":false},"created_at":"2015-09-03T04:28:19Z","updated_at":"2015-09-03T04:28:19Z","body":"Can you not just instruct the user to include the `tinyMiddleware` whenever they are creating their store? It doesn't seem to be that unreasonable of an install request. The devtools have you do essentially the same thing, just at a higher level."}}