Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Created November 11, 2018 21:13
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/6515fd6ad317ffe68f2b98d2ba2805e8 to your computer and use it in GitHub Desktop.
Save productioncoder/6515fd6ad317ffe68f2b98d2ba2805e8 to your computer and use it in GitHub Desktop.
Youtube in React: parse channel information with VIDEO_DETAILS_SUCCESS action
function reduceVideoDetails(responses, prevState) {
const channelResponse = responses.find(response => response.result.kind === CHANNEL_LIST_RESPONSE);
let channelEntry = {};
if (channelResponse && channelResponse.result.items) {
// we're explicitly asking for a channel with a particular id
// so the response set must either contain 0 items (if a channel with the specified id does not exist)
// or at most one item (i.e. the channel we've been asking for)
const channel = channelResponse.result.items[0];
channelEntry = {
[channel.id]: channel,
}
}
return {
...prevState,
byId: {
...prevState.byId,
...channelEntry,
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment