UNPKG

1.11 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = createItemsReducer;
7
8var _immutable = require('immutable');
9
10/**
11 * @param actionTypes
12 * @param idField
13 * @returns {paginationReducer}
14 */
15function 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 * @param {Object} state
27 * @param {Object} action
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} /** Created by hhj on 8/29/16. */
\No newline at end of file