redux-paginator-immutable 17.0.50 → 17.1.0
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/Info.d.ts → Info.d.ts} +0 -0
- package/{lib/Info.js → Info.js} +0 -0
- package/{lib/Info.js.map → Info.js.map} +0 -0
- package/{lib/LoadDataItem.d.ts → LoadDataItem.d.ts} +0 -0
- package/{lib/LoadDataItem.js → LoadDataItem.js} +0 -0
- package/{lib/LoadDataItem.js.map → LoadDataItem.js.map} +0 -0
- package/{lib/LoadPaginator.d.ts → LoadPaginator.d.ts} +0 -0
- package/{lib/LoadPaginator.js → LoadPaginator.js} +0 -0
- package/{lib/LoadPaginator.js.map → LoadPaginator.js.map} +0 -0
- package/{lib/LoadPaginatorTypes.d.ts → LoadPaginatorTypes.d.ts} +0 -0
- package/{lib/LoadPaginatorTypes.js → LoadPaginatorTypes.js} +0 -0
- package/{lib/LoadPaginatorTypes.js.map → LoadPaginatorTypes.js.map} +0 -0
- package/{lib/LoadingButton.d.ts → LoadingButton.d.ts} +0 -0
- package/{lib/LoadingButton.js → LoadingButton.js} +0 -0
- package/{lib/LoadingButton.js.map → LoadingButton.js.map} +0 -0
- package/{lib/actionTypes.d.ts → actionTypes.d.ts} +0 -0
- package/{lib/actionTypes.js → actionTypes.js} +0 -0
- package/{lib/actionTypes.js.map → actionTypes.js.map} +0 -0
- package/{lib/actions.d.ts → actions.d.ts} +0 -0
- package/{lib/actions.js → actions.js} +0 -0
- package/{lib/actions.js.map → actions.js.map} +0 -0
- package/{lib/agent.d.ts → agent.d.ts} +0 -0
- package/{lib/agent.js → agent.js} +0 -0
- package/{lib/agent.js.map → agent.js.map} +0 -0
- package/{lib/createDataReducer.d.ts → createDataReducer.d.ts} +0 -0
- package/{lib/createDataReducer.js → createDataReducer.js} +0 -0
- package/{lib/createDataReducer.js.map → createDataReducer.js.map} +0 -0
- package/{lib/createItemReducer.d.ts → createItemReducer.d.ts} +0 -0
- package/{lib/createItemReducer.js → createItemReducer.js} +0 -0
- package/{lib/createItemReducer.js.map → createItemReducer.js.map} +0 -0
- package/{lib/createPaginator.d.ts → createPaginator.d.ts} +0 -0
- package/{lib/createPaginator.js → createPaginator.js} +0 -0
- package/{lib/createPaginator.js.map → createPaginator.js.map} +0 -0
- package/{lib/index.d.ts → index.d.ts} +0 -0
- package/{lib/index.js → index.js} +0 -0
- package/{lib/index.js.map → index.js.map} +0 -0
- package/package.json +122 -112
- package/{lib/paginatorMiddleware.d.ts → paginatorMiddleware.d.ts} +0 -0
- package/{lib/paginatorMiddleware.js → paginatorMiddleware.js} +0 -0
- package/{lib/paginatorMiddleware.js.map → paginatorMiddleware.js.map} +0 -0
- package/{lib/reducerItemData.d.ts → reducerItemData.d.ts} +0 -0
- package/{lib/reducerItemData.js → reducerItemData.js} +0 -0
- package/{lib/reducerItemData.js.map → reducerItemData.js.map} +0 -0
- package/{lib/reducerOperations.d.ts → reducerOperations.d.ts} +0 -0
- package/{lib/reducerOperations.js → reducerOperations.js} +0 -0
- package/{lib/reducerOperations.js.map → reducerOperations.js.map} +0 -0
- package/{lib/reducers.d.ts → reducers.d.ts} +0 -0
- package/{lib/reducers.js → reducers.js} +0 -0
- package/{lib/reducers.js.map → reducers.js.map} +0 -0
- package/{lib/selectors.d.ts → selectors.d.ts} +0 -0
- package/{lib/selectors.js → selectors.js} +0 -0
- package/{lib/selectors.js.map → selectors.js.map} +0 -0
- package/style.css +0 -0
- package/{lib/types.d.ts → types.d.ts} +0 -0
- package/{lib/types.js → types.js} +0 -0
- package/{lib/types.js.map → types.js.map} +0 -0
- package/{lib/util.d.ts → util.d.ts} +0 -0
- package/{lib/util.js → util.js} +0 -0
- package/{lib/util.js.map → util.js.map} +0 -0
- package/README.md +0 -3
- 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/actions.ts
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import agent from "superagent";
|
|
3
|
-
import { EndPointCb, Action } from "./types";
|
|
4
|
-
|
|
5
|
-
type RequestPageArgsTypes = {
|
|
6
|
-
endpoint: string;
|
|
7
|
-
endpointCb: EndPointCb;
|
|
8
|
-
manageEntity: any;
|
|
9
|
-
resultsKey: string;
|
|
10
|
-
totalKey: string;
|
|
11
|
-
pageArgName: string;
|
|
12
|
-
idKey: string;
|
|
13
|
-
page: number;
|
|
14
|
-
token: string;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
type ReceivePageArgsTypes = {
|
|
18
|
-
endpoint: string;
|
|
19
|
-
endpointCb: EndPointCb;
|
|
20
|
-
manageEntity: any;
|
|
21
|
-
pageArgName: string;
|
|
22
|
-
idKey: string;
|
|
23
|
-
page: number;
|
|
24
|
-
token: string;
|
|
25
|
-
items: Array<any>;
|
|
26
|
-
total: number;
|
|
27
|
-
error: boolean;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const requestPage = ({
|
|
31
|
-
endpoint,
|
|
32
|
-
endpointCb,
|
|
33
|
-
manageEntity,
|
|
34
|
-
resultsKey,
|
|
35
|
-
totalKey,
|
|
36
|
-
pageArgName,
|
|
37
|
-
idKey,
|
|
38
|
-
page,
|
|
39
|
-
token,
|
|
40
|
-
}: RequestPageArgsTypes): Action => ({
|
|
41
|
-
type : "@@redux-paginator-immutable/REQUEST_PAGE",
|
|
42
|
-
meta : {
|
|
43
|
-
endpoint,
|
|
44
|
-
endpointCb,
|
|
45
|
-
manageEntity,
|
|
46
|
-
resultsKey,
|
|
47
|
-
totalKey,
|
|
48
|
-
pageArgName,
|
|
49
|
-
idKey,
|
|
50
|
-
},
|
|
51
|
-
payload: {
|
|
52
|
-
page,
|
|
53
|
-
token,
|
|
54
|
-
},
|
|
55
|
-
}),
|
|
56
|
-
|
|
57
|
-
receivePage = ({
|
|
58
|
-
endpoint,
|
|
59
|
-
endpointCb,
|
|
60
|
-
manageEntity,
|
|
61
|
-
pageArgName,
|
|
62
|
-
idKey,
|
|
63
|
-
page,
|
|
64
|
-
token,
|
|
65
|
-
items,
|
|
66
|
-
error,
|
|
67
|
-
total,
|
|
68
|
-
}: ReceivePageArgsTypes): Action => ({
|
|
69
|
-
type : "@@redux-paginator-immutable/RECEIVE_PAGE",
|
|
70
|
-
meta : {
|
|
71
|
-
endpoint,
|
|
72
|
-
endpointCb,
|
|
73
|
-
manageEntity,
|
|
74
|
-
pageArgName,
|
|
75
|
-
idKey,
|
|
76
|
-
},
|
|
77
|
-
payload: {
|
|
78
|
-
page,
|
|
79
|
-
token,
|
|
80
|
-
items,
|
|
81
|
-
error,
|
|
82
|
-
total,
|
|
83
|
-
},
|
|
84
|
-
}),
|
|
85
|
-
|
|
86
|
-
resetView = (endpoint: string, token: string): Action => ({
|
|
87
|
-
type : "@@redux-paginator-immutable/RESET_VIEW",
|
|
88
|
-
meta : {
|
|
89
|
-
endpoint,
|
|
90
|
-
},
|
|
91
|
-
payload: {
|
|
92
|
-
token,
|
|
93
|
-
},
|
|
94
|
-
}),
|
|
95
|
-
|
|
96
|
-
changeView = (endpoint: string, {
|
|
97
|
-
token,
|
|
98
|
-
view,
|
|
99
|
-
}: {
|
|
100
|
-
token: string;
|
|
101
|
-
view: number;
|
|
102
|
-
}): Action => ({
|
|
103
|
-
type : "@@redux-paginator-immutable/CHANGE_VIEW",
|
|
104
|
-
meta : {
|
|
105
|
-
endpoint,
|
|
106
|
-
},
|
|
107
|
-
payload: {
|
|
108
|
-
token,
|
|
109
|
-
view,
|
|
110
|
-
},
|
|
111
|
-
}),
|
|
112
|
-
|
|
113
|
-
clearData = (endpoint: string): Action => ({
|
|
114
|
-
type : "@@redux-paginator-immutable/CLEAR_DATA",
|
|
115
|
-
meta : {
|
|
116
|
-
endpoint,
|
|
117
|
-
},
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
// data info
|
|
121
|
-
type FetchDataItem = {
|
|
122
|
-
dataItemURL: string;
|
|
123
|
-
endpoint: string;
|
|
124
|
-
normalizeDataItem: any;
|
|
125
|
-
id: string;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
const fetchDataItemRequest = ({
|
|
129
|
-
dataItemURL,
|
|
130
|
-
normalizeDataItem,
|
|
131
|
-
id,
|
|
132
|
-
}: FetchDataItem): Promise<any> => (
|
|
133
|
-
new Promise((resolve, reject) => (
|
|
134
|
-
agent.
|
|
135
|
-
get(`${dataItemURL}/${id}`).
|
|
136
|
-
set("Accept", "application/json").
|
|
137
|
-
end(normalizeDataItem(resolve, reject))
|
|
138
|
-
)) as Promise<any>
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
export const fetchItem = (things: FetchDataItem): any => ({
|
|
142
|
-
type : "@@redux-paginator-immutable/FETCH_ITEM_DATA",
|
|
143
|
-
payload : fetchDataItemRequest(things),
|
|
144
|
-
meta : {
|
|
145
|
-
id : things.id,
|
|
146
|
-
endpoint : things.endpoint,
|
|
147
|
-
},
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
export default {
|
|
151
|
-
clearData,
|
|
152
|
-
requestPage,
|
|
153
|
-
receivePage,
|
|
154
|
-
resetView,
|
|
155
|
-
changeView,
|
|
156
|
-
};
|
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 };
|