redux filter reducer

Solutions on MaxInterview for redux filter reducer by the best coders in the world

showing results for - "redux filter reducer"
Augustus
26 Jan 2017
1// reducers.js
2
3const items = [{
4  title: 'Mad max',
5  year: 2015,
6  rating: 8,
7  genre: 'fantasy',
8}, {
9  title: 'Spider man 2',
10  year: 2014,
11  rating: 7,
12  genre: 'fantasy',
13}, {
14  title: 'Iron man 3',
15  year: 2013,
16  rating: 7,
17  genre: 'fantasy',
18}, {
19  title: 'Dumb and Dumber To',
20  year: 2014,
21  rating: 5,
22  genre: 'comedy',
23}, {
24  title: 'Ted 2',
25  year: 2015,
26  rating: 6,
27  genre: 'comedy',
28}];
29
30export default function moviesReducer(state = {
31  movies: items,
32  year: 'all',
33  rating: 'all',
34  genre: 'all',
35  sorting: 'year',
36}, action) {
37  switch (action.type) {
38    case 'SET_YEAR':
39      return {
40        ...state,
41        year: action.year,
42      };
43    case 'SET_RATING':
44      return {
45        ...state,
46        rating: action.rating,
47      };
48    case 'SET_GENRE':
49      return {
50        ...state,
51        genre: action.genre,
52      };
53    case 'SET_SORTING':
54      return {
55        ...state,
56        sorting: action.sorting,
57      };
58    default:
59      return state;
60  }
61}
62