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.
Files changed (85) hide show
  1. package/{lib/Info.d.ts → Info.d.ts} +0 -0
  2. package/{lib/Info.js → Info.js} +0 -0
  3. package/{lib/Info.js.map → Info.js.map} +0 -0
  4. package/{lib/LoadDataItem.d.ts → LoadDataItem.d.ts} +0 -0
  5. package/{lib/LoadDataItem.js → LoadDataItem.js} +0 -0
  6. package/{lib/LoadDataItem.js.map → LoadDataItem.js.map} +0 -0
  7. package/{lib/LoadPaginator.d.ts → LoadPaginator.d.ts} +0 -0
  8. package/{lib/LoadPaginator.js → LoadPaginator.js} +0 -0
  9. package/{lib/LoadPaginator.js.map → LoadPaginator.js.map} +0 -0
  10. package/{lib/LoadPaginatorTypes.d.ts → LoadPaginatorTypes.d.ts} +0 -0
  11. package/{lib/LoadPaginatorTypes.js → LoadPaginatorTypes.js} +0 -0
  12. package/{lib/LoadPaginatorTypes.js.map → LoadPaginatorTypes.js.map} +0 -0
  13. package/{lib/LoadingButton.d.ts → LoadingButton.d.ts} +0 -0
  14. package/{lib/LoadingButton.js → LoadingButton.js} +0 -0
  15. package/{lib/LoadingButton.js.map → LoadingButton.js.map} +0 -0
  16. package/{lib/actionTypes.d.ts → actionTypes.d.ts} +0 -0
  17. package/{lib/actionTypes.js → actionTypes.js} +0 -0
  18. package/{lib/actionTypes.js.map → actionTypes.js.map} +0 -0
  19. package/{lib/actions.d.ts → actions.d.ts} +0 -0
  20. package/{lib/actions.js → actions.js} +0 -0
  21. package/{lib/actions.js.map → actions.js.map} +0 -0
  22. package/{lib/agent.d.ts → agent.d.ts} +0 -0
  23. package/{lib/agent.js → agent.js} +0 -0
  24. package/{lib/agent.js.map → agent.js.map} +0 -0
  25. package/{lib/createDataReducer.d.ts → createDataReducer.d.ts} +0 -0
  26. package/{lib/createDataReducer.js → createDataReducer.js} +0 -0
  27. package/{lib/createDataReducer.js.map → createDataReducer.js.map} +0 -0
  28. package/{lib/createItemReducer.d.ts → createItemReducer.d.ts} +0 -0
  29. package/{lib/createItemReducer.js → createItemReducer.js} +0 -0
  30. package/{lib/createItemReducer.js.map → createItemReducer.js.map} +0 -0
  31. package/{lib/createPaginator.d.ts → createPaginator.d.ts} +0 -0
  32. package/{lib/createPaginator.js → createPaginator.js} +0 -0
  33. package/{lib/createPaginator.js.map → createPaginator.js.map} +0 -0
  34. package/{lib/index.d.ts → index.d.ts} +0 -0
  35. package/{lib/index.js → index.js} +0 -0
  36. package/{lib/index.js.map → index.js.map} +0 -0
  37. package/package.json +122 -112
  38. package/{lib/paginatorMiddleware.d.ts → paginatorMiddleware.d.ts} +0 -0
  39. package/{lib/paginatorMiddleware.js → paginatorMiddleware.js} +0 -0
  40. package/{lib/paginatorMiddleware.js.map → paginatorMiddleware.js.map} +0 -0
  41. package/{lib/reducerItemData.d.ts → reducerItemData.d.ts} +0 -0
  42. package/{lib/reducerItemData.js → reducerItemData.js} +0 -0
  43. package/{lib/reducerItemData.js.map → reducerItemData.js.map} +0 -0
  44. package/{lib/reducerOperations.d.ts → reducerOperations.d.ts} +0 -0
  45. package/{lib/reducerOperations.js → reducerOperations.js} +0 -0
  46. package/{lib/reducerOperations.js.map → reducerOperations.js.map} +0 -0
  47. package/{lib/reducers.d.ts → reducers.d.ts} +0 -0
  48. package/{lib/reducers.js → reducers.js} +0 -0
  49. package/{lib/reducers.js.map → reducers.js.map} +0 -0
  50. package/{lib/selectors.d.ts → selectors.d.ts} +0 -0
  51. package/{lib/selectors.js → selectors.js} +0 -0
  52. package/{lib/selectors.js.map → selectors.js.map} +0 -0
  53. package/style.css +0 -0
  54. package/{lib/types.d.ts → types.d.ts} +0 -0
  55. package/{lib/types.js → types.js} +0 -0
  56. package/{lib/types.js.map → types.js.map} +0 -0
  57. package/{lib/util.d.ts → util.d.ts} +0 -0
  58. package/{lib/util.js → util.js} +0 -0
  59. package/{lib/util.js.map → util.js.map} +0 -0
  60. package/README.md +0 -3
  61. package/src/Info.tsx +0 -28
  62. package/src/LoadDataItem.tsx +0 -84
  63. package/src/LoadPaginator.tsx +0 -104
  64. package/src/LoadPaginatorTypes.ts +0 -31
  65. package/src/LoadingButton.tsx +0 -44
  66. package/src/__tests__/actions.spec.js +0 -130
  67. package/src/__tests__/agent.spec.js +0 -32
  68. package/src/__tests__/createPaginator.spec.js +0 -39
  69. package/src/__tests__/reducers.spec.js +0 -131
  70. package/src/__tests__/selectors.spec.js +0 -180
  71. package/src/__tests__/setup.js +0 -1
  72. package/src/actionTypes.ts +0 -9
  73. package/src/actions.ts +0 -156
  74. package/src/agent.ts +0 -62
  75. package/src/createDataReducer.ts +0 -90
  76. package/src/createItemReducer.ts +0 -29
  77. package/src/createPaginator.ts +0 -104
  78. package/src/index.ts +0 -26
  79. package/src/paginatorMiddleware.ts +0 -93
  80. package/src/reducerItemData.ts +0 -74
  81. package/src/reducerOperations.ts +0 -92
  82. package/src/reducers.ts +0 -77
  83. package/src/selectors.ts +0 -111
  84. package/src/types.ts +0 -130
  85. package/src/util.ts +0 -51
