redux-paginator-immutable 17.0.49 → 17.0.51
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/package.json +19 -16
- package/README.md +0 -3
- package/lib/Info.d.ts +0 -9
- package/lib/Info.js +0 -18
- package/lib/Info.js.map +0 -1
- package/lib/LoadDataItem.d.ts +0 -25
- package/lib/LoadDataItem.js +0 -60
- package/lib/LoadDataItem.js.map +0 -1
- package/lib/LoadPaginator.d.ts +0 -4
- package/lib/LoadPaginator.js +0 -79
- package/lib/LoadPaginator.js.map +0 -1
- package/lib/LoadPaginatorTypes.d.ts +0 -29
- package/lib/LoadPaginatorTypes.js +0 -3
- package/lib/LoadPaginatorTypes.js.map +0 -1
- package/lib/LoadingButton.d.ts +0 -8
- package/lib/LoadingButton.js +0 -26
- package/lib/LoadingButton.js.map +0 -1
- package/lib/actionTypes.d.ts +0 -9
- package/lib/actionTypes.js +0 -13
- package/lib/actionTypes.js.map +0 -1
- package/lib/actions.d.ts +0 -42
- package/lib/actions.js +0 -82
- package/lib/actions.js.map +0 -1
- package/lib/agent.d.ts +0 -8
- package/lib/agent.js +0 -37
- package/lib/agent.js.map +0 -1
- package/lib/createDataReducer.d.ts +0 -14
- package/lib/createDataReducer.js +0 -67
- package/lib/createDataReducer.js.map +0 -1
- package/lib/createItemReducer.d.ts +0 -9
- package/lib/createItemReducer.js +0 -18
- package/lib/createItemReducer.js.map +0 -1
- package/lib/createPaginator.d.ts +0 -33
- package/lib/createPaginator.js +0 -87
- package/lib/createPaginator.js.map +0 -1
- package/lib/index.d.ts +0 -11
- package/lib/index.js +0 -30
- package/lib/index.js.map +0 -1
- package/lib/paginatorMiddleware.d.ts +0 -5
- package/lib/paginatorMiddleware.js +0 -69
- package/lib/paginatorMiddleware.js.map +0 -1
- package/lib/reducerItemData.d.ts +0 -18
- package/lib/reducerItemData.js +0 -60
- package/lib/reducerItemData.js.map +0 -1
- package/lib/reducerOperations.d.ts +0 -4
- package/lib/reducerOperations.js +0 -75
- package/lib/reducerOperations.js.map +0 -1
- package/lib/reducers.d.ts +0 -2
- package/lib/reducers.js +0 -75
- package/lib/reducers.js.map +0 -1
- package/lib/selectors.d.ts +0 -38
- package/lib/selectors.js +0 -83
- package/lib/selectors.js.map +0 -1
- package/lib/types.d.ts +0 -107
- package/lib/types.js +0 -3
- package/lib/types.js.map +0 -1
- package/lib/util.d.ts +0 -9
- package/lib/util.js +0 -53
- package/lib/util.js.map +0 -1
- package/src/Info.tsx +0 -28
- package/src/LoadDataItem.tsx +0 -84
- package/src/LoadPaginator.tsx +0 -104
- package/src/LoadPaginatorTypes.ts +0 -31
- package/src/LoadingButton.tsx +0 -44
- package/src/__tests__/actions.spec.js +0 -130
- package/src/__tests__/agent.spec.js +0 -32
- package/src/__tests__/createPaginator.spec.js +0 -39
- package/src/__tests__/reducers.spec.js +0 -131
- package/src/__tests__/selectors.spec.js +0 -180
- package/src/__tests__/setup.js +0 -1
- package/src/actionTypes.ts +0 -9
- package/src/actions.ts +0 -156
- package/src/agent.ts +0 -62
- package/src/createDataReducer.ts +0 -90
- package/src/createItemReducer.ts +0 -29
- package/src/createPaginator.ts +0 -104
- package/src/index.ts +0 -26
- package/src/paginatorMiddleware.ts +0 -93
- package/src/reducerItemData.ts +0 -74
- package/src/reducerOperations.ts +0 -92
- package/src/reducers.ts +0 -77
- package/src/selectors.ts +0 -111
- package/src/types.ts +0 -130
- package/src/util.ts +0 -51
package/src/agent.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-bitwise*/
|
|
2
|
-
|
|
3
|
-
type FetchPageArgs = {
|
|
4
|
-
endpoint: string;
|
|
5
|
-
pageArgName: string;
|
|
6
|
-
page: number;
|
|
7
|
-
token: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
import agent from "superagent";
|
|
11
|
-
import qs from "query-string";
|
|
12
|
-
|
|
13
|
-
export const
|
|
14
|
-
buildSuffix = (pageArgName: string, page: number, params: string) => {
|
|
15
|
-
const parsedParams = qs.parse(params);
|
|
16
|
-
let finalParsedParams = {},
|
|
17
|
-
startString = "";
|
|
18
|
-
|
|
19
|
-
for (const key of Object.keys(parsedParams)) {
|
|
20
|
-
if (parsedParams[key] === null) {
|
|
21
|
-
startString += key;
|
|
22
|
-
} else {
|
|
23
|
-
finalParsedParams = { ...finalParsedParams,
|
|
24
|
-
[key]: parsedParams[key],
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
startString = startString === "" ? "?" : `${startString}?`;
|
|
30
|
-
|
|
31
|
-
if (Object.keys(finalParsedParams).length > 0 && qs.extract(params) !== "") {
|
|
32
|
-
startString = params.replace(qs.extract(params), "");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return startString + qs.stringify({ ...finalParsedParams,
|
|
36
|
-
[pageArgName]: page,
|
|
37
|
-
}, {
|
|
38
|
-
encode: false,
|
|
39
|
-
}).replace(startString, "");
|
|
40
|
-
},
|
|
41
|
-
fetchPage = ({
|
|
42
|
-
endpoint,
|
|
43
|
-
pageArgName,
|
|
44
|
-
page,
|
|
45
|
-
token,
|
|
46
|
-
}: FetchPageArgs) => {
|
|
47
|
-
const suffix = buildSuffix(pageArgName, page, token),
|
|
48
|
-
url = endpoint + suffix,
|
|
49
|
-
promise: any = new Promise(
|
|
50
|
-
(resolve: any, reject: any) => (
|
|
51
|
-
agent.
|
|
52
|
-
get(url).
|
|
53
|
-
end((err: any, res: any) => err ? reject(err) : resolve(res))
|
|
54
|
-
),
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
return promise.then((res: {
|
|
58
|
-
body: any;
|
|
59
|
-
}) => ({
|
|
60
|
-
response: res.body,
|
|
61
|
-
}));
|
|
62
|
-
};
|
package/src/createDataReducer.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { createSelector } from "reselect";
|
|
2
|
-
import * as Immutable from "immutable";
|
|
3
|
-
import { PaginatorSettings } from "./types";
|
|
4
|
-
|
|
5
|
-
type Selector = (state : any, id : string) => any;
|
|
6
|
-
type ListSelector = (state : any) => any;
|
|
7
|
-
|
|
8
|
-
/*
|
|
9
|
-
Use to create a complex list where you need more information about
|
|
10
|
-
the item. For instance, if you DO need to fetch more data or to
|
|
11
|
-
manipulate it
|
|
12
|
-
*/
|
|
13
|
-
const
|
|
14
|
-
createDataReducer = ({ key }: PaginatorSettings) => {
|
|
15
|
-
const
|
|
16
|
-
getItems = (state: any) : any => (
|
|
17
|
-
state.getIn(["entities", key])
|
|
18
|
-
),
|
|
19
|
-
getItem : Selector = createSelector(
|
|
20
|
-
getItems,
|
|
21
|
-
(_state : any, id : string) => id,
|
|
22
|
-
(data : any, id : string) : any => data.get(id) || Immutable.Map(),
|
|
23
|
-
),
|
|
24
|
-
getItemsList : ListSelector = createSelector(
|
|
25
|
-
getItems,
|
|
26
|
-
(data : any) => data.map((current : any) => current.get("Data")).toList(),
|
|
27
|
-
),
|
|
28
|
-
getItemData : Selector = createSelector(
|
|
29
|
-
getItems,
|
|
30
|
-
(_state : any, id : string) => id,
|
|
31
|
-
(data : any, id : string) : any => {
|
|
32
|
-
if (typeof data === "undefined") {
|
|
33
|
-
return Immutable.Map();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return data.getIn([id, "Data"]);
|
|
37
|
-
},
|
|
38
|
-
),
|
|
39
|
-
getItemHasError : Selector = createSelector(
|
|
40
|
-
getItem,
|
|
41
|
-
(data : any) : boolean => {
|
|
42
|
-
if (typeof data === "undefined") {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return data.get("error") === true;
|
|
47
|
-
},
|
|
48
|
-
),
|
|
49
|
-
getIsFetchingItemInfo : Selector = createSelector(
|
|
50
|
-
getItem,
|
|
51
|
-
(data : any) : boolean => {
|
|
52
|
-
if (typeof data === "undefined") {
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return data.get("fetching");
|
|
57
|
-
},
|
|
58
|
-
),
|
|
59
|
-
getItemIsFetched : Selector = createSelector(
|
|
60
|
-
getItem,
|
|
61
|
-
(data : any) : boolean => {
|
|
62
|
-
if (typeof data === "undefined") {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return data.get("fetched");
|
|
67
|
-
},
|
|
68
|
-
),
|
|
69
|
-
getShouldFetchItemInfo : Selector = createSelector(
|
|
70
|
-
getIsFetchingItemInfo,
|
|
71
|
-
getItemIsFetched,
|
|
72
|
-
getItemHasError,
|
|
73
|
-
(isFetching : boolean, isFetched : boolean, hasError : boolean) : boolean => (
|
|
74
|
-
!isFetched && !isFetching && !hasError
|
|
75
|
-
),
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
return {
|
|
79
|
-
getItems,
|
|
80
|
-
getItem,
|
|
81
|
-
getItemsList,
|
|
82
|
-
getItemData,
|
|
83
|
-
getItemHasError,
|
|
84
|
-
getIsFetchingItemInfo,
|
|
85
|
-
getItemIsFetched,
|
|
86
|
-
getShouldFetchItemInfo,
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
export default createDataReducer;
|
package/src/createItemReducer.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { createSelector } from "reselect";
|
|
2
|
-
import { PaginatorSettings } from "./types";
|
|
3
|
-
|
|
4
|
-
/*
|
|
5
|
-
Use to create a simple list where you do not need more information about
|
|
6
|
-
the item. For instance, if you do NOT need to fetch more data or
|
|
7
|
-
manipulate it
|
|
8
|
-
*/
|
|
9
|
-
const createReducer = ({ key }: PaginatorSettings) => {
|
|
10
|
-
const
|
|
11
|
-
getItems = (state: any) => state.getIn(["entities", key]),
|
|
12
|
-
getItem : (state : any, id : string) => any = createSelector(
|
|
13
|
-
getItems,
|
|
14
|
-
(_state : any, id : string) => id,
|
|
15
|
-
(data : any, id : string) => data.get(id),
|
|
16
|
-
),
|
|
17
|
-
getItemsList = createSelector(
|
|
18
|
-
getItems,
|
|
19
|
-
(data : any) => data.toList(),
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
return {
|
|
23
|
-
getItems,
|
|
24
|
-
getItem,
|
|
25
|
-
getItemsList,
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default createReducer;
|
package/src/createPaginator.ts
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
const defaultRowsPerLoad = 25;
|
|
2
|
-
|
|
3
|
-
import * as Immutable from "immutable";
|
|
4
|
-
import { pages as pagesReducer, items as itemsReducer, dataItems as dataItemsReducer } from "./reducers";
|
|
5
|
-
import actions from "./actions";
|
|
6
|
-
import { PaginatorSettings } from "./types";
|
|
7
|
-
|
|
8
|
-
type EndpointData = {
|
|
9
|
-
path: string;
|
|
10
|
-
cb: () => string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
type Endpoint = EndpointData | string;
|
|
14
|
-
|
|
15
|
-
type Action = {
|
|
16
|
-
meta?: {
|
|
17
|
-
endpoint: string;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const getEndpoint = (data: Endpoint) => {
|
|
22
|
-
if (typeof data === "object") {
|
|
23
|
-
return {
|
|
24
|
-
path : data.path,
|
|
25
|
-
cb : data.cb,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
path : data,
|
|
31
|
-
cb : null,
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export const
|
|
36
|
-
onlyForEndpoint = (endpoint : string, reducer : any) => (state = Immutable.Map(), action : Action) => {
|
|
37
|
-
if (typeof action.meta === "undefined" || action.meta.endpoint !== endpoint) {
|
|
38
|
-
return state;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return reducer(state, action);
|
|
42
|
-
},
|
|
43
|
-
createPaginator = (endpointData: Endpoint, settings: PaginatorSettings) => {
|
|
44
|
-
const
|
|
45
|
-
{
|
|
46
|
-
path: endpoint,
|
|
47
|
-
cb: endpointCb,
|
|
48
|
-
} = getEndpoint(endpointData),
|
|
49
|
-
{
|
|
50
|
-
key,
|
|
51
|
-
normalizeDataItem,
|
|
52
|
-
dataItemURL,
|
|
53
|
-
manageEntity,
|
|
54
|
-
resultsKey,
|
|
55
|
-
totalKey = "Total",
|
|
56
|
-
pageArgName = "page",
|
|
57
|
-
idKey = "ID",
|
|
58
|
-
rowsPerLoad = defaultRowsPerLoad,
|
|
59
|
-
manipulateItems = (items) => items,
|
|
60
|
-
} = settings,
|
|
61
|
-
endpointedActions = {
|
|
62
|
-
requestPage: (page: number, token: string) => actions.requestPage({
|
|
63
|
-
endpoint,
|
|
64
|
-
endpointCb,
|
|
65
|
-
manageEntity,
|
|
66
|
-
resultsKey,
|
|
67
|
-
totalKey,
|
|
68
|
-
pageArgName,
|
|
69
|
-
idKey,
|
|
70
|
-
page,
|
|
71
|
-
token,
|
|
72
|
-
}),
|
|
73
|
-
|
|
74
|
-
resetView (token : any) {
|
|
75
|
-
return actions.resetView(endpoint, token);
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
changeView ({ view, token }: { view: number; token: string; }) {
|
|
79
|
-
return actions.changeView(endpoint, {
|
|
80
|
-
view,
|
|
81
|
-
token,
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
|
|
85
|
-
clearData () {
|
|
86
|
-
return actions.clearData(endpoint);
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
key,
|
|
92
|
-
normalizeDataItem,
|
|
93
|
-
dataItemURL,
|
|
94
|
-
manipulateItems,
|
|
95
|
-
rowsPerLoad,
|
|
96
|
-
manageEntity,
|
|
97
|
-
resultsKey,
|
|
98
|
-
endpoint,
|
|
99
|
-
pagesReducer : onlyForEndpoint(endpoint, pagesReducer),
|
|
100
|
-
itemsReducer : onlyForEndpoint(endpoint, itemsReducer),
|
|
101
|
-
dataItemsReducer : onlyForEndpoint(endpoint, dataItemsReducer),
|
|
102
|
-
...endpointedActions,
|
|
103
|
-
};
|
|
104
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { createPaginator } from "./createPaginator";
|
|
2
|
-
import paginatorMiddleware from "./paginatorMiddleware";
|
|
3
|
-
import paginatorSelectors from "./selectors";
|
|
4
|
-
import { manageDataEntity, manipulateDataItems, manipulateItems, manageEntity } from "./util";
|
|
5
|
-
import Info from "./Info";
|
|
6
|
-
import LoadingButton from "./LoadingButton";
|
|
7
|
-
import LoadPaginator from "./LoadPaginator";
|
|
8
|
-
import LoadDataItem from "./LoadDataItem";
|
|
9
|
-
import createDataReducer from "./createDataReducer";
|
|
10
|
-
import createItemReducer from "./createItemReducer";
|
|
11
|
-
|
|
12
|
-
export {
|
|
13
|
-
Info,
|
|
14
|
-
LoadingButton,
|
|
15
|
-
LoadPaginator,
|
|
16
|
-
LoadDataItem,
|
|
17
|
-
createPaginator,
|
|
18
|
-
paginatorMiddleware,
|
|
19
|
-
paginatorSelectors,
|
|
20
|
-
createDataReducer,
|
|
21
|
-
manageDataEntity,
|
|
22
|
-
manipulateDataItems,
|
|
23
|
-
createItemReducer,
|
|
24
|
-
manipulateItems,
|
|
25
|
-
manageEntity,
|
|
26
|
-
};
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console, max-lines-per-function */
|
|
2
|
-
import { REQUEST_PAGE } from "./actionTypes";
|
|
3
|
-
import actions from "./actions";
|
|
4
|
-
import { fetchPage } from "./agent";
|
|
5
|
-
import { Action, Dispatch } from "./types";
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
{ receivePage } = actions,
|
|
9
|
-
|
|
10
|
-
paginatorMiddleware = ({ dispatch }: { dispatch: Dispatch;}) => (next: any) => (action: Action) => {
|
|
11
|
-
if (action.type === REQUEST_PAGE) {
|
|
12
|
-
const {
|
|
13
|
-
meta: {
|
|
14
|
-
endpoint,
|
|
15
|
-
endpointCb,
|
|
16
|
-
manageEntity,
|
|
17
|
-
resultsKey,
|
|
18
|
-
totalKey,
|
|
19
|
-
pageArgName,
|
|
20
|
-
idKey,
|
|
21
|
-
},
|
|
22
|
-
payload: {
|
|
23
|
-
page,
|
|
24
|
-
token,
|
|
25
|
-
},
|
|
26
|
-
} = action;
|
|
27
|
-
|
|
28
|
-
dispatch((dispatch2) => {
|
|
29
|
-
const
|
|
30
|
-
markAsError = () => {
|
|
31
|
-
dispatch2(receivePage({
|
|
32
|
-
endpoint,
|
|
33
|
-
endpointCb,
|
|
34
|
-
manageEntity,
|
|
35
|
-
pageArgName,
|
|
36
|
-
idKey,
|
|
37
|
-
page,
|
|
38
|
-
error : true,
|
|
39
|
-
token,
|
|
40
|
-
items : [],
|
|
41
|
-
total : 0,
|
|
42
|
-
}));
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
rawPath = typeof endpointCb === "function" ? endpointCb(token) : endpoint,
|
|
46
|
-
path = rawPath === null ? "" : rawPath;
|
|
47
|
-
|
|
48
|
-
try {
|
|
49
|
-
fetchPage({
|
|
50
|
-
endpoint: path,
|
|
51
|
-
pageArgName,
|
|
52
|
-
page,
|
|
53
|
-
token,
|
|
54
|
-
}).then((res: { response: any; }) => {
|
|
55
|
-
const { response } = res;
|
|
56
|
-
|
|
57
|
-
let
|
|
58
|
-
results = [],
|
|
59
|
-
total = 0;
|
|
60
|
-
|
|
61
|
-
if (typeof resultsKey === "undefined") {
|
|
62
|
-
results = response;
|
|
63
|
-
} else {
|
|
64
|
-
results = response[resultsKey];
|
|
65
|
-
total = response[totalKey];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
dispatch2(receivePage({
|
|
69
|
-
endpoint,
|
|
70
|
-
endpointCb,
|
|
71
|
-
manageEntity,
|
|
72
|
-
pageArgName,
|
|
73
|
-
idKey,
|
|
74
|
-
page,
|
|
75
|
-
error : false,
|
|
76
|
-
token,
|
|
77
|
-
items : results,
|
|
78
|
-
total,
|
|
79
|
-
}));
|
|
80
|
-
}).
|
|
81
|
-
catch(() => {
|
|
82
|
-
markAsError();
|
|
83
|
-
});
|
|
84
|
-
} catch (err) {
|
|
85
|
-
markAsError();
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return next(action);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export default paginatorMiddleware;
|
package/src/reducerItemData.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
type FetchItemDataFulFilledProps = {
|
|
2
|
-
payload: {
|
|
3
|
-
Data: any;
|
|
4
|
-
};
|
|
5
|
-
meta: {
|
|
6
|
-
id: string;
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
import * as Immutable from "immutable";
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
defaultOptions = Immutable.Map({
|
|
13
|
-
fetching : true,
|
|
14
|
-
fetched : false,
|
|
15
|
-
error : false,
|
|
16
|
-
}),
|
|
17
|
-
|
|
18
|
-
fetchItemDataPending = (state: any, {
|
|
19
|
-
meta: {
|
|
20
|
-
id,
|
|
21
|
-
},
|
|
22
|
-
}: {
|
|
23
|
-
meta: {
|
|
24
|
-
id: string;
|
|
25
|
-
};
|
|
26
|
-
}) => (
|
|
27
|
-
state.update(id, (current : any) => {
|
|
28
|
-
if (typeof current === "undefined") {
|
|
29
|
-
return defaultOptions;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return current.mergeDeep(defaultOptions);
|
|
33
|
-
})
|
|
34
|
-
),
|
|
35
|
-
fetchItemDataRejected = (state: any, {
|
|
36
|
-
meta: {
|
|
37
|
-
id,
|
|
38
|
-
},
|
|
39
|
-
}: {
|
|
40
|
-
meta: {
|
|
41
|
-
id: string;
|
|
42
|
-
};
|
|
43
|
-
}) => state.update(id, (current : any) => {
|
|
44
|
-
if (typeof current === "undefined") {
|
|
45
|
-
return current;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return current.mergeDeep(Immutable.Map({
|
|
49
|
-
fetching : false,
|
|
50
|
-
fetched : false,
|
|
51
|
-
error : true,
|
|
52
|
-
}));
|
|
53
|
-
}),
|
|
54
|
-
fetchItemDataFulFilled = (state: any, {
|
|
55
|
-
payload: {
|
|
56
|
-
Data,
|
|
57
|
-
},
|
|
58
|
-
meta: {
|
|
59
|
-
id,
|
|
60
|
-
},
|
|
61
|
-
}: FetchItemDataFulFilledProps) => state.update(id, (current : any) => {
|
|
62
|
-
if (typeof current === "undefined") {
|
|
63
|
-
return current;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return current.mergeDeep(Immutable.Map({
|
|
67
|
-
Data,
|
|
68
|
-
fetching : false,
|
|
69
|
-
fetched : true,
|
|
70
|
-
error : false,
|
|
71
|
-
}));
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
export { fetchItemDataPending, fetchItemDataRejected, fetchItemDataFulFilled };
|
package/src/reducerOperations.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as Immutable from "immutable";
|
|
2
|
-
import { Action } from "redux";
|
|
3
|
-
import { PagesState, RequestPageAction, ReceivePageAction, ChangeViewAction, ItemsState } from "./types";
|
|
4
|
-
|
|
5
|
-
const requestPage = (state: PagesState, action: RequestPageAction) => {
|
|
6
|
-
const
|
|
7
|
-
{ payload: { token, page } } = action,
|
|
8
|
-
// it is the type any because ts apparently has a problem
|
|
9
|
-
elements : any = Immutable.Map({
|
|
10
|
-
page,
|
|
11
|
-
error : false,
|
|
12
|
-
fetching : true,
|
|
13
|
-
fetched : false,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
if (state.has(token)) {
|
|
17
|
-
return state.update(token, (current : any) => current.merge(elements));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const init = elements.merge({
|
|
21
|
-
view : 1,
|
|
22
|
-
token,
|
|
23
|
-
ids : Immutable.List(),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
return state.set(token, init);
|
|
27
|
-
},
|
|
28
|
-
receivePage = (state: PagesState, action: ReceivePageAction) => {
|
|
29
|
-
const {
|
|
30
|
-
meta: {
|
|
31
|
-
idKey,
|
|
32
|
-
},
|
|
33
|
-
payload: {
|
|
34
|
-
token,
|
|
35
|
-
items,
|
|
36
|
-
total,
|
|
37
|
-
error,
|
|
38
|
-
},
|
|
39
|
-
} = action;
|
|
40
|
-
|
|
41
|
-
if (state.has(token)) {
|
|
42
|
-
const hasError = error === true;
|
|
43
|
-
|
|
44
|
-
return state.update(token, (
|
|
45
|
-
(current : any) => current.update((page : any) => current.merge(Immutable.Map({
|
|
46
|
-
ids : page.get("ids").concat(Immutable.List(items.map((item) => String(item[idKey])))),
|
|
47
|
-
fetching : false,
|
|
48
|
-
error : hasError,
|
|
49
|
-
fetched : true,
|
|
50
|
-
total : hasError ? page.get("total") : total,
|
|
51
|
-
})))
|
|
52
|
-
));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return state;
|
|
56
|
-
},
|
|
57
|
-
performChangeView = (state: PagesState, action: any, view: number) => {
|
|
58
|
-
const {
|
|
59
|
-
payload: {
|
|
60
|
-
token,
|
|
61
|
-
},
|
|
62
|
-
} = action,
|
|
63
|
-
item = state.get(token);
|
|
64
|
-
|
|
65
|
-
if (typeof item === "undefined") {
|
|
66
|
-
return state;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return state.update(token, (current : any) => current.set("view", view));
|
|
70
|
-
},
|
|
71
|
-
changeView = (state: PagesState, action: ChangeViewAction) => (
|
|
72
|
-
performChangeView(state, action, action.payload.view)
|
|
73
|
-
),
|
|
74
|
-
resetView = (state: PagesState, action: Action) => performChangeView(state, action, 1),
|
|
75
|
-
receivePageItems = (state: ItemsState, action: ReceivePageAction) => {
|
|
76
|
-
const
|
|
77
|
-
{ payload, meta } = action,
|
|
78
|
-
{ items: payloadItems } = payload,
|
|
79
|
-
{ idKey, manageEntity } = meta,
|
|
80
|
-
manage = typeof manageEntity === "function" ? manageEntity : (
|
|
81
|
-
(item : any) => Immutable.Map(item)
|
|
82
|
-
),
|
|
83
|
-
newItems = payloadItems.reduce(
|
|
84
|
-
(previous, item) => (
|
|
85
|
-
previous.set(String(item[idKey]), manage(item, state, idKey))
|
|
86
|
-
), Immutable.Map(),
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
return state.merge(newItems);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
export { requestPage, receivePage, performChangeView, changeView, resetView, receivePageItems };
|
package/src/reducers.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import * as Immutable from "immutable";
|
|
2
|
-
import { Action, PagesState, ItemsState } from "./types";
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
REQUEST_PAGE,
|
|
6
|
-
RECEIVE_PAGE,
|
|
7
|
-
RESET_VIEW,
|
|
8
|
-
CHANGE_VIEW,
|
|
9
|
-
CLEAR_DATA,
|
|
10
|
-
FETCH_CURRENT_COMPANY_INFO_PENDING,
|
|
11
|
-
FETCH_ITEM_DATA_PENDING,
|
|
12
|
-
FETCH_ITEM_DATA_REJECTED,
|
|
13
|
-
FETCH_ITEM_DATA_FULFILLED,
|
|
14
|
-
} from "./actionTypes";
|
|
15
|
-
|
|
16
|
-
import * as reducerItemData from "./reducerItemData";
|
|
17
|
-
import * as reducerOperations from "./reducerOperations";
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
export const
|
|
21
|
-
pages = (state: PagesState = Immutable.Map(), action: Action) => {
|
|
22
|
-
switch (action.type) {
|
|
23
|
-
case REQUEST_PAGE:
|
|
24
|
-
return reducerOperations.requestPage(state, action);
|
|
25
|
-
|
|
26
|
-
case RECEIVE_PAGE:
|
|
27
|
-
return reducerOperations.receivePage(state, action);
|
|
28
|
-
|
|
29
|
-
case RESET_VIEW:
|
|
30
|
-
return reducerOperations.resetView(state, action);
|
|
31
|
-
|
|
32
|
-
case CHANGE_VIEW:
|
|
33
|
-
return reducerOperations.changeView(state, action);
|
|
34
|
-
|
|
35
|
-
case FETCH_CURRENT_COMPANY_INFO_PENDING:
|
|
36
|
-
case CLEAR_DATA:
|
|
37
|
-
return state.clear();
|
|
38
|
-
|
|
39
|
-
default:
|
|
40
|
-
return state;
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
items = (state: ItemsState = Immutable.Map(), action: Action) => {
|
|
44
|
-
switch (action.type) {
|
|
45
|
-
case RECEIVE_PAGE:
|
|
46
|
-
return reducerOperations.receivePageItems(state, action);
|
|
47
|
-
|
|
48
|
-
case FETCH_CURRENT_COMPANY_INFO_PENDING:
|
|
49
|
-
case CLEAR_DATA:
|
|
50
|
-
return state.clear();
|
|
51
|
-
|
|
52
|
-
default:
|
|
53
|
-
return state;
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
dataItems = (state: ItemsState = Immutable.Map(), action: Action) => {
|
|
57
|
-
switch (action.type) {
|
|
58
|
-
case RECEIVE_PAGE:
|
|
59
|
-
return reducerOperations.receivePageItems(state, action);
|
|
60
|
-
|
|
61
|
-
case FETCH_ITEM_DATA_PENDING:
|
|
62
|
-
return reducerItemData.fetchItemDataPending(state, action);
|
|
63
|
-
|
|
64
|
-
case FETCH_ITEM_DATA_REJECTED:
|
|
65
|
-
return reducerItemData.fetchItemDataRejected(state, action);
|
|
66
|
-
|
|
67
|
-
case FETCH_ITEM_DATA_FULFILLED:
|
|
68
|
-
return reducerItemData.fetchItemDataFulFilled(state, action);
|
|
69
|
-
|
|
70
|
-
case FETCH_CURRENT_COMPANY_INFO_PENDING:
|
|
71
|
-
case CLEAR_DATA:
|
|
72
|
-
return state.clear();
|
|
73
|
-
|
|
74
|
-
default:
|
|
75
|
-
return state;
|
|
76
|
-
}
|
|
77
|
-
};
|