Last active
November 11, 2018 13:55
-
-
Save productioncoder/b44260f7a503dad1e134074960cf8f1c to your computer and use it in GitHub Desktop.
Youtube in React: channels reducer for WATCH_DETAILS_SUCCESS
This file contains 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
function reduceWatchDetails(responses, prevState) { | |
const channelResponse = responses.find(response => response.result.kind === CHANNEL_LIST_RESPONSE); | |
let channels = {}; | |
if (channelResponse && channelResponse.result.items) { | |
// we know that there will only be one item | |
// because we ask for a channel with a specific id | |
const channel = channelResponse.result.items[0]; | |
channels[channel.id] = channel; | |
} | |
return { | |
...prevState, | |
byId: { | |
...prevState.byId, | |
...channels | |
} | |
}; | |
} |
This file contains 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
export const CHANNEL_LIST_RESPONSE = 'youtube#channelListResponse'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment