Skip to content

Commit

Permalink
feat: add request decamelizer
Browse files Browse the repository at this point in the history
  • Loading branch information
mori-dev committed Dec 4, 2016
1 parent 012685c commit c167126
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/middlewares/request_decamelizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @flow
import { decamelizeKeys } 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(/.*_START$/)) {
action.payload = decamelizeKeys(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 @@ -7,6 +7,7 @@ import { browserHistory } from 'react-router';
import rootSaga from '../sagas/index';
import rootReducer from '../reducers';
import responseCamelizer from '../middleware/response_camelizer';
import requestDecamelizer from '../middleware/request_decamelizer';

const routing = routerMiddleware(browserHistory);
const sagaMiddleware = createSagaMiddleware();
Expand All @@ -15,6 +16,7 @@ const enhancer = compose(
routing,
sagaMiddleware,
responseCamelizer,
requestDecamelizer,
createLogger(),
),
);
Expand Down

0 comments on commit c167126

Please sign in to comment.