Created
December 2, 2017 17:21
-
-
Save zrod/a1dabd27d3c2d52d155971beada17864 to your computer and use it in GitHub Desktop.
spread operator mess
This file contains hidden or 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
import authType from './authType'; | |
import { LIKE_POST_SUCCESS } from '../actions/actionTypes'; | |
export default function authReducer(state = authType, action) { | |
switch (action.type) { | |
// ... | |
case types.LIKE_POST_SUCCESS: | |
return { | |
...state, | |
...{ | |
user: { | |
...state.user, | |
activity: { | |
...state.user.activity, | |
post: { | |
...state.user.activity.post, | |
likes: [ | |
...state.user.activity.post.likes, | |
action.payload | |
] | |
} | |
} | |
} | |
} | |
}; | |
default: | |
return state; | |
} | |
} | |
/** | |
* Part of the auth object: | |
{ | |
user: { | |
id: 0, | |
username: '', | |
avatar: '', | |
activity: { | |
post: { | |
likes: [], | |
favorites: [] | |
} | |
} | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment