Skip to content

Instantly share code, notes, and snippets.

@fay-jai
Created August 8, 2016 23:28
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 fay-jai/8f37a66e3ead48a787406c86454ae004 to your computer and use it in GitHub Desktop.
Save fay-jai/8f37a66e3ead48a787406c86454ae004 to your computer and use it in GitHub Desktop.
// PSEUDO CODE BELOW
import { combineReducers, createStore } from "redux";
// sub reducer function that manages just the points part of the overall
// application state
function pointsReducer(pointsState = 0, action) {
switch (action.type) {
case TWO_POINT_SHOT:
case FREE_THROW:
return pointsState + action.payload.points;
default:
return pointsState;
}
}
// sub reducer function that manages just the playerList part of the
// overall application state
function playerListReducer(playerListState = [], action) {
switch (action.type) {
case ADD_PLAYER:
return playerListState.concat(action.payload.player); // no mutations allowed!
default:
return playerListState;
}
}
// a new combined reducer which will pass along an action
// to each sub reducer function
const coach = combineReducer({
points: pointsReducer,
playerList: playerListReducer
});
const twoPointer = {
type: TWO_POINT_SHOT,
payload: {
points: 2
}
};
const team1Hoop = createStore(coach); // pass the reducer function as part of creating a store
team1Hoop.dispatch(twoPointer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment