Skip to content

Commit

Permalink
refactor(reducers): use 'combineReducers'
Browse files Browse the repository at this point in the history
make 'searchTerm' reducer keep its own state
  • Loading branch information
aneurysmjs committed Jan 1, 2018
1 parent e5f6bba commit 3de47cb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
25 changes: 8 additions & 17 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { SET_SEARCH_TERM } from '../constants/ActionTypes';
import setSearchTerm from './setSearchTerm';
/**
* @module reducers
*/

const initialState = {
searchTerm: ''
};
import { combineReducers } from 'redux';
import searchTerm from './searchTerm';

const rootReducer = (state = initialState, action) => {
switch (action.type) {

case SET_SEARCH_TERM:
return setSearchTerm(state, action);

default:
return state;
}
};

export default rootReducer;
export default combineReducers({
searchTerm
});
24 changes: 24 additions & 0 deletions src/reducers/searchTerm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @module reducers/searchTerm
*/

import { SET_SEARCH_TERM } from '../constants/ActionTypes';

/**
*
* @param state
* @param action
* @return {*}
*/
export default function searchTerm(state = '', action) {

switch (action.type) {

case SET_SEARCH_TERM:
return action.searchTerm;

default:
return state;
}

}
5 changes: 0 additions & 5 deletions src/reducers/setSearchTerm.js

This file was deleted.

0 comments on commit 3de47cb

Please sign in to comment.