Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function userFollowersReducer(
- events: Event[],
- initialState = []
- ): string[] {
- return events.reduce((followers: string[], e: Event): string[] => {
- switch (e.type) {
- case 'USER_FOLLOWED':
- // add userId in array
- return [...followers, e.payload.followedUserId]
- case 'USER_UNFOLLOWED':
- // remove userId from array
- return followers.filter(userId => userId !== e.payload.unfollowedUserId)
- default:
- // keep array the same in case if any other event
- return followers
- }
- }, initialState)
- }
Add Comment
Please, Sign In to add comment