Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* It's easy to avoid mutating arrays using spread operators (const newArr = [...oldArray])
- this is how to make sure you only overwrite new values to an object */
- 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
- const updatedObj = Object.assign({}, state, {status: 'online'}); //creates new object, starting blank, the updating and overwriting with following objects. The updated status overrides the one of the current state because it follows it.
- return updatedObj;
- default:
- return state;
- }
- };
- const wakeUp = () => {
- return {
- type: 'ONLINE'
- }
- };
- const store = Redux.createStore(immutableReducer);
Add Comment
Please, Sign In to add comment