Skip to content

Instantly share code, notes, and snippets.

@productioncoder
Last active November 8, 2018 21:17
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/8ea5ce309504ad176f2d066b93891196 to your computer and use it in GitHub Desktop.
Save productioncoder/8ea5ce309504ad176f2d066b93891196 to your computer and use it in GitHub Desktop.
Youtube robust watch details reducer
function reduceWatchDetails(responses, prevState) {
const videoDetailResponse = responses.find(r => r.result.kind === 'youtube#videoListResponse');
// we know that items will only have one element
// because we explicitly asked for a video with a specific id
const video = videoDetailResponse.result.items[0];
return {
...prevState,
byId: {
...prevState.byId,
[video.id]: video
},
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment