Guest User

Untitled

a guest
Jan 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. function userFollowersReducer(
  2. events: Event[],
  3. initialState = []
  4. ): string[] {
  5. return events.reduce((followers: string[], e: Event): string[] => {
  6. switch (e.type) {
  7. case 'USER_FOLLOWED':
  8. // add userId in array
  9. return [...followers, e.payload.followedUserId]
  10. case 'USER_UNFOLLOWED':
  11. // remove userId from array
  12. return followers.filter(userId => userId !== e.payload.unfollowedUserId)
  13. default:
  14. // keep array the same in case if any other event
  15. return followers
  16. }
  17. }, initialState)
  18. }
Add Comment
Please, Sign In to add comment