Created
October 17, 2018 17:50
-
-
Save jepras/dbce19bf1793b17b5e413b4379dd809b to your computer and use it in GitHub Desktop.
Use Object.assign to take in an empty object to create shallow copy, then take in state as parameter and update one of the parameters within.
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
const defaultState = { | |
user: 'CamperBot', | |
status: 'offline', | |
friends: '732,982', | |
community: 'freeCodeCamp' | |
}; | |
const immutableReducer = (state = defaultState, action) => { | |
switch(action.type) { | |
case 'ONLINE': | |
// don't mutate state here or the tests will fail | |
return Object.assign({}, state, { | |
status: 'online' | |
}) | |
default: | |
return state; | |
} | |
}; | |
const wakeUp = () => { | |
return { | |
type: 'ONLINE' | |
} | |
}; | |
const store = Redux.createStore(immutableReducer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment