Skip to content

Instantly share code, notes, and snippets.

@jyotendra
Created January 25, 2017 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jyotendra/1e59b2ef2152c790a1a753f62db092f5 to your computer and use it in GitHub Desktop.
Save jyotendra/1e59b2ef2152c790a1a753f62db092f5 to your computer and use it in GitHub Desktop.
import {combineReducer} from "redux";
import counter from "./reducerExample";
/*
The idea is to
*/
export default const rootReducer = combineReducer({
counter
//, other reducers goes here with this object.
});
const INITIAL_STATE = {
count: 0
};
/*
Counter reducer takes two parameter:
state, action
state is initialized to an object with count object. Action parameter
receives action dispatched by some component.
Every reducer gets every action, that's being dispatched. The reducer then checks for its type and see
if it has execution method for that type, by using switch-case statements.
*/
export default function CounterReducer(state=INITIAL_STATE, action){
switch(action.type){
case "INCREMENT_COUNTER":
// Caution !! its considered to be a bad practice to mutate the state.
// You should use Object.assign method or immutable.js to make a new copy, rather.
state.count += 1;
return state;
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment