Skip to content

Commit

Permalink
feat: add response camelizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mori-dev committed Dec 4, 2016
1 parent d7e4430 commit 012685c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/middlewares/response_camelizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @flow
import { camelizeKeys } from 'humps';
import * as ActionTypes from '../actions/action_types';

export default (store: any) => (next: any) => (action: any) => {
for (const key in ActionTypes) {
if ((ActionTypes[key] === action.type) && action.type.match(/.*(_OK|_NG)$/)) {
action.payload = camelizeKeys(action.payload);
}
}
next(action);
};
2 changes: 2 additions & 0 deletions src/store/configure_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { routerMiddleware } from 'react-router-redux';
import { browserHistory } from 'react-router';
import rootSaga from '../sagas/index';
import rootReducer from '../reducers';
import responseCamelizer from '../middleware/response_camelizer';

const routing = routerMiddleware(browserHistory);
const sagaMiddleware = createSagaMiddleware();
const enhancer = compose(
applyMiddleware(
routing,
sagaMiddleware,
responseCamelizer,
createLogger(),
),
);
Expand Down

0 comments on commit 012685c

Please sign in to comment.