redux-paginator-immutable 17.0.34 → 17.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/LoadPaginator.js +4 -58
- package/lib/LoadPaginator.js.map +1 -1
- package/lib/reducers.d.ts +1 -3
- package/lib/reducers.js +3 -7
- package/lib/reducers.js.map +1 -1
- package/lib/selectors.js +1 -1
- package/package.json +2 -2
- package/src/LoadPaginator.tsx +6 -63
- package/src/reducers.ts +48 -45
- package/src/selectors.ts +1 -1
- package/src/types/index.ts +1 -1
package/lib/LoadPaginator.js
CHANGED
|
@@ -34,57 +34,14 @@ const selectors_1 = __importDefault(require("./selectors"));
|
|
|
34
34
|
const LoadingButton_1 = __importDefault(require("./LoadingButton"));
|
|
35
35
|
const words_1 = __importDefault(require("./words"));
|
|
36
36
|
const LoadPaginator = (props) => {
|
|
37
|
-
const { token, settings } = props, { list, entities } = (0, react_redux_1.useSelector)((state) => (selectors_1.default.getPaginators(state, settings.key))),
|
|
38
|
-
// paginator = useMemo(() => {
|
|
39
|
-
// const
|
|
40
|
-
// currentPage = selectors.getCurrentView(list, token),
|
|
41
|
-
// isFetching = selectors.isPageFetching(list, token, currentPage),
|
|
42
|
-
// isFetched = selectors.isPageFetched(list, token, currentPage),
|
|
43
|
-
// isNextFetching = selectors.isPageFetching(list, token, currentPage + 1),
|
|
44
|
-
// isNextFetched = selectors.isPageFetched(list, token, currentPage + 1),
|
|
45
|
-
// eslint-disable-next-line max-len
|
|
46
|
-
// resultsUpTo = selectors.getResultsUpToPage(list, token, entities, currentPage, settings.rowsPerLoad),
|
|
47
|
-
// items = settings.manipulateItems(resultsUpTo),
|
|
48
|
-
// total = selectors.getCurrentTotalResultsCount(list, token),
|
|
49
|
-
// // currentPage was previously given to the following function
|
|
50
|
-
// hasProblems = selectors.hasPageProblems(list, token),
|
|
51
|
-
// shouldLoadNext = !isNextFetched && !isNextFetching;
|
|
52
|
-
// return Immutable.Map({
|
|
53
|
-
// currentPage,
|
|
54
|
-
// hasProblems,
|
|
55
|
-
// isFetched,
|
|
56
|
-
// isFetching,
|
|
57
|
-
// items,
|
|
58
|
-
// shouldLoadNext,
|
|
59
|
-
// total,
|
|
60
|
-
// });
|
|
61
|
-
// }, [list, entities, token]),
|
|
62
|
-
currentPage = selectors_1.default.getCurrentView(list, token), isFetching = selectors_1.default.isPageFetching(list, token, currentPage), isFetched = selectors_1.default.isPageFetched(list, token, currentPage),
|
|
63
|
-
// isNextFetching = selectors.isPageFetching(list, token, currentPage + 1),
|
|
64
|
-
// isNextFetched = selectors.isPageFetched(list, token, currentPage + 1),
|
|
65
|
-
// eslint-disable-next-line max-len
|
|
66
|
-
resultsUpTo = selectors_1.default.getResultsUpToPage(list, token, entities, currentPage, settings.rowsPerLoad), items = settings.manipulateItems(resultsUpTo), total = selectors_1.default.getCurrentTotalResultsCount(list, token),
|
|
67
|
-
// currentPage was previously given to the following function
|
|
68
|
-
hasProblems = selectors_1.default.hasPageProblems(list, token),
|
|
69
|
-
// shouldLoadNext = !isNextFetched && !isNextFetching,
|
|
70
|
-
paginator = Immutable.Map({
|
|
37
|
+
const { token, settings } = props, { list, entities } = (0, react_redux_1.useSelector)((state) => (selectors_1.default.getPaginators(state, settings.key))), currentPage = selectors_1.default.getCurrentView(list, token), isFetching = selectors_1.default.isPageFetching(list, token, currentPage), isFetched = selectors_1.default.isPageFetched(list, token, currentPage), resultsUpTo = (selectors_1.default.getResultsUpToPage(list, token, entities, currentPage, settings.rowsPerLoad)), items = settings.manipulateItems(resultsUpTo), total = selectors_1.default.getCurrentTotalResultsCount(list, token), hasProblems = selectors_1.default.hasPageProblems(list, token), paginator = Immutable.Map({
|
|
71
38
|
currentPage,
|
|
72
39
|
hasProblems,
|
|
73
40
|
isFetched,
|
|
74
41
|
isFetching,
|
|
75
42
|
items,
|
|
76
|
-
// shouldLoadNext,
|
|
77
43
|
total,
|
|
78
|
-
}), dispatch = (0, react_redux_1.useDispatch)(), resetView = (currentToken) => dispatch(settings.resetView(currentToken)), changeView = (data) => dispatch(settings.changeView(data)), loadData = (page) => dispatch(settings.requestPage(page, token)),
|
|
79
|
-
// items = paginator.get("items"),
|
|
80
|
-
// hasProblems = paginator.get("hasProblems"),
|
|
81
|
-
// currentPage = paginator.get("currentPage"),
|
|
82
|
-
// isFetching = paginator.get("isFetching"),
|
|
83
|
-
showLoading = paginator.get("total") !== items.size,
|
|
84
|
-
// isFetched = paginator.get("isFetched"),
|
|
85
|
-
shouldFetch = !isFetched && !isFetching, handleLoadMoreClick = () => {
|
|
86
|
-
// const
|
|
87
|
-
// shouldLoadNext = paginator.get("shouldLoadNext");
|
|
44
|
+
}), dispatch = (0, react_redux_1.useDispatch)(), resetView = (currentToken) => dispatch(settings.resetView(currentToken)), changeView = (data) => dispatch(settings.changeView(data)), loadData = (page) => dispatch(settings.requestPage(page, token)), showLoading = paginator.get("total") !== items.size, shouldFetch = !isFetched && !isFetching, handleLoadMoreClick = () => {
|
|
88
45
|
if (hasProblems) {
|
|
89
46
|
loadData(currentPage);
|
|
90
47
|
}
|
|
@@ -93,25 +50,14 @@ const LoadPaginator = (props) => {
|
|
|
93
50
|
token,
|
|
94
51
|
view: currentPage + 1,
|
|
95
52
|
});
|
|
96
|
-
// if (shouldLoadNext) {
|
|
97
|
-
// loadData(currentPage + 1);
|
|
98
|
-
// }
|
|
99
53
|
}
|
|
100
54
|
};
|
|
101
|
-
// eslint-disable-next-line no-console
|
|
102
|
-
console.log("paginator", paginator ? paginator.toJS() : null);
|
|
103
|
-
// eslint-disable-next-line no-console
|
|
104
|
-
console.log("currentPage", currentPage);
|
|
105
|
-
// eslint-disable-next-line no-console
|
|
106
|
-
console.log("list", list.toJS());
|
|
107
|
-
// eslint-disable-next-line no-console
|
|
108
|
-
console.log("entities", entities.toJS());
|
|
109
|
-
(0, react_1.useEffect)(() => (() => resetView(token)), []);
|
|
110
55
|
(0, react_1.useEffect)(() => {
|
|
111
56
|
if (shouldFetch) {
|
|
112
57
|
loadData(currentPage);
|
|
113
58
|
}
|
|
114
|
-
}, [shouldFetch
|
|
59
|
+
}, [shouldFetch]);
|
|
60
|
+
(0, react_1.useEffect)(() => () => resetView(token), []);
|
|
115
61
|
if (items.size === 0 && isFetching) {
|
|
116
62
|
return react_1.default.createElement(Messages_1.LoadingMessage, { message: words_1.default.LoadingData });
|
|
117
63
|
}
|
package/lib/LoadPaginator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoadPaginator.js","sourceRoot":"","sources":["../src/LoadPaginator.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"LoadPaginator.js","sourceRoot":"","sources":["../src/LoadPaginator.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAyC;AACzC,qDAAuC;AACvC,6CAAuD;AACvD,2CAAiE;AACjE,4DAAoC;AACpC,oEAA4C;AAC5C,oDAA4B;AAI5B,MACE,aAAa,GAAG,CAAC,KAA8B,EAAE,EAAE;IACjD,MACE,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,EAE3B,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAA,yBAAW,EAAC,CAAC,KAAa,EAAE,EAAE,CAAC,CAClD,mBAAS,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,CAAC,CAC7C,CAAC,EAEF,WAAW,GAAG,mBAAS,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,EACnD,UAAU,GAAG,mBAAS,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,EAC/D,SAAS,GAAG,mBAAS,CAAC,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,EAC7D,WAAW,GAAG,CACZ,mBAAS,CAAC,kBAAkB,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ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,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;IAE5C,IAAI,KAAK,CAAC,IAAI,KAAK,CAAC,IAAI,UAAU,EAAE;QAClC,OAAO,8BAAC,yBAAc,IAAC,OAAO,EAAE,eAAK,CAAC,WAAW,GAAI,CAAC;KACvD;IAED,IAAI,WAAW,IAAI,WAAW,KAAK,CAAC,EAAE;QACpC,OAAO,CACL,8BAAC,4BAAiB,IAChB,OAAO,EAAE,eAAK,CAAC,gBAAgB,EAC/B,OAAO,EAAE,mBAAmB,GAC5B,CACH,CAAC;KACH;IAED,OAAO,CACL;QAEI,eAAK,CAAC,YAAY,CAAC,KAAK,CAAC,QAAoC,EAAE;YAC7D,KAAK,EAAM,KAAK,CAAC,KAAK;YACtB,QAAQ,EAAG,KAAK,CAAC,QAAQ;YACzB,SAAS;YACT,UAAU;YACV,SAAS;YACT,QAAQ;SACT,CAAC;QAGF,WAAW,CAAC,CAAC,CAAC,CACZ,8BAAC,uBAAa,IACZ,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,mBAAmB,GACpC,CACH,CAAC,CAAC,CAAC,IAAI,CAET,CACJ,CAAC;AACJ,CAAC,CAAC;AAEJ,kBAAe,aAAa,CAAC"}
|
package/lib/reducers.d.ts
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import type { ItemsState, PagesState, Action } from "./types";
|
|
2
|
-
export declare const pages: (state: PagesState, action: Action) => any;
|
|
3
|
-
export declare const items: (state: ItemsState, action: Action) => any;
|
|
4
|
-
export declare const dataItems: (state: ItemsState, action: Action) => any;
|
|
2
|
+
export declare const pages: (state: PagesState, action: Action) => any, items: (state: ItemsState, action: Action) => any, dataItems: (state: ItemsState, action: Action) => any;
|
package/lib/reducers.js
CHANGED
|
@@ -44,9 +44,7 @@ const pages = (state = Immutable.Map(), action) => {
|
|
|
44
44
|
default:
|
|
45
45
|
return state;
|
|
46
46
|
}
|
|
47
|
-
}
|
|
48
|
-
exports.pages = pages;
|
|
49
|
-
const items = (state = Immutable.Map(), action) => {
|
|
47
|
+
}, items = (state = Immutable.Map(), action) => {
|
|
50
48
|
switch (action.type) {
|
|
51
49
|
case actionTypes_1.RECEIVE_PAGE:
|
|
52
50
|
return reducerOperations.receivePageItems(state, action);
|
|
@@ -56,9 +54,7 @@ const items = (state = Immutable.Map(), action) => {
|
|
|
56
54
|
default:
|
|
57
55
|
return state;
|
|
58
56
|
}
|
|
59
|
-
}
|
|
60
|
-
exports.items = items;
|
|
61
|
-
const dataItems = (state = Immutable.Map(), action) => {
|
|
57
|
+
}, dataItems = (state = Immutable.Map(), action) => {
|
|
62
58
|
switch (action.type) {
|
|
63
59
|
case actionTypes_1.RECEIVE_PAGE:
|
|
64
60
|
return reducerOperations.receivePageItems(state, action);
|
|
@@ -75,5 +71,5 @@ const dataItems = (state = Immutable.Map(), action) => {
|
|
|
75
71
|
return state;
|
|
76
72
|
}
|
|
77
73
|
};
|
|
78
|
-
exports.dataItems = dataItems;
|
|
74
|
+
exports.pages = pages, exports.items = items, exports.dataItems = dataItems;
|
|
79
75
|
//# sourceMappingURL=reducers.js.map
|
package/lib/reducers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reducers.js","sourceRoot":"","sources":["../src/reducers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;
|
|
1
|
+
{"version":3,"file":"reducers.js","sourceRoot":"","sources":["../src/reducers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAuC;AAEvC,+CAUuB;AAGvB,mEAAqD;AACrD,uEAAyD;AAElD,MACL,KAAK,GAAG,CAAC,QAAoB,SAAS,CAAC,GAAG,EAAE,EAAE,MAAc,EAAE,EAAE;IAC9D,QAAQ,MAAM,CAAC,IAAI,EAAE;QACnB,KAAK,0BAAY;YACf,OAAO,iBAAiB,CAAC,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K,EAAE,MAAM,CAAC,CAAC;QAE/D,KAAK,gDAAkC,CAAC;QACxC,KAAK,wBAAU;YACb,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;QAEvB;YACE,OAAO,KAAK,CAAC;KAChB;AACH,CAAC,CAAC;AAxDF,QAAA,KAAK,UAsBL,QAAA,KAAK,UAaL,QAAA,SAAS,aAqBP"}
|
package/lib/selectors.js
CHANGED
|
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const Immutable = __importStar(require("immutable"));
|
|
27
27
|
const reselect_1 = require("reselect");
|
|
28
|
-
const pagesSelector = (state) => state, rowsPerPage =
|
|
28
|
+
const pagesSelector = (state) => state, rowsPerPage = 25, pageSelector = (0, reselect_1.createSelector)(pagesSelector, (_state, token) => token, (pages, token) => pages.get(token)), getAllResults = (0, reselect_1.createSelector)(pageSelector, (_state, _token, items) => items, (page, items) => {
|
|
29
29
|
if (typeof page === "undefined") {
|
|
30
30
|
return Immutable.List();
|
|
31
31
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redux-paginator-immutable",
|
|
3
|
-
"version": "17.0.
|
|
3
|
+
"version": "17.0.36",
|
|
4
4
|
"types": "./lib/index.d.ts",
|
|
5
5
|
"description": "redux-paginator-immutable helps you deal with paginated API by composing your existing reducers",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -112,4 +112,4 @@
|
|
|
112
112
|
"superagent": "^7.1.3",
|
|
113
113
|
"x25": "^17.1.1"
|
|
114
114
|
}
|
|
115
|
-
}
|
|
115
|
+
}
|
package/src/LoadPaginator.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
import React, { useEffect } from "react";
|
|
3
2
|
import * as Immutable from "immutable";
|
|
4
3
|
import { useDispatch, useSelector } from "react-redux";
|
|
@@ -18,45 +17,15 @@ const
|
|
|
18
17
|
selectors.getPaginators(state, settings.key)
|
|
19
18
|
)),
|
|
20
19
|
|
|
21
|
-
// paginator = useMemo(() => {
|
|
22
|
-
// const
|
|
23
|
-
// currentPage = selectors.getCurrentView(list, token),
|
|
24
|
-
// isFetching = selectors.isPageFetching(list, token, currentPage),
|
|
25
|
-
// isFetched = selectors.isPageFetched(list, token, currentPage),
|
|
26
|
-
// isNextFetching = selectors.isPageFetching(list, token, currentPage + 1),
|
|
27
|
-
// isNextFetched = selectors.isPageFetched(list, token, currentPage + 1),
|
|
28
|
-
// eslint-disable-next-line max-len
|
|
29
|
-
// resultsUpTo = selectors.getResultsUpToPage(list, token, entities, currentPage, settings.rowsPerLoad),
|
|
30
|
-
// items = settings.manipulateItems(resultsUpTo),
|
|
31
|
-
// total = selectors.getCurrentTotalResultsCount(list, token),
|
|
32
|
-
// // currentPage was previously given to the following function
|
|
33
|
-
// hasProblems = selectors.hasPageProblems(list, token),
|
|
34
|
-
// shouldLoadNext = !isNextFetched && !isNextFetching;
|
|
35
|
-
|
|
36
|
-
// return Immutable.Map({
|
|
37
|
-
// currentPage,
|
|
38
|
-
// hasProblems,
|
|
39
|
-
// isFetched,
|
|
40
|
-
// isFetching,
|
|
41
|
-
// items,
|
|
42
|
-
// shouldLoadNext,
|
|
43
|
-
// total,
|
|
44
|
-
// });
|
|
45
|
-
// }, [list, entities, token]),
|
|
46
|
-
|
|
47
|
-
|
|
48
20
|
currentPage = selectors.getCurrentView(list, token),
|
|
49
21
|
isFetching = selectors.isPageFetching(list, token, currentPage),
|
|
50
22
|
isFetched = selectors.isPageFetched(list, token, currentPage),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
resultsUpTo = selectors.getResultsUpToPage(list, token, entities, currentPage, settings.rowsPerLoad),
|
|
23
|
+
resultsUpTo = (
|
|
24
|
+
selectors.getResultsUpToPage(list, token, entities, currentPage, settings.rowsPerLoad)
|
|
25
|
+
),
|
|
55
26
|
items = settings.manipulateItems(resultsUpTo),
|
|
56
27
|
total = selectors.getCurrentTotalResultsCount(list, token),
|
|
57
|
-
// currentPage was previously given to the following function
|
|
58
28
|
hasProblems = selectors.hasPageProblems(list, token),
|
|
59
|
-
// shouldLoadNext = !isNextFetched && !isNextFetching,
|
|
60
29
|
|
|
61
30
|
paginator = Immutable.Map({
|
|
62
31
|
currentPage,
|
|
@@ -64,7 +33,6 @@ const
|
|
|
64
33
|
isFetched,
|
|
65
34
|
isFetching,
|
|
66
35
|
items,
|
|
67
|
-
// shouldLoadNext,
|
|
68
36
|
total,
|
|
69
37
|
}),
|
|
70
38
|
|
|
@@ -73,18 +41,10 @@ const
|
|
|
73
41
|
changeView : ChangeView = (data) => dispatch(settings.changeView(data)),
|
|
74
42
|
loadData : LoadData = (page) => dispatch(settings.requestPage(page, token)),
|
|
75
43
|
|
|
76
|
-
// items = paginator.get("items"),
|
|
77
|
-
// hasProblems = paginator.get("hasProblems"),
|
|
78
|
-
// currentPage = paginator.get("currentPage"),
|
|
79
|
-
// isFetching = paginator.get("isFetching"),
|
|
80
44
|
showLoading = paginator.get("total") !== items.size,
|
|
81
45
|
|
|
82
|
-
// isFetched = paginator.get("isFetched"),
|
|
83
46
|
shouldFetch = !isFetched && !isFetching,
|
|
84
47
|
handleLoadMoreClick = () => {
|
|
85
|
-
// const
|
|
86
|
-
// shouldLoadNext = paginator.get("shouldLoadNext");
|
|
87
|
-
|
|
88
48
|
if (hasProblems) {
|
|
89
49
|
loadData(currentPage);
|
|
90
50
|
} else {
|
|
@@ -92,33 +52,16 @@ const
|
|
|
92
52
|
token,
|
|
93
53
|
view: currentPage + 1,
|
|
94
54
|
});
|
|
95
|
-
|
|
96
|
-
// if (shouldLoadNext) {
|
|
97
|
-
// loadData(currentPage + 1);
|
|
98
|
-
// }
|
|
99
55
|
}
|
|
100
56
|
};
|
|
101
57
|
|
|
102
|
-
// eslint-disable-next-line no-console
|
|
103
|
-
console.log("paginator", paginator ? paginator.toJS() : null);
|
|
104
|
-
|
|
105
|
-
// eslint-disable-next-line no-console
|
|
106
|
-
console.log("currentPage", currentPage);
|
|
107
|
-
|
|
108
|
-
// eslint-disable-next-line no-console
|
|
109
|
-
console.log("list", list.toJS());
|
|
110
|
-
// eslint-disable-next-line no-console
|
|
111
|
-
console.log("entities", entities.toJS());
|
|
112
|
-
|
|
113
|
-
useEffect(() => (
|
|
114
|
-
() => resetView(token)
|
|
115
|
-
), []);
|
|
116
|
-
|
|
117
58
|
useEffect(() => {
|
|
118
59
|
if (shouldFetch) {
|
|
119
60
|
loadData(currentPage);
|
|
120
61
|
}
|
|
121
|
-
}, [shouldFetch
|
|
62
|
+
}, [shouldFetch]);
|
|
63
|
+
|
|
64
|
+
useEffect(() => () => resetView(token), []);
|
|
122
65
|
|
|
123
66
|
if (items.size === 0 && isFetching) {
|
|
124
67
|
return <LoadingMessage message={words.LoadingData} />;
|
package/src/reducers.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as Immutable from "immutable";
|
|
2
|
+
|
|
2
3
|
import {
|
|
3
4
|
REQUEST_PAGE,
|
|
4
5
|
RECEIVE_PAGE,
|
|
@@ -10,64 +11,66 @@ import {
|
|
|
10
11
|
FETCH_ITEM_DATA_REJECTED,
|
|
11
12
|
FETCH_ITEM_DATA_FULFILLED,
|
|
12
13
|
} from "./actionTypes";
|
|
14
|
+
|
|
13
15
|
import type { ItemsState, PagesState, Action } from "./types";
|
|
14
16
|
import * as reducerItemData from "./reducerItemData";
|
|
15
17
|
import * as reducerOperations from "./reducerOperations";
|
|
16
18
|
|
|
17
|
-
export const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
export const
|
|
20
|
+
pages = (state: PagesState = Immutable.Map(), action: Action) => {
|
|
21
|
+
switch (action.type) {
|
|
22
|
+
case REQUEST_PAGE:
|
|
23
|
+
return reducerOperations.requestPage(state, action);
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
case RECEIVE_PAGE:
|
|
26
|
+
return reducerOperations.receivePage(state, action);
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
case RESET_VIEW:
|
|
29
|
+
return reducerOperations.resetView(state, action);
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
case CHANGE_VIEW:
|
|
32
|
+
return reducerOperations.changeView(state, action);
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
+
case FETCH_CURRENT_COMPANY_INFO_PENDING:
|
|
35
|
+
case CLEAR_DATA:
|
|
36
|
+
return state.clear();
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
default:
|
|
39
|
+
return state;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
items = (state: ItemsState = Immutable.Map(), action: Action) => {
|
|
43
|
+
switch (action.type) {
|
|
44
|
+
case RECEIVE_PAGE:
|
|
45
|
+
return reducerOperations.receivePageItems(state, action);
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
case FETCH_CURRENT_COMPANY_INFO_PENDING:
|
|
48
|
+
case CLEAR_DATA:
|
|
49
|
+
return state.clear();
|
|
47
50
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
default:
|
|
52
|
+
return state;
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
dataItems = (state: ItemsState = Immutable.Map(), action: Action) => {
|
|
56
|
+
switch (action.type) {
|
|
57
|
+
case RECEIVE_PAGE:
|
|
58
|
+
return reducerOperations.receivePageItems(state, action);
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
case FETCH_ITEM_DATA_PENDING:
|
|
61
|
+
return reducerItemData.fetchItemDataPending(state, action);
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
case FETCH_ITEM_DATA_REJECTED:
|
|
64
|
+
return reducerItemData.fetchItemDataRejected(state, action);
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
case FETCH_ITEM_DATA_FULFILLED:
|
|
67
|
+
return reducerItemData.fetchItemDataFulFilled(state, action);
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
case FETCH_CURRENT_COMPANY_INFO_PENDING:
|
|
70
|
+
case CLEAR_DATA:
|
|
71
|
+
return state.clear();
|
|
69
72
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
73
|
+
default:
|
|
74
|
+
return state;
|
|
75
|
+
}
|
|
76
|
+
};
|
package/src/selectors.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type PaginatorSettings = {
|
|
|
15
15
|
key: string;
|
|
16
16
|
manageEntity: any;
|
|
17
17
|
resultsKey: string;
|
|
18
|
-
// by default
|
|
18
|
+
// by default 25 per page
|
|
19
19
|
rowsPerLoad?: number;
|
|
20
20
|
// by default "(items) => items"
|
|
21
21
|
manipulateItems?: (items: any) => any;
|