Guest User

Untitled

a guest
May 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import {combineReducers} from 'redux';
  2. import {createApiReducer} from './utils';
  3. import {
  4. CATEGORIES,
  5. CHANNELS,
  6. COUNTRIES,
  7. filterLoadedAction,
  8. filterLoadingAction,
  9. filterLoadingErrorAction,
  10. GENRES,
  11. LANGUAGES,
  12. MOVIES
  13. } from '../constants/actionTypes'
  14.  
  15. import {CATEGORY, COUNTRY, GENRE, LANGUAGE} from './../constants/filterTypes';
  16. import type {CategoryFilter, CountryFilter, GenreFilter, LanguageFilter} from "../entities";
  17.  
  18. export type FilterState<T> = {
  19. data: Array<T>
  20. }
  21.  
  22. export type EntityFiltersState = {
  23. category: FilterState<CategoryFilter>,
  24. genre: FilterState<GenreFilter>,
  25. language: FilterState<LanguageFilter>,
  26. country: FilterState<CountryFilter>
  27. }
  28.  
  29. export type FiltersState = {
  30. movies: EntityFiltersState,
  31. channels: EntityFiltersState
  32. }
  33.  
  34. function createFilterReducer(contentType, filterType) {
  35. return createApiReducer([
  36. filterLoadingAction(contentType, filterType),
  37. filterLoadedAction(contentType, filterType),
  38. filterLoadingErrorAction(contentType, filterType)
  39. ])
  40. }
  41.  
  42. const filterReducer = combineReducers({
  43. movies: combineReducers({
  44. [CATEGORY]: createFilterReducer(MOVIES, CATEGORIES),
  45. [GENRE]: createFilterReducer(MOVIES, GENRES),
  46. [LANGUAGE]: createFilterReducer(MOVIES, LANGUAGES),
  47. [COUNTRY]: createFilterReducer(MOVIES, COUNTRIES)
  48. }),
  49. channels: combineReducers({
  50. [CATEGORY]: createFilterReducer(CHANNELS, CATEGORIES),
  51. [GENRE]: createFilterReducer(CHANNELS, GENRES),
  52. [LANGUAGE]: createFilterReducer(CHANNELS, LANGUAGES),
  53. [COUNTRY]: createFilterReducer(CHANNELS, COUNTRIES)
  54. })
  55. });
  56.  
  57. export default filterReducer
Add Comment
Please, Sign In to add comment