in src/amo/reducers/categories.js [91:137]
export default function reducer(
// eslint-disable-next-line default-param-last
state: CategoriesState = initialState,
action: Action,
): CategoriesState {
switch (action.type) {
case FETCH_CATEGORIES:
return { ...initialState, loading: true };
case LOAD_CATEGORIES: {
const { payload } = action;
const categoryList = createEmptyCategoryList();
payload.results.forEach((category) => {
// This category has no data, so skip it.
if (!category) {
// eslint-disable-next-line amo/only-log-strings
log.warn('category was falsey: %o', category);
return;
}
if (!categoryList[category.type]) {
log.warn(oneLine`add-on category for unknown add-on type
"${category.type}" received from API.`);
return;
}
categoryList[category.type].push(category);
});
const categories: CategoryMapType = {};
Object.keys(categoryList).forEach((addonType) => {
// $FlowIgnore: flow can't be sure that the reduce result match ExternalCategory definition, let's trust the test coverage here.
categories[addonType] = categoryList[addonType]
.sort((a, b) => a.name.localeCompare(b.name))
.reduce((object, value) => ({ ...object, [value.slug]: value }), {});
});
return {
categories,
loading: false,
};
}
default:
return state;
}
}