diff --git a/src/middlewares/response_camelizer.js b/src/middlewares/response_camelizer.js new file mode 100644 index 0000000..631b5b1 --- /dev/null +++ b/src/middlewares/response_camelizer.js @@ -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); +}; diff --git a/src/store/configure_store.js b/src/store/configure_store.js index f2e5efd..c4c8f16 100644 --- a/src/store/configure_store.js +++ b/src/store/configure_store.js @@ -6,6 +6,7 @@ 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(); @@ -13,6 +14,7 @@ const enhancer = compose( applyMiddleware( routing, sagaMiddleware, + responseCamelizer, createLogger(), ), );