Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Last active November 11, 2018 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save productioncoder/b44260f7a503dad1e134074960cf8f1c to your computer and use it in GitHub Desktop.
Save productioncoder/b44260f7a503dad1e134074960cf8f1c to your computer and use it in GitHub Desktop.
Youtube in React: channels reducer for WATCH_DETAILS_SUCCESS
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
}
};
}
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