redux-paginator-immutable 17.0.4 → 17.0.18

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 (61) hide show
  1. package/lib/__tests__/createPaginator.spec.js +2 -2
  2. package/lib/__tests__/reducers.spec.js +2 -3
  3. package/lib/__tests__/selectors.spec.js +11 -13
  4. package/package.json +15 -8
  5. package/src/Info.tsx +29 -0
  6. package/src/LoadDataItem.tsx +84 -0
  7. package/src/{LoadPaginator.jsx → LoadPaginator.tsx} +77 -94
  8. package/src/LoadingButton.tsx +40 -0
  9. package/src/__tests__/createPaginator.spec.js +6 -6
  10. package/src/__tests__/reducers.spec.js +28 -28
  11. package/src/__tests__/selectors.spec.js +80 -81
  12. package/src/{actionTypes.js → actionTypes.ts} +0 -4
  13. package/src/actions.ts +157 -0
  14. package/src/agent.ts +62 -0
  15. package/src/createDataReducer.ts +98 -0
  16. package/src/{createItemReducer.js → createItemReducer.ts} +6 -12
  17. package/src/createPaginator.ts +107 -0
  18. package/src/{index.js → index.ts} +0 -13
  19. package/src/paginatorMiddleware.ts +93 -0
  20. package/src/reducerItemData.ts +74 -0
  21. package/src/reducerOperations.ts +101 -0
  22. package/src/{reducers.js → reducers.ts} +9 -18
  23. package/src/selectors.ts +113 -0
  24. package/src/types/{actions.js → actions.ts} +27 -39
  25. package/src/types/{index.js → index.ts} +3 -13
  26. package/src/types/{state.js → state.ts} +3 -6
  27. package/src/util.ts +51 -0
  28. package/src/{words.js → words.ts} +0 -2
  29. package/lib/Info.js +0 -37
  30. package/lib/LoadDataItem.js +0 -110
  31. package/lib/LoadPaginator.js +0 -216
  32. package/lib/LoadingButton.js +0 -75
  33. package/lib/actionTypes.js +0 -16
  34. package/lib/actions.js +0 -136
  35. package/lib/agent.js +0 -86
  36. package/lib/createDataReducer.js +0 -83
  37. package/lib/createItemReducer.js +0 -36
  38. package/lib/createPaginator.js +0 -141
  39. package/lib/index.js +0 -58
  40. package/lib/paginatorMiddleware.js +0 -102
  41. package/lib/reducerItemData.js +0 -63
  42. package/lib/reducerOperations.js +0 -114
  43. package/lib/reducers.js +0 -87
  44. package/lib/selectors.js +0 -129
  45. package/lib/types/actions.js +0 -1
  46. package/lib/types/index.js +0 -29
  47. package/lib/types/state.js +0 -1
  48. package/lib/util.js +0 -73
  49. package/lib/words.js +0 -15
  50. package/src/Info.jsx +0 -32
  51. package/src/LoadDataItem.jsx +0 -116
  52. package/src/LoadingButton.jsx +0 -55
  53. package/src/actions.js +0 -153
  54. package/src/agent.js +0 -55
  55. package/src/createDataReducer.js +0 -94
  56. package/src/createPaginator.js +0 -131
  57. package/src/paginatorMiddleware.js +0 -94
  58. package/src/reducerItemData.jsx +0 -64
  59. package/src/reducerOperations.jsx +0 -112
  60. package/src/selectors.js +0 -143
  61. package/src/util.js +0 -71
@@ -0,0 +1,93 @@
1
+ /* eslint-disable no-console, max-lines-per-function */
2
+ import type { Dispatch, Action } from "./types";
3
+ import { REQUEST_PAGE } from "./actionTypes";
4
+ import actions from "./actions";
5
+ import { fetchPage } from "./agent";
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;
@@ -0,0 +1,74 @@
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 };
@@ -0,0 +1,101 @@
1
+ import * as Immutable from "immutable";
2
+ import type {
3
+ ItemsState,
4
+ PagesState,
5
+ Action,
6
+ ReceivePageAction,
7
+ ChangeViewAction,
8
+ RequestPageAction,
9
+ } from "./types";
10
+
11
+ const requestPage = (state: PagesState, action: RequestPageAction) => {
12
+ const {
13
+ payload: {
14
+ token,
15
+ page,
16
+ },
17
+ } = action,
18
+ elements = Immutable.Map({
19
+ page,
20
+ error : false,
21
+ fetching : true,
22
+ fetched : false,
23
+ });
24
+
25
+ if (state.has(token)) {
26
+ return state.update(token, (current : any) => current.merge(elements));
27
+ }
28
+
29
+ const init = elements.merge({
30
+ view : 1,
31
+ token,
32
+ ids : Immutable.List(),
33
+ });
34
+
35
+ return state.set(token, init);
36
+ },
37
+ receivePage = (state: PagesState, action: ReceivePageAction) => {
38
+ const {
39
+ meta: {
40
+ idKey,
41
+ },
42
+ payload: {
43
+ token,
44
+ items,
45
+ total,
46
+ error,
47
+ },
48
+ } = action;
49
+
50
+ if (state.has(token)) {
51
+ const hasError = error === true;
52
+
53
+ return state.update(token, (
54
+ (current : any) => current.update((page : any) => current.merge(Immutable.Map({
55
+ ids : page.get("ids").concat(Immutable.List(items.map((item) => String(item[idKey])))),
56
+ fetching : false,
57
+ error : hasError,
58
+ fetched : true,
59
+ total : hasError ? page.get("total") : total,
60
+ })))
61
+ ));
62
+ }
63
+
64
+ return state;
65
+ },
66
+ performChangeView = (state: PagesState, action: any, view: number) => {
67
+ const {
68
+ payload: {
69
+ token,
70
+ },
71
+ } = action,
72
+ item = state.get(token);
73
+
74
+ if (typeof item === "undefined") {
75
+ return state;
76
+ }
77
+
78
+ return state.update(token, (current : any) => current.set("view", view));
79
+ },
80
+ changeView = (state: PagesState, action: ChangeViewAction) => (
81
+ performChangeView(state, action, action.payload.view)
82
+ ),
83
+ resetView = (state: PagesState, action: Action) => performChangeView(state, action, 1),
84
+ receivePageItems = (state: ItemsState, action: ReceivePageAction) => {
85
+ const
86
+ { payload, meta } = action,
87
+ { items: payloadItems } = payload,
88
+ { idKey, manageEntity } = meta,
89
+ manage = typeof manageEntity === "function" ? manageEntity : (
90
+ (item : any) => Immutable.Map(item)
91
+ ),
92
+ newItems = payloadItems.reduce(
93
+ (previous, item) => (
94
+ previous.set(String(item[idKey]), manage(item, state, idKey))
95
+ ), Immutable.Map(),
96
+ );
97
+
98
+ return state.merge(newItems);
99
+ };
100
+
101
+ export { requestPage, receivePage, performChangeView, changeView, resetView, receivePageItems };
@@ -1,12 +1,4 @@
1
- // @flow
2
-
3
- import type {
4
- ItemsState,
5
- PagesState,
6
-
7
- Action,
8
- } from "./types";
9
-
1
+ import * as Immutable from "immutable";
10
2
  import {
11
3
  REQUEST_PAGE,
12
4
  RECEIVE_PAGE,
@@ -14,18 +6,15 @@ import {
14
6
  CHANGE_VIEW,
15
7
  CLEAR_DATA,
16
8
  FETCH_CURRENT_COMPANY_INFO_PENDING,
17
-
18
9
  FETCH_ITEM_DATA_PENDING,
19
10
  FETCH_ITEM_DATA_REJECTED,
20
11
  FETCH_ITEM_DATA_FULFILLED,
21
12
  } from "./actionTypes";
22
-
23
- import * as Immutable from "immutable";
24
-
13
+ import type { ItemsState, PagesState, Action } from "./types";
25
14
  import * as reducerItemData from "./reducerItemData";
26
15
  import * as reducerOperations from "./reducerOperations";
27
16
 
28
- export const pages = (state : PagesState = Immutable.Map(), action : Action) => {
17
+ export const pages = (state: PagesState = Immutable.Map(), action: Action) => {
29
18
  switch (action.type) {
30
19
  case REQUEST_PAGE:
31
20
  return reducerOperations.requestPage(state, action);
@@ -47,8 +36,7 @@ export const pages = (state : PagesState = Immutable.Map(), action : Action) =>
47
36
  return state;
48
37
  }
49
38
  };
50
-
51
- export const items = (state : ItemsState = Immutable.Map(), action : Action) => {
39
+ export const items = (state: ItemsState = Immutable.Map(), action: Action) => {
52
40
  switch (action.type) {
53
41
  case RECEIVE_PAGE:
54
42
  return reducerOperations.receivePageItems(state, action);
@@ -56,26 +44,29 @@ export const items = (state : ItemsState = Immutable.Map(), action : Action) =>
56
44
  case FETCH_CURRENT_COMPANY_INFO_PENDING:
57
45
  case CLEAR_DATA:
58
46
  return state.clear();
47
+
59
48
  default:
60
49
  return state;
61
50
  }
62
51
  };
63
-
64
- export const dataItems = (state : ItemsState = Immutable.Map(), action : Action) => {
52
+ export const dataItems = (state: ItemsState = Immutable.Map(), action: Action) => {
65
53
  switch (action.type) {
66
54
  case RECEIVE_PAGE:
67
55
  return reducerOperations.receivePageItems(state, action);
68
56
 
69
57
  case FETCH_ITEM_DATA_PENDING:
70
58
  return reducerItemData.fetchItemDataPending(state, action);
59
+
71
60
  case FETCH_ITEM_DATA_REJECTED:
72
61
  return reducerItemData.fetchItemDataRejected(state, action);
62
+
73
63
  case FETCH_ITEM_DATA_FULFILLED:
74
64
  return reducerItemData.fetchItemDataFulFilled(state, action);
75
65
 
76
66
  case FETCH_CURRENT_COMPANY_INFO_PENDING:
77
67
  case CLEAR_DATA:
78
68
  return state.clear();
69
+
79
70
  default:
80
71
  return state;
81
72
  }
@@ -0,0 +1,113 @@
1
+ import * as Immutable from "immutable";
2
+ import { createSelector } from "reselect";
3
+ import type { State, PagesState } from "./types";
4
+
5
+ const
6
+ pagesSelector = (state: State) => state,
7
+
8
+ rowsPerPage = 50,
9
+ pageSelector = createSelector(
10
+ pagesSelector,
11
+ (_state: State, token: string) => token,
12
+ (pages: PagesState, token: string) => pages.get(token),
13
+ ),
14
+ getAllResults = createSelector(
15
+ pageSelector,
16
+ (_state : State, _token : string, items : any) => items,
17
+ (page : any, items : any) => {
18
+ if (typeof page === "undefined") {
19
+ return Immutable.List();
20
+ }
21
+
22
+ return page.get("ids").map((id : number) => items.get(String(id)));
23
+ },
24
+ ),
25
+ getResultsUpToPage = createSelector(
26
+ pageSelector,
27
+ (_state : State, _token : string, items : any) => items,
28
+ (_state : State, _token : string, _items: any, target: any) => target,
29
+ (_state : State, _token : string, _items : any, _target : any, perPage : number) => (
30
+ perPage || rowsPerPage
31
+ ),
32
+ (page : any, items : any, target : any, perPage : any) => {
33
+ if (typeof page === "undefined") {
34
+ return Immutable.List();
35
+ }
36
+
37
+ const ids = page.get("ids").slice(0, perPage * target);
38
+
39
+ return ids.map((id : number) => items.get(String(id)));
40
+ }),
41
+ getCurrentTotalResultsCount = createSelector(
42
+ pageSelector,
43
+ (page : any) => {
44
+ if (typeof page === "undefined") {
45
+ return 0;
46
+ }
47
+
48
+ return page.get("total");
49
+ }),
50
+ isPageFetching = createSelector(
51
+ pageSelector,
52
+ (_state : State, _token : string, target : any) => target,
53
+ (page : any, target : any) => {
54
+ if (typeof page === "undefined") {
55
+ return false;
56
+ }
57
+
58
+ return page.get("fetching") && target === page.get("page");
59
+ }),
60
+ isPageFetched = createSelector(
61
+ pageSelector,
62
+ (_state : State, _token : string, target : any) => target,
63
+ (page : any, target : any) => {
64
+ if (typeof page === "undefined") {
65
+ return false;
66
+ }
67
+
68
+ return page.get("fetched") && target <= page.get("page");
69
+ }),
70
+ hasPageProblems = createSelector(
71
+ pageSelector,
72
+ (page : any) => {
73
+ if (typeof page === "undefined") {
74
+ return false;
75
+ }
76
+
77
+ return page.get("error");
78
+ }),
79
+ getCurrentView = createSelector(
80
+ pageSelector,
81
+ (page : any) => {
82
+ if (typeof page === "undefined") {
83
+ return 1;
84
+ }
85
+
86
+ return page.get("view");
87
+ }),
88
+
89
+ // these selectors are used for the entire app
90
+ getPaginatorPaginations = (state: any, name: string) => state.getIn(["paginations", name]),
91
+ getPaginatorEntities = (state: any, name: string) => state.getIn(["entities", name]),
92
+ getPaginators = createSelector(
93
+ getPaginatorPaginations,
94
+ getPaginatorEntities,
95
+ (list : any, entities : any) => ({
96
+ list,
97
+ entities,
98
+ }),
99
+ );
100
+
101
+ export default {
102
+ getAllResults,
103
+ getCurrentTotalResultsCount,
104
+ getResultsUpToPage,
105
+ isPageFetching,
106
+ isPageFetched,
107
+ hasPageProblems,
108
+ getCurrentView,
109
+ // for state
110
+ getPaginatorPaginations,
111
+ getPaginatorEntities,
112
+ getPaginators,
113
+ };
@@ -1,10 +1,8 @@
1
- // @flow
2
-
3
1
  import type { EndPointCb } from "./index";
4
2
 
5
3
  export type RequestPageAction = {
6
- type : "@@redux-paginator-immutable/REQUEST_PAGE";
7
- meta : {
4
+ type: "@@redux-paginator-immutable/REQUEST_PAGE";
5
+ meta: {
8
6
  endpoint: string;
9
7
  endpointCb: EndPointCb;
10
8
  manageEntity: any;
@@ -18,10 +16,9 @@ export type RequestPageAction = {
18
16
  token: string;
19
17
  };
20
18
  };
21
-
22
19
  export type ReceivePageAction = {
23
- type : "@@redux-paginator-immutable/RECEIVE_PAGE";
24
- meta : {
20
+ type: "@@redux-paginator-immutable/RECEIVE_PAGE";
21
+ meta: {
25
22
  endpoint: string;
26
23
  endpointCb: EndPointCb;
27
24
  manageEntity: any;
@@ -33,14 +30,13 @@ export type ReceivePageAction = {
33
30
  token: string;
34
31
  items: Array<any>;
35
32
  total: number;
36
- error: bool;
33
+ error: boolean;
37
34
  raw?: string;
38
35
  };
39
36
  };
40
-
41
37
  export type ChangeViewAction = {
42
- type : "@@redux-paginator-immutable/CHANGE_VIEW";
43
- meta : {
38
+ type: "@@redux-paginator-immutable/CHANGE_VIEW";
39
+ meta: {
44
40
  endpoint: string;
45
41
  };
46
42
  payload: {
@@ -48,44 +44,38 @@ export type ChangeViewAction = {
48
44
  token: string;
49
45
  };
50
46
  };
51
-
52
47
  export type ResetViewAction = {
53
- type : "@@redux-paginator-immutable/RESET_VIEW";
54
- meta : {
48
+ type: "@@redux-paginator-immutable/RESET_VIEW";
49
+ meta: {
55
50
  endpoint: string;
56
51
  };
57
52
  payload: {
58
53
  token: string;
59
54
  };
60
55
  };
61
-
62
56
  export type ClearDataAction = {
63
- type : "@@redux-paginator-immutable/CLEAR_DATA";
64
- meta : {
57
+ type: "@@redux-paginator-immutable/CLEAR_DATA";
58
+ meta: {
65
59
  endpoint: string;
66
60
  };
67
61
  };
68
-
69
62
  export type FetchCurrentCompanyInfoPending = {
70
- type : "FETCH_CURRENT_COMPANY_INFO_PENDING";
63
+ type: "FETCH_CURRENT_COMPANY_INFO_PENDING";
71
64
  };
72
-
73
65
  export type FetchItemDataPending = {
74
- type : "@@redux-paginator-immutable/FETCH_ITEM_DATA_PENDING";
66
+ type: "@@redux-paginator-immutable/FETCH_ITEM_DATA_PENDING";
75
67
  meta: {
76
68
  id: string;
77
- }
69
+ };
78
70
  };
79
-
80
71
  export type FetchItemDataRejected = {
81
- type : "@@redux-paginator-immutable/FETCH_ITEM_DATA_REJECTED";
72
+ type: "@@redux-paginator-immutable/FETCH_ITEM_DATA_REJECTED";
82
73
  meta: {
83
74
  id: string;
84
- }
75
+ };
85
76
  };
86
-
87
77
  export type FetchItemDataFulFilled = {
88
- type : "@@redux-paginator-immutable/FETCH_ITEM_DATA_FULFILLED";
78
+ type: "@@redux-paginator-immutable/FETCH_ITEM_DATA_FULFILLED";
89
79
  payload: {
90
80
  Data: any;
91
81
  };
@@ -93,15 +83,13 @@ export type FetchItemDataFulFilled = {
93
83
  id: string;
94
84
  };
95
85
  };
96
-
97
- export type Action = RequestPageAction
98
- | ReceivePageAction
99
- | ResetViewAction
100
- | ChangeViewAction
101
- | ClearDataAction
102
-
103
- | FetchCurrentCompanyInfoPending
104
-
105
- |FetchItemDataPending
106
- |FetchItemDataRejected
107
- |FetchItemDataFulFilled;
86
+ export type Action =
87
+ RequestPageAction |
88
+ ReceivePageAction |
89
+ ResetViewAction |
90
+ ChangeViewAction |
91
+ ClearDataAction |
92
+ FetchCurrentCompanyInfoPending |
93
+ FetchItemDataPending |
94
+ FetchItemDataRejected |
95
+ FetchItemDataFulFilled;
@@ -1,9 +1,6 @@
1
- // @flow
2
1
  /* eslint-disable no-use-before-define */
3
-
4
2
  export * from "./actions";
5
3
  export * from "./state";
6
-
7
4
  import type { State } from "./state";
8
5
  import type { Action } from "./actions";
9
6
 
@@ -11,28 +8,21 @@ export type GetState = () => State;
11
8
  export type PromiseAction = Promise<Action>;
12
9
  export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
13
10
  export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any;
14
-
15
- export type EndPointCb = ((token? : string) => string) | null;
16
-
11
+ export type EndPointCb = ((token?: string) => string) | null;
17
12
  export type PaginatorSettings = {
18
13
  key: string;
19
14
  manageEntity: any;
20
15
  resultsKey: string;
21
16
  dataItemURL: string;
22
17
  normalizeDataItem: any;
23
-
24
18
  // by default "{rowsPerLoad} from x25/utility/others"
25
19
  rowsPerLoad?: number;
26
-
27
20
  // by default "(items) => items"
28
21
  manipulateItems?: (items: any) => any;
29
-
30
22
  // by default "Total"
31
23
  totalKey?: string;
32
-
33
- // by default "page"
24
+ // by default "page"
34
25
  pageArgName?: string;
35
-
36
26
  // default "ID"
37
27
  idKey?: string;
38
- }
28
+ };
@@ -1,9 +1,6 @@
1
- // @flow
2
-
3
1
  export type PagesState = any;
4
2
  export type ItemsState = any;
5
-
6
3
  export type State = {
7
- +pages: PagesState;
8
- +itemsReducer: ItemsState;
9
- }
4
+ readonly pages: PagesState;
5
+ readonly itemsReducer: ItemsState;
6
+ };
package/src/util.ts ADDED
@@ -0,0 +1,51 @@
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 };
@@ -1,5 +1,3 @@
1
- // @flow
2
-
3
1
  const words = {
4
2
  ThereWasAProblem : "There was a problem. Try again",
5
3
  Showing : "Showing",