Skip to content

Instantly share code, notes, and snippets.

@jepras
Created October 17, 2018 17:50
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 jepras/dbce19bf1793b17b5e413b4379dd809b to your computer and use it in GitHub Desktop.
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.
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