Skip to content

Instantly share code, notes, and snippets.

@productioncoder productioncoder/videos.js

Last active Dec 17, 2018
What would you like to do?
Youtube videos reducer: parsing most popular videos by id responses
function reduceFetchMostPopularVideosByCategory(responses, categories, prevState) {
let videoMap = {};
let byCategoryMap = {};
responses.forEach((response, index) => {
// ignore answer if there was an error
if (response.status === 400) return;
const categoryId = categories[index];
const {byId, byCategory} = groupVideosByIdAndCategory(response.result);
videoMap = {...videoMap, ...byId};
byCategoryMap[categoryId] = byCategory;
// compute new state
return {
byId: {...prevState.byId, ...videoMap},
byCategory: {...prevState.byCategory, ...byCategoryMap},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.