Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
feat: support default and * import from app reducers (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
christophehurpeau authored Feb 13, 2017
1 parent 4e6817f commit a5783db
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
5 changes: 2 additions & 3 deletions examples/counter/reducers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function counter(state = 0, action) {
export const counter = (state = 0, action) => {
switch (action.type) {
case 'INCREMENT':
return state + 1;
Expand All @@ -7,5 +7,4 @@ function counter(state = 0, action) {
default:
return state;
}
}
export default { counter };
};
8 changes: 4 additions & 4 deletions src/client/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createHistory } from 'history';
import RedBox from 'redbox-react';
/* eslint-disable import/no-extraneous-dependencies */
import routes from '__app_modules__routes__';
import reducers from '__app_modules__redux_reducers__';
import * as reducers from '__app_modules__redux_reducers__';
import middlewares from '__app_modules__redux_middlewares__';
import { parse as stateParser } from '__app_modules__redux_stateSerializer__';
/* eslint-enable import/no-extraneous-dependencies */
Expand Down Expand Up @@ -44,7 +44,7 @@ function bootstrapClient() {
});
const store = createStore(
history,
reducers,
reducers.default || reducers,
middlewares,
initialState,
);
Expand All @@ -67,9 +67,9 @@ function bootstrapClient() {
if (module.hot && process.env.NODE_ENV !== 'production') {
module.hot.accept('__app_modules__redux_reducers__', () => {
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
const newReducer = require('__app_modules__redux_reducers__').default;
const newReducers = require('__app_modules__redux_reducers__');

store.replaceReducer(createRootReducer(newReducer));
store.replaceReducer(createRootReducer(newReducers.default || newReducers));
});
module.hot.accept('__app_modules__routes__', () => {
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
Expand Down
4 changes: 2 additions & 2 deletions src/server/middlewares/store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createMemoryHistory, useBasename, useQueries } from 'history';
/* eslint-disable import/no-extraneous-dependencies */
import reducers from '__app_modules__redux_reducers__';
import * as reducers from '__app_modules__redux_reducers__';
import middlewares from '__app_modules__redux_middlewares__';
/* eslint-enable import/no-extraneous-dependencies */
import { create as createStore } from '../../shared/store';
Expand All @@ -12,6 +12,6 @@ export default () => function* storeMiddleware(next) {
entries: [this.req.url],
});
this.state.history = history;
this.state.store = createStore(history, reducers, middlewares);
this.state.store = createStore(history, reducers.default || reducers, middlewares);
yield next;
};

0 comments on commit a5783db

Please sign in to comment.