Created
August 8, 2016 23:28
-
-
Save fay-jai/8f37a66e3ead48a787406c86454ae004 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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