@@ -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
- };
package/src/selectors.ts DELETED
@@ -1,111 +0,0 @@
1
- import * as Immutable from "immutable";
2
- import { createSelector } from "reselect";
3
- import { State, PagesState } from "./types";
4
-
5
- const
6
- pagesSelector = (state: State) => state,
7
- pageSelector = createSelector(
8
- pagesSelector,
9
- (_state: State, token: string) => token,
10
- (pages: PagesState, token: string) => pages.get(token),
11
- ),
12
- getAllResults = createSelector(
13
- pageSelector,
14
- (_state : State, _token : string, items : any) => items,
15
- (page : any, items : any) => {
16
- if (typeof page === "undefined") {
17
- return Immutable.List();
18
- }
19
-
20
- return page.get("ids").map((id : number) => items.get(String(id)));
21
- },
22
- ),
23
- getResultsUpToPage = createSelector(
24
- pageSelector,
25
- (_state : State, _token : string, items : any) => items,
26
- (_state : State, _token : string, _items: any, target: any) => target,
27
- (_state : State, _token : string, _items : any, _target : any, perPage : number) => (
28
- perPage
29
- ),
30
- (page : any, items : any, target : any, perPage : any) => {
31
- if (typeof page === "undefined") {
32
- return Immutable.List();
33
- }
34
-
35
- const ids = page.get("ids").slice(0, perPage * target);
36
-
37
- return ids.map((id : number) => items.get(String(id)));
38
- }),
39
- getCurrentTotalResultsCount = createSelector(
40
- pageSelector,
41
- (page : any) => {
42
- if (typeof page === "undefined") {
43
- return 0;
44
- }
45
-
46
- return page.get("total");
47
- }),
48
- isPageFetching = createSelector(
49
- pageSelector,
50
- (_state : State, _token : string, target : any) => target,
51
- (page : any, target : any) => {
52
- if (typeof page === "undefined") {
53
- return false;
54
- }
55
-
56
- return page.get("fetching") && target === page.get("page");
57
- }),
58
- isPageFetched = createSelector(
59
- pageSelector,
60
- (_state : State, _token : string, target : any) => target,
61
- (page : any, target : any) => {
62
- if (typeof page === "undefined") {
63
- return false;
64
- }
65
-
66
- return page.get("fetched") && target <= page.get("page");
67
- }),
68
- hasPageProblems = createSelector(
69
- pageSelector,
70
- (page : any) => {
71
- if (typeof page === "undefined") {
72
- return false;
73
- }
74
-
75
- return page.get("error");
76
- }),
77
- getCurrentView = createSelector(
78
- pageSelector,
79
- (page : any) => {
80
- if (typeof page === "undefined") {
81
- return 1;
82
- }
83
-
84
- return page.get("view");
85
- }),
86
-
87
- // these selectors are used for the entire app
88
- getPaginatorPaginations = (state: any, name: string) => state.getIn(["paginations", name]),
89
- getPaginatorEntities = (state: any, name: string) => state.getIn(["entities", name]),
90
- getPaginators = createSelector(
91
- getPaginatorPaginations,
92
- getPaginatorEntities,
93
- (list : any, entities : any) => ({
94
- list,
95
- entities,
96
- }),
97
- );
98
-
99
- export default {
100
- getAllResults,
101
- getCurrentTotalResultsCount,
102
- getResultsUpToPage,
103
- isPageFetching,
104
- isPageFetched,
105
- hasPageProblems,
106
- getCurrentView,
107
- // for state
108
- getPaginatorPaginations,
109
- getPaginatorEntities,
110
- getPaginators,
111
- };
package/src/types.ts DELETED
@@ -1,130 +0,0 @@
1
- export type PagesState = any;
2
- export type ItemsState = any;
3
- export type State = {
4
- readonly pages: PagesState;
5
- readonly itemsReducer: ItemsState;
6
- };
7
-
8
-
9
- export type GetState = () => State;
10
- export type PromiseAction = Promise<Action>;
11
- export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
12
- export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any;
13
- export type EndPointCb = ((token?: string) => string) | null;
14
-
15
-
16
- export type PaginatorSettings = {
17
- key: string;
18
- manageEntity: any;
19
- resultsKey: string;
20
- // by default 25 per page
21
- rowsPerLoad?: number;
22
- // by default "(items) => items"
23
- manipulateItems?: (items: any) => any;
24
- // by default "Total"
25
- totalKey?: string;
26
- // by default "page"
27
- pageArgName?: string;
28
- // default "ID"
29
- idKey?: string;
30
-
31
- dataItemURL?: string;
32
- normalizeDataItem?: any;
33
- };
34
-
35
-
36
- // actions
37
-
38
- export type RequestPageAction = {
39
- type: "@@redux-paginator-immutable/REQUEST_PAGE";
40
- meta: {
41
- endpoint: string;
42
- endpointCb: EndPointCb;
43
- manageEntity: any;
44
- resultsKey: string;
45
- totalKey: string;
46
- pageArgName: string;
47
- idKey: string;
48
- };
49
- payload: {
50
- page: number;
51
- token: string;
52
- };
53
- };
54
- export type ReceivePageAction = {
55
- type: "@@redux-paginator-immutable/RECEIVE_PAGE";
56
- meta: {
57
- endpoint: string;
58
- endpointCb: EndPointCb;
59
- manageEntity: any;
60
- pageArgName: string;
61
- idKey: string;
62
- };
63
- payload: {
64
- page: number;
65
- token: string;
66
- items: Array<any>;
67
- total: number;
68
- error: boolean;
69
- raw?: string;
70
- };
71
- };
72
- export type ChangeViewAction = {
73
- type: "@@redux-paginator-immutable/CHANGE_VIEW";
74
- meta: {
75
- endpoint: string;
76
- };
77
- payload: {
78
- view: number;
79
- token: string;
80
- };
81
- };
82
- export type ResetViewAction = {
83
- type: "@@redux-paginator-immutable/RESET_VIEW";
84
- meta: {
85
- endpoint: string;
86
- };
87
- payload: {
88
- token: string;
89
- };
90
- };
91
- export type ClearDataAction = {
92
- type: "@@redux-paginator-immutable/CLEAR_DATA";
93
- meta: {
94
- endpoint: string;
95
- };
96
- };
97
- export type FetchCurrentCompanyInfoPending = {
98
- type: "FETCH_CURRENT_COMPANY_INFO_PENDING";
99
- };
100
- export type FetchItemDataPending = {
101
- type: "@@redux-paginator-immutable/FETCH_ITEM_DATA_PENDING";
102
- meta: {
103
- id: string;
104
- };
105
- };
106
- export type FetchItemDataRejected = {
107
- type: "@@redux-paginator-immutable/FETCH_ITEM_DATA_REJECTED";
108
- meta: {
109
- id: string;
110
- };
111
- };
112
- export type FetchItemDataFulFilled = {
113
- type: "@@redux-paginator-immutable/FETCH_ITEM_DATA_FULFILLED";
114
- payload: {
115
- Data: any;
116
- };
117
- meta: {
118
- id: string;
119
- };
120
- };
121
- export type Action =
122
- RequestPageAction |
123
- ReceivePageAction |
124
- ResetViewAction |
125
- ChangeViewAction |
126
- ClearDataAction |
127
- FetchCurrentCompanyInfoPending |
128
- FetchItemDataPending |
129
- FetchItemDataRejected |
130
- FetchItemDataFulFilled;
package/src/util.ts DELETED
@@ -1,51 +0,0 @@
1
- /* eslint-disable no-duplicate-imports */
2
- type NormalizrEntity = (data: any) => any;
3
-
4
- import type { Map as ImmutableMap } from "immutable";
5
- import * as Immutable from "immutable";
6
- import { createSelector } from "reselect";
7
-
8
- type ManageDataEntity = ImmutableMap<string, any>;
9
-
10
- // simple item
11
- const
12
- manageEntity = (normalizrEntity: NormalizrEntity) => (
13
- (item: any, state: any, keyID: string): ManageDataEntity => {
14
- // prevent rewrite
15
- const old = state.get(String(item[keyID]));
16
-
17
- if (typeof old === "undefined") {
18
- return Immutable.Map(normalizrEntity(item));
19
- }
20
-
21
- return old;
22
- }
23
- ),
24
- manipulateItems = (sortKey = "ID") => createSelector(
25
- (data : any) => data,
26
- (data : any) => data.sortBy((current : any) => -current.get(sortKey)),
27
- ),
28
-
29
- // data item
30
- manageDataEntity = (normalizrEntity: NormalizrEntity) => (
31
- (item: any, state: any, keyID: string): ManageDataEntity => {
32
- // prevent rewrite
33
- const old = state.get(String(item[keyID]));
34
-
35
- if (typeof old === "undefined") {
36
- return Immutable.Map({
37
- Data: normalizrEntity(item),
38
- });
39
- }
40
-
41
- return old;
42
- }
43
- ),
44
- manipulateDataItems = (sortKey = "ID") => (
45
- createSelector(
46
- (data : any) => data,
47
- (data : any) => data.sortBy((current : any) => -current.getIn(["Data", sortKey])),
48
- )
49
- );
50
-
51
- export { manageDataEntity, manipulateDataItems, manipulateItems, manageEntity };