1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = createItemsReducer;
|
7 |
|
8 | var _immutable = require('immutable');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function createItemsReducer(actionTypes) {
|
16 | var idField = arguments.length <= 1 || arguments[1] === undefined ? 'id' : arguments[1];
|
17 |
|
18 |
|
19 | var itemsIds = function itemsIds(items) {
|
20 | return (0, _immutable.List)(items).map(function (item) {
|
21 | return item[idField];
|
22 | });
|
23 | };
|
24 |
|
25 | |
26 |
|
27 |
|
28 |
|
29 | return function paginationReducer() {
|
30 | var state = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
|
31 | var action = arguments[1];
|
32 |
|
33 |
|
34 | var items = action.data;
|
35 |
|
36 | switch (action.type) {
|
37 |
|
38 | case actionTypes.fetchCollectionSuccess:
|
39 | case actionTypes.fetchCollectionByIdsSuccess:
|
40 | return itemsIds(items);
|
41 |
|
42 | case actionTypes.fetchCollectionError:
|
43 | return (0, _immutable.List)();
|
44 |
|
45 | default:
|
46 | return state;
|
47 | }
|
48 | };
|
49 | } |
\ | No newline at end of file |