Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {combineReducers} from 'redux';
- import {createApiReducer} from './utils';
- import {
- CATEGORIES,
- CHANNELS,
- COUNTRIES,
- filterLoadedAction,
- filterLoadingAction,
- filterLoadingErrorAction,
- GENRES,
- LANGUAGES,
- MOVIES
- } from '../constants/actionTypes'
- import {CATEGORY, COUNTRY, GENRE, LANGUAGE} from './../constants/filterTypes';
- import type {CategoryFilter, CountryFilter, GenreFilter, LanguageFilter} from "../entities";
- export type FilterState<T> = {
- data: Array<T>
- }
- export type EntityFiltersState = {
- category: FilterState<CategoryFilter>,
- genre: FilterState<GenreFilter>,
- language: FilterState<LanguageFilter>,
- country: FilterState<CountryFilter>
- }
- export type FiltersState = {
- movies: EntityFiltersState,
- channels: EntityFiltersState
- }
- function createFilterReducer(contentType, filterType) {
- return createApiReducer([
- filterLoadingAction(contentType, filterType),
- filterLoadedAction(contentType, filterType),
- filterLoadingErrorAction(contentType, filterType)
- ])
- }
- const filterReducer = combineReducers({
- movies: combineReducers({
- [CATEGORY]: createFilterReducer(MOVIES, CATEGORIES),
- [GENRE]: createFilterReducer(MOVIES, GENRES),
- [LANGUAGE]: createFilterReducer(MOVIES, LANGUAGES),
- [COUNTRY]: createFilterReducer(MOVIES, COUNTRIES)
- }),
- channels: combineReducers({
- [CATEGORY]: createFilterReducer(CHANNELS, CATEGORIES),
- [GENRE]: createFilterReducer(CHANNELS, GENRES),
- [LANGUAGE]: createFilterReducer(CHANNELS, LANGUAGES),
- [COUNTRY]: createFilterReducer(CHANNELS, COUNTRIES)
- })
- });
- export default filterReducer
Add Comment
Please, Sign In to add comment