@ngdux/list 1.4.0 → 3.0.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/{esm2020 → esm2022}/index.mjs +11 -11
- package/{esm2020 → esm2022}/lib/+state/effects.mjs +23 -23
- package/esm2022/lib/+state/state.service.mjs +55 -0
- package/esm2022/lib/models/list.model.mjs +7 -0
- package/{esm2020 → esm2022}/lib/ngdux-list-state.module.mjs +53 -53
- package/{esm2020 → esm2022}/lib/services/list-notification-service.mjs +21 -21
- package/esm2022/lib/state-generator/abstract-list-effects.mjs +50 -0
- package/esm2022/lib/state-generator/abstract-list-state.service.mjs +44 -0
- package/{esm2020 → esm2022}/lib/state-generator/abstract-list.facade.mjs +85 -91
- package/{esm2020 → esm2022}/lib/state-generator/list-actions.mjs +58 -63
- package/esm2022/lib/state-generator/list-reducer.mjs +104 -0
- package/esm2022/lib/state-generator/list-selectors.mjs +80 -0
- package/{esm2020 → esm2022}/lib/state-generator/list-state.mjs +17 -17
- package/{esm2020 → esm2022}/ngdux-list.mjs +4 -4
- package/{fesm2020 → fesm2022}/ngdux-list.mjs +523 -550
- package/fesm2022/ngdux-list.mjs.map +1 -0
- package/index.d.ts +11 -11
- package/lib/+state/effects.d.ts +14 -14
- package/lib/+state/state.service.d.ts +22 -22
- package/lib/models/list.model.d.ts +191 -195
- package/lib/ngdux-list-state.module.d.ts +23 -23
- package/lib/services/list-notification-service.d.ts +13 -13
- package/lib/state-generator/abstract-list-effects.d.ts +49 -59
- package/lib/state-generator/abstract-list-state.service.d.ts +21 -21
- package/lib/state-generator/abstract-list.facade.d.ts +45 -49
- package/lib/state-generator/list-actions.d.ts +2 -2
- package/lib/state-generator/list-reducer.d.ts +10 -10
- package/lib/state-generator/list-selectors.d.ts +4 -4
- package/lib/state-generator/list-state.d.ts +12 -12
- package/package.json +11 -120
- package/esm2020/lib/+state/state.service.mjs +0 -55
- package/esm2020/lib/models/list.model.mjs +0 -7
- package/esm2020/lib/state-generator/abstract-list-effects.mjs +0 -66
- package/esm2020/lib/state-generator/abstract-list-state.service.mjs +0 -44
- package/esm2020/lib/state-generator/list-reducer.mjs +0 -104
- package/esm2020/lib/state-generator/list-selectors.mjs +0 -80
- package/fesm2015/ngdux-list.mjs +0 -537
- package/fesm2015/ngdux-list.mjs.map +0 -1
- package/fesm2020/ngdux-list.mjs.map +0 -1
|
@@ -13,577 +13,550 @@ import { __decorate, __param, __metadata } from 'tslib';
|
|
|
13
13
|
import { of } from 'rxjs';
|
|
14
14
|
import { map, withLatestFrom, filter, switchMap, catchError, exhaustMap, tap } from 'rxjs/operators';
|
|
15
15
|
|
|
16
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
17
|
-
const LIST_FEATURE_KEY = new InjectionToken('LIST_FEATURE_KEY');
|
|
18
|
-
const LIST_FEATURE_KEYS = new InjectionToken('LIST_FEATURE_KEYS');
|
|
19
|
-
const LIST_SERVICES = new InjectionToken('LIST_SERVICES');
|
|
16
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
17
|
+
const LIST_FEATURE_KEY = new InjectionToken('LIST_FEATURE_KEY');
|
|
18
|
+
const LIST_FEATURE_KEYS = new InjectionToken('LIST_FEATURE_KEYS');
|
|
19
|
+
const LIST_SERVICES = new InjectionToken('LIST_SERVICES');
|
|
20
20
|
const LIST_NOTIFICATION_SERVICES = new InjectionToken('LIST_NOTIFICATION_SERVICES');
|
|
21
21
|
|
|
22
|
-
function createListActions(featureName) {
|
|
23
|
-
const resetRequestState = createAction(`[${featureName} API] Reset ${featureName} Request State`);
|
|
24
|
-
const initialize = createAction(`[${featureName} API] Initialize ${featureName}`);
|
|
25
|
-
const reset = createAction(`[Organization ${featureName} API] Reset ${featureName}`);
|
|
26
|
-
const loadNextPage = createAction(`[${featureName} API] Load Next ${featureName} Page`);
|
|
27
|
-
const loadPreviousPage = createAction(`[${featureName} API] Load Previous ${featureName} Page`);
|
|
28
|
-
const loadFirstPage = createAction(`[${featureName} API] Load First ${featureName} Page`);
|
|
29
|
-
const setPageSize = createAction(`[${featureName} API] Set ${featureName} Page Size`, props());
|
|
30
|
-
const setSorting = createAction(`[${featureName} API] Set ${featureName} Sorting`, props());
|
|
31
|
-
const setFiltering = createAction(`[${featureName} API] Set ${featureName} Filtering`, props());
|
|
32
|
-
const setRequestParams = createAction(`[${featureName} API] Set ${featureName} Request Params`, props());
|
|
33
|
-
const changePageSize = createAction(`[${featureName} API] Change ${featureName} Page Size`, props());
|
|
34
|
-
const changePageNumber = createAction(`[${featureName} API] Change ${featureName} Page Number`, props());
|
|
35
|
-
const changePagingOptions = createAction(`[${featureName} API] Change ${featureName} Page Options`, props());
|
|
36
|
-
const changeSorting = createAction(`[${featureName} API] Change ${featureName} Sorting`, props());
|
|
37
|
-
const changeFiltering = createAction(`[${featureName} API] Change ${featureName} Filtering`, props());
|
|
38
|
-
const changeSelectedResources = createAction(`[${featureName} API] Change Selected Resources ${featureName}`, props());
|
|
39
|
-
const changeRequestParams = createAction(`[${featureName} API] Change ${featureName} Request Params`, props());
|
|
40
|
-
const loadPage = createAction(`[${featureName} API] Load ${featureName} Page`);
|
|
41
|
-
const loadPageSuccess = createAction(`[${featureName} API] Load ${featureName} Page Success`, props());
|
|
42
|
-
const loadPageFailure = createAction(`[${featureName} API] Load ${featureName} Page Failure`, props());
|
|
43
|
-
const deleteAction = createAction(`[${featureName} API] Delete ${featureName}`, props());
|
|
44
|
-
const deleteSuccess = createAction(`[${featureName} API] Delete ${featureName} Success`, props());
|
|
45
|
-
const deleteFailure = createAction(`[${featureName} API] Delete ${featureName} Failure`, props());
|
|
46
|
-
const patch = createAction(`[${featureName} API] Patch ${featureName}`, props());
|
|
47
|
-
const patchSuccess = createAction(`[${featureName} API] Patch ${featureName} Success`, props());
|
|
48
|
-
const patchFailure = createAction(`[${featureName} API] Patch ${featureName} Failure`, props());
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
patchSuccess,
|
|
78
|
-
patchFailure,
|
|
79
|
-
resetRequestState,
|
|
80
|
-
showRemovalsConfirmation
|
|
81
|
-
};
|
|
22
|
+
function createListActions(featureName) {
|
|
23
|
+
const resetRequestState = createAction(`[${featureName} API] Reset ${featureName} Request State`);
|
|
24
|
+
const initialize = createAction(`[${featureName} API] Initialize ${featureName}`);
|
|
25
|
+
const reset = createAction(`[Organization ${featureName} API] Reset ${featureName}`);
|
|
26
|
+
const loadNextPage = createAction(`[${featureName} API] Load Next ${featureName} Page`);
|
|
27
|
+
const loadPreviousPage = createAction(`[${featureName} API] Load Previous ${featureName} Page`);
|
|
28
|
+
const loadFirstPage = createAction(`[${featureName} API] Load First ${featureName} Page`);
|
|
29
|
+
const setPageSize = createAction(`[${featureName} API] Set ${featureName} Page Size`, props());
|
|
30
|
+
const setSorting = createAction(`[${featureName} API] Set ${featureName} Sorting`, props());
|
|
31
|
+
const setFiltering = createAction(`[${featureName} API] Set ${featureName} Filtering`, props());
|
|
32
|
+
const setRequestParams = createAction(`[${featureName} API] Set ${featureName} Request Params`, props());
|
|
33
|
+
const changePageSize = createAction(`[${featureName} API] Change ${featureName} Page Size`, props());
|
|
34
|
+
const changePageNumber = createAction(`[${featureName} API] Change ${featureName} Page Number`, props());
|
|
35
|
+
const changePagingOptions = createAction(`[${featureName} API] Change ${featureName} Page Options`, props());
|
|
36
|
+
const changeSorting = createAction(`[${featureName} API] Change ${featureName} Sorting`, props());
|
|
37
|
+
const changeFiltering = createAction(`[${featureName} API] Change ${featureName} Filtering`, props());
|
|
38
|
+
const changeSelectedResources = createAction(`[${featureName} API] Change Selected Resources ${featureName}`, props());
|
|
39
|
+
const changeRequestParams = createAction(`[${featureName} API] Change ${featureName} Request Params`, props());
|
|
40
|
+
const loadPage = createAction(`[${featureName} API] Load ${featureName} Page`);
|
|
41
|
+
const loadPageSuccess = createAction(`[${featureName} API] Load ${featureName} Page Success`, props());
|
|
42
|
+
const loadPageFailure = createAction(`[${featureName} API] Load ${featureName} Page Failure`, props());
|
|
43
|
+
const deleteAction = createAction(`[${featureName} API] Delete ${featureName}`, props());
|
|
44
|
+
const deleteSuccess = createAction(`[${featureName} API] Delete ${featureName} Success`, props());
|
|
45
|
+
const deleteFailure = createAction(`[${featureName} API] Delete ${featureName} Failure`, props());
|
|
46
|
+
const patch = createAction(`[${featureName} API] Patch ${featureName}`, props());
|
|
47
|
+
const patchSuccess = createAction(`[${featureName} API] Patch ${featureName} Success`, props());
|
|
48
|
+
const patchFailure = createAction(`[${featureName} API] Patch ${featureName} Failure`, props());
|
|
49
|
+
return {
|
|
50
|
+
initialize,
|
|
51
|
+
reset,
|
|
52
|
+
setPageSize,
|
|
53
|
+
setSorting,
|
|
54
|
+
setFiltering,
|
|
55
|
+
setRequestParams,
|
|
56
|
+
changePageSize,
|
|
57
|
+
changePageNumber,
|
|
58
|
+
changePagingOptions,
|
|
59
|
+
changeSorting,
|
|
60
|
+
changeFiltering,
|
|
61
|
+
changeRequestParams,
|
|
62
|
+
loadPreviousPage,
|
|
63
|
+
loadNextPage,
|
|
64
|
+
loadFirstPage,
|
|
65
|
+
changeSelectedResources,
|
|
66
|
+
loadPage,
|
|
67
|
+
loadPageSuccess,
|
|
68
|
+
loadPageFailure,
|
|
69
|
+
delete: deleteAction,
|
|
70
|
+
deleteSuccess,
|
|
71
|
+
deleteFailure,
|
|
72
|
+
patch,
|
|
73
|
+
patchSuccess,
|
|
74
|
+
patchFailure,
|
|
75
|
+
resetRequestState
|
|
76
|
+
};
|
|
82
77
|
}
|
|
83
78
|
|
|
84
|
-
function createListEntityAdapter(idKey = 'id') {
|
|
85
|
-
return createEntityAdapter({
|
|
86
|
-
selectId: resource => resource[idKey]
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function createListReducer(entityAdapter, actions, actionHandlers, initialListState) {
|
|
90
|
-
const initialState = {
|
|
91
|
-
...createInitialListState(entityAdapter),
|
|
92
|
-
...initialListState
|
|
93
|
-
};
|
|
94
|
-
return createReducer(initialState, ...createListActionHandlers(initialState, entityAdapter, actions), ...(actionHandlers || []));
|
|
95
|
-
}
|
|
96
|
-
function createInitialListState(entityAdapter) {
|
|
97
|
-
return entityAdapter.getInitialState({
|
|
98
|
-
...getDefaultRequestOptions(),
|
|
99
|
-
lastPageNumber: undefined,
|
|
100
|
-
selectedResourceIds: [],
|
|
101
|
-
loadingState: RequestState.IDLE,
|
|
102
|
-
requestState: RequestState.IDLE,
|
|
103
|
-
errors: undefined
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
function createListActionHandlers(initialListState, entityAdapter, actions) {
|
|
107
|
-
return [
|
|
108
|
-
on(actions.reset, () => initialListState),
|
|
109
|
-
on(actions.initialize, (state) => entityAdapter.removeAll({
|
|
110
|
-
...state,
|
|
111
|
-
selectedResourceIds: [],
|
|
112
|
-
pagingOptions: {
|
|
113
|
-
...state.pagingOptions,
|
|
114
|
-
page: DEFAULT_PAGE
|
|
115
|
-
},
|
|
116
|
-
requestState: RequestState.IDLE
|
|
117
|
-
})),
|
|
118
|
-
on(actions.changePageSize, actions.setPageSize, (state, { pageSize }) => ({
|
|
119
|
-
...state,
|
|
120
|
-
pagingOptions: { page: DEFAULT_PAGE, pageSize },
|
|
121
|
-
lastPageNumber: undefined
|
|
122
|
-
})),
|
|
123
|
-
on(actions.changePageNumber, (state, { pageNumber }) => ({
|
|
124
|
-
...state,
|
|
125
|
-
pagingOptions: { ...state.pagingOptions, page: pageNumber }
|
|
126
|
-
})),
|
|
127
|
-
on(actions.changePagingOptions, (state, { pagingOptions }) => ({
|
|
128
|
-
...state,
|
|
129
|
-
pagingOptions
|
|
130
|
-
})),
|
|
131
|
-
on(actions.changeSorting, actions.setSorting, (state, { sortingOptions }) => ({
|
|
132
|
-
...state,
|
|
133
|
-
sortingOptions,
|
|
134
|
-
pagingOptions: { ...state.pagingOptions, page: DEFAULT_PAGE }
|
|
135
|
-
})),
|
|
136
|
-
on(actions.changeFiltering, actions.setFiltering, (state, { filteringOptions }) => ({
|
|
137
|
-
...state,
|
|
138
|
-
filteringOptions,
|
|
139
|
-
pagingOptions: { ...state.pagingOptions, page: DEFAULT_PAGE },
|
|
140
|
-
lastPageNumber: undefined
|
|
141
|
-
})),
|
|
142
|
-
on(actions.changeRequestParams, actions.setRequestParams, (state, { params }) => ({
|
|
143
|
-
...state,
|
|
144
|
-
requestParameters: params,
|
|
145
|
-
pagingOptions: { ...state.pagingOptions, page: DEFAULT_PAGE }
|
|
146
|
-
})),
|
|
147
|
-
on(actions.changeSelectedResources, (state, { selectedResourceIds }) => ({
|
|
148
|
-
...state,
|
|
149
|
-
selectedResourceIds
|
|
150
|
-
})),
|
|
151
|
-
on(actions.loadFirstPage, (state) => ({
|
|
152
|
-
...state,
|
|
153
|
-
pagingOptions: { ...state.pagingOptions, page: 1 }
|
|
154
|
-
})),
|
|
155
|
-
on(actions.loadPageSuccess, (state, { resources, pagingOptions }) => {
|
|
156
|
-
const lastPageNumber = getLastPageNumber(resources, pagingOptions) || state.lastPageNumber;
|
|
157
|
-
if (lastPageNumber && pagingOptions.page > lastPageNumber) {
|
|
158
|
-
return {
|
|
159
|
-
...state,
|
|
160
|
-
pagingOptions: {
|
|
161
|
-
...state.pagingOptions,
|
|
162
|
-
page: lastPageNumber
|
|
163
|
-
},
|
|
164
|
-
lastPageNumber,
|
|
165
|
-
selectedResourceIds: []
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
return entityAdapter.setAll(resources, {
|
|
169
|
-
...state,
|
|
170
|
-
lastPageNumber,
|
|
171
|
-
selectedResourceIds: []
|
|
172
|
-
});
|
|
173
|
-
}),
|
|
174
|
-
on(actions.deleteSuccess, (state) => ({
|
|
175
|
-
...state,
|
|
176
|
-
selectedResourceIds: []
|
|
177
|
-
})),
|
|
178
|
-
...createLoadingStateActionHandlers(actions.loadPage, actions.loadPageSuccess, actions.loadPageFailure),
|
|
179
|
-
...createRequestStateActionHandlers(undefined, actions.delete, actions.deleteSuccess, actions.deleteFailure),
|
|
180
|
-
...createRequestStateActionHandlers(actions.resetRequestState, actions.patch, actions.patchSuccess, actions.patchFailure)
|
|
181
|
-
];
|
|
79
|
+
function createListEntityAdapter(idKey = 'id') {
|
|
80
|
+
return createEntityAdapter({
|
|
81
|
+
selectId: resource => resource[idKey]
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function createListReducer(entityAdapter, actions, actionHandlers, initialListState) {
|
|
85
|
+
const initialState = {
|
|
86
|
+
...createInitialListState(entityAdapter),
|
|
87
|
+
...initialListState
|
|
88
|
+
};
|
|
89
|
+
return createReducer(initialState, ...createListActionHandlers(initialState, entityAdapter, actions), ...(actionHandlers || []));
|
|
90
|
+
}
|
|
91
|
+
function createInitialListState(entityAdapter) {
|
|
92
|
+
return entityAdapter.getInitialState({
|
|
93
|
+
...getDefaultRequestOptions(),
|
|
94
|
+
lastPageNumber: undefined,
|
|
95
|
+
selectedResourceIds: [],
|
|
96
|
+
loadingState: RequestState.IDLE,
|
|
97
|
+
requestState: RequestState.IDLE,
|
|
98
|
+
errors: undefined
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function createListActionHandlers(initialListState, entityAdapter, actions) {
|
|
102
|
+
return [
|
|
103
|
+
on(actions.reset, () => initialListState),
|
|
104
|
+
on(actions.initialize, (state) => entityAdapter.removeAll({
|
|
105
|
+
...state,
|
|
106
|
+
selectedResourceIds: [],
|
|
107
|
+
pagingOptions: {
|
|
108
|
+
...state.pagingOptions,
|
|
109
|
+
page: DEFAULT_PAGE
|
|
110
|
+
},
|
|
111
|
+
requestState: RequestState.IDLE
|
|
112
|
+
})),
|
|
113
|
+
on(actions.changePageSize, actions.setPageSize, (state, { pageSize }) => ({
|
|
114
|
+
...state,
|
|
115
|
+
pagingOptions: { page: DEFAULT_PAGE, pageSize },
|
|
116
|
+
lastPageNumber: undefined
|
|
117
|
+
})),
|
|
118
|
+
on(actions.changePageNumber, (state, { pageNumber }) => ({
|
|
119
|
+
...state,
|
|
120
|
+
pagingOptions: { ...state.pagingOptions, page: pageNumber }
|
|
121
|
+
})),
|
|
122
|
+
on(actions.changePagingOptions, (state, { pagingOptions }) => ({
|
|
123
|
+
...state,
|
|
124
|
+
pagingOptions
|
|
125
|
+
})),
|
|
126
|
+
on(actions.changeSorting, actions.setSorting, (state, { sortingOptions }) => ({
|
|
127
|
+
...state,
|
|
128
|
+
sortingOptions,
|
|
129
|
+
pagingOptions: { ...state.pagingOptions, page: DEFAULT_PAGE }
|
|
130
|
+
})),
|
|
131
|
+
on(actions.changeFiltering, actions.setFiltering, (state, { filteringOptions }) => ({
|
|
132
|
+
...state,
|
|
133
|
+
filteringOptions,
|
|
134
|
+
pagingOptions: { ...state.pagingOptions, page: DEFAULT_PAGE },
|
|
135
|
+
lastPageNumber: undefined
|
|
136
|
+
})),
|
|
137
|
+
on(actions.changeRequestParams, actions.setRequestParams, (state, { params }) => ({
|
|
138
|
+
...state,
|
|
139
|
+
requestParameters: params,
|
|
140
|
+
pagingOptions: { ...state.pagingOptions, page: DEFAULT_PAGE }
|
|
141
|
+
})),
|
|
142
|
+
on(actions.changeSelectedResources, (state, { selectedResourceIds }) => ({
|
|
143
|
+
...state,
|
|
144
|
+
selectedResourceIds
|
|
145
|
+
})),
|
|
146
|
+
on(actions.loadFirstPage, (state) => ({
|
|
147
|
+
...state,
|
|
148
|
+
pagingOptions: { ...state.pagingOptions, page: 1 }
|
|
149
|
+
})),
|
|
150
|
+
on(actions.loadPageSuccess, (state, { resources, pagingOptions }) => {
|
|
151
|
+
const lastPageNumber = getLastPageNumber(resources, pagingOptions) || state.lastPageNumber;
|
|
152
|
+
if (lastPageNumber && pagingOptions.page > lastPageNumber) {
|
|
153
|
+
return {
|
|
154
|
+
...state,
|
|
155
|
+
pagingOptions: {
|
|
156
|
+
...state.pagingOptions,
|
|
157
|
+
page: lastPageNumber
|
|
158
|
+
},
|
|
159
|
+
lastPageNumber,
|
|
160
|
+
selectedResourceIds: []
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
return entityAdapter.setAll(resources, {
|
|
164
|
+
...state,
|
|
165
|
+
lastPageNumber,
|
|
166
|
+
selectedResourceIds: []
|
|
167
|
+
});
|
|
168
|
+
}),
|
|
169
|
+
on(actions.deleteSuccess, (state) => ({
|
|
170
|
+
...state,
|
|
171
|
+
selectedResourceIds: []
|
|
172
|
+
})),
|
|
173
|
+
...createLoadingStateActionHandlers(actions.loadPage, actions.loadPageSuccess, actions.loadPageFailure),
|
|
174
|
+
...createRequestStateActionHandlers(undefined, actions.delete, actions.deleteSuccess, actions.deleteFailure),
|
|
175
|
+
...createRequestStateActionHandlers(actions.resetRequestState, actions.patch, actions.patchSuccess, actions.patchFailure)
|
|
176
|
+
];
|
|
182
177
|
}
|
|
183
178
|
|
|
184
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
185
|
-
function createListSelectors(entityAdapter, getListState) {
|
|
186
|
-
const getAll = createSelector(getListState, entityAdapter.getSelectors().selectAll);
|
|
187
|
-
const getPagingOptions = createSelector(getListState, state => state.pagingOptions);
|
|
188
|
-
const getRequestOptions = createSelector(getListState, (state) => ({
|
|
189
|
-
pagingOptions: state.pagingOptions,
|
|
190
|
-
sortingOptions: state.sortingOptions,
|
|
191
|
-
filteringOptions: state.filteringOptions
|
|
192
|
-
}));
|
|
193
|
-
const getLastPageNumber = createSelector(getListState, state => state.lastPageNumber);
|
|
194
|
-
const isLastPage = createSelector(getPagingOptions, getLastPageNumber, ({ page }, lastPageNumber) => {
|
|
195
|
-
return lastPageNumber ? lastPageNumber <= page : false;
|
|
196
|
-
});
|
|
197
|
-
const getCurrentPageData = createSelector(getAll, resources => {
|
|
198
|
-
return resources;
|
|
199
|
-
});
|
|
200
|
-
const getSortingOptions = createSelector(getListState, state => state.sortingOptions);
|
|
201
|
-
const getRequestParameters = createSelector(getListState, state => state.requestParameters);
|
|
202
|
-
const getFilteringOptions = createSelector(getListState, state => state.filteringOptions);
|
|
203
|
-
const getCurrentPageNumber = createSelector(getPagingOptions, options => options?.page);
|
|
204
|
-
const getSelectedResourceIds = createSelector(getListState, state => state.selectedResourceIds);
|
|
205
|
-
const getLoadingState = createSelector(getListState, state => state.loadingState);
|
|
206
|
-
const getSelectedItems = createSelector(getSelectedResourceIds, createSelector(getListState, entityAdapter.getSelectors().selectEntities), (selectedResourceIds, resources) => selectedResourceIds.reduce((acc, selectedResourceId) => {
|
|
207
|
-
const resource = resources[selectedResourceId];
|
|
208
|
-
if (resource) {
|
|
209
|
-
acc.push(resource);
|
|
210
|
-
}
|
|
211
|
-
return acc;
|
|
212
|
-
}, []));
|
|
213
|
-
const getSelectionRecord = createSelector(getSelectedResourceIds, createSelector(getListState, entityAdapter.getSelectors().selectEntities), (selectedResourceIds, resources) => selectedResourceIds.reduce((selected, selectedResourceId) => {
|
|
214
|
-
const resource = resources[selectedResourceId];
|
|
215
|
-
if (resource) {
|
|
216
|
-
selected[selectedResourceId] = resource;
|
|
217
|
-
}
|
|
218
|
-
return selected;
|
|
219
|
-
}, {}));
|
|
220
|
-
const getRequestState = createSelector(getListState, state => state.requestState);
|
|
221
|
-
const getErrors = createSelector(getListState, state => state.errors);
|
|
222
|
-
const isReady = createSelector(getAll, getLoadingState, (users, loadingState) => !!users && loadingState === RequestState.SUCCESS);
|
|
223
|
-
const areSelectedReady = createSelector(getSelectedResourceIds, getSelectionRecord, getLoadingState, (selectedResourceIds, resources, loadingState) => {
|
|
224
|
-
return selectedResourceIds.every(resourceId => !!resources[resourceId]) && loadingState === RequestState.SUCCESS;
|
|
225
|
-
});
|
|
226
|
-
const isDeleteDisabled = createSelector(getSelectedResourceIds, selectedResourceIds => !selectedResourceIds.length);
|
|
227
|
-
const isCopyDisabled = createSelector(getSelectedResourceIds, selectedResourceIds => selectedResourceIds.length !== 1);
|
|
228
|
-
const getTotalCount = createSelector(getPagingOptions, isLastPage, getCurrentPageData, (pagingOptions, isLastPage, currentPageData) => {
|
|
229
|
-
if (!pagingOptions) {
|
|
230
|
-
return 0;
|
|
231
|
-
}
|
|
232
|
-
if (isLastPage) {
|
|
233
|
-
return (pagingOptions.page - 1) * pagingOptions.pageSize + currentPageData.length;
|
|
234
|
-
}
|
|
235
|
-
return (pagingOptions.page + 1) * pagingOptions.pageSize;
|
|
236
|
-
});
|
|
237
|
-
return {
|
|
238
|
-
getAll,
|
|
239
|
-
getRequestOptions,
|
|
240
|
-
isLastPage,
|
|
241
|
-
getCurrentPageData,
|
|
242
|
-
getPagingOptions,
|
|
243
|
-
getSortingOptions,
|
|
244
|
-
getFilteringOptions,
|
|
245
|
-
getRequestParameters,
|
|
246
|
-
getCurrentPageNumber,
|
|
247
|
-
getLastPageNumber,
|
|
248
|
-
getLoadingState,
|
|
249
|
-
getSelectedResourceIds,
|
|
250
|
-
getSelectedItems,
|
|
251
|
-
getSelectionRecord,
|
|
252
|
-
getRequestState,
|
|
253
|
-
getErrors,
|
|
254
|
-
areSelectedReady,
|
|
255
|
-
isReady,
|
|
256
|
-
isDeleteDisabled,
|
|
257
|
-
isCopyDisabled,
|
|
258
|
-
getTotalCount
|
|
259
|
-
};
|
|
179
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
180
|
+
function createListSelectors(entityAdapter, getListState) {
|
|
181
|
+
const getAll = createSelector(getListState, entityAdapter.getSelectors().selectAll);
|
|
182
|
+
const getPagingOptions = createSelector(getListState, state => state.pagingOptions);
|
|
183
|
+
const getRequestOptions = createSelector(getListState, (state) => ({
|
|
184
|
+
pagingOptions: state.pagingOptions,
|
|
185
|
+
sortingOptions: state.sortingOptions,
|
|
186
|
+
filteringOptions: state.filteringOptions
|
|
187
|
+
}));
|
|
188
|
+
const getLastPageNumber = createSelector(getListState, state => state.lastPageNumber);
|
|
189
|
+
const isLastPage = createSelector(getPagingOptions, getLastPageNumber, ({ page }, lastPageNumber) => {
|
|
190
|
+
return lastPageNumber ? lastPageNumber <= page : false;
|
|
191
|
+
});
|
|
192
|
+
const getCurrentPageData = createSelector(getAll, resources => {
|
|
193
|
+
return resources;
|
|
194
|
+
});
|
|
195
|
+
const getSortingOptions = createSelector(getListState, state => state.sortingOptions);
|
|
196
|
+
const getRequestParameters = createSelector(getListState, state => state.requestParameters);
|
|
197
|
+
const getFilteringOptions = createSelector(getListState, state => state.filteringOptions);
|
|
198
|
+
const getCurrentPageNumber = createSelector(getPagingOptions, options => options?.page);
|
|
199
|
+
const getSelectedResourceIds = createSelector(getListState, state => state.selectedResourceIds);
|
|
200
|
+
const getLoadingState = createSelector(getListState, state => state.loadingState);
|
|
201
|
+
const getSelectedItems = createSelector(getSelectedResourceIds, createSelector(getListState, entityAdapter.getSelectors().selectEntities), (selectedResourceIds, resources) => selectedResourceIds.reduce((acc, selectedResourceId) => {
|
|
202
|
+
const resource = resources[selectedResourceId];
|
|
203
|
+
if (resource) {
|
|
204
|
+
acc.push(resource);
|
|
205
|
+
}
|
|
206
|
+
return acc;
|
|
207
|
+
}, []));
|
|
208
|
+
const getSelectionRecord = createSelector(getSelectedResourceIds, createSelector(getListState, entityAdapter.getSelectors().selectEntities), (selectedResourceIds, resources) => selectedResourceIds.reduce((selected, selectedResourceId) => {
|
|
209
|
+
const resource = resources[selectedResourceId];
|
|
210
|
+
if (resource) {
|
|
211
|
+
selected[selectedResourceId] = resource;
|
|
212
|
+
}
|
|
213
|
+
return selected;
|
|
214
|
+
}, {}));
|
|
215
|
+
const getRequestState = createSelector(getListState, state => state.requestState);
|
|
216
|
+
const getErrors = createSelector(getListState, state => state.errors);
|
|
217
|
+
const isReady = createSelector(getAll, getLoadingState, (users, loadingState) => !!users && loadingState === RequestState.SUCCESS);
|
|
218
|
+
const areSelectedReady = createSelector(getSelectedResourceIds, getSelectionRecord, getLoadingState, (selectedResourceIds, resources, loadingState) => {
|
|
219
|
+
return selectedResourceIds.every(resourceId => !!resources[resourceId]) && loadingState === RequestState.SUCCESS;
|
|
220
|
+
});
|
|
221
|
+
const isDeleteDisabled = createSelector(getSelectedResourceIds, selectedResourceIds => !selectedResourceIds.length);
|
|
222
|
+
const isCopyDisabled = createSelector(getSelectedResourceIds, selectedResourceIds => selectedResourceIds.length !== 1);
|
|
223
|
+
const getTotalCount = createSelector(getPagingOptions, isLastPage, getCurrentPageData, (pagingOptions, isLastPage, currentPageData) => {
|
|
224
|
+
if (!pagingOptions) {
|
|
225
|
+
return 0;
|
|
226
|
+
}
|
|
227
|
+
if (isLastPage) {
|
|
228
|
+
return (pagingOptions.page - 1) * pagingOptions.pageSize + currentPageData.length;
|
|
229
|
+
}
|
|
230
|
+
return (pagingOptions.page + 1) * pagingOptions.pageSize;
|
|
231
|
+
});
|
|
232
|
+
return {
|
|
233
|
+
getAll,
|
|
234
|
+
getRequestOptions,
|
|
235
|
+
isLastPage,
|
|
236
|
+
getCurrentPageData,
|
|
237
|
+
getPagingOptions,
|
|
238
|
+
getSortingOptions,
|
|
239
|
+
getFilteringOptions,
|
|
240
|
+
getRequestParameters,
|
|
241
|
+
getCurrentPageNumber,
|
|
242
|
+
getLastPageNumber,
|
|
243
|
+
getLoadingState,
|
|
244
|
+
getSelectedResourceIds,
|
|
245
|
+
getSelectedItems,
|
|
246
|
+
getSelectionRecord,
|
|
247
|
+
getRequestState,
|
|
248
|
+
getErrors,
|
|
249
|
+
areSelectedReady,
|
|
250
|
+
isReady,
|
|
251
|
+
isDeleteDisabled,
|
|
252
|
+
isCopyDisabled,
|
|
253
|
+
getTotalCount
|
|
254
|
+
};
|
|
260
255
|
}
|
|
261
256
|
|
|
262
|
-
class ListStateService {
|
|
263
|
-
constructor(reducerManager, featureKeys) {
|
|
264
|
-
this.reducerManager = reducerManager;
|
|
265
|
-
this.actions = {};
|
|
266
|
-
this.selectors = {};
|
|
267
|
-
this.entityAdapter = this.getEntityAdapter();
|
|
268
|
-
featureKeys.forEach(featureKey => {
|
|
269
|
-
if (!this.actions[featureKey]) {
|
|
270
|
-
this.actions[featureKey] = this.getActions(featureKey);
|
|
271
|
-
this.addReducer(featureKey, this.actions[featureKey]);
|
|
272
|
-
this.selectors[featureKey] = this.getSelectors(featureKey);
|
|
273
|
-
}
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
getActions(featureKey) {
|
|
277
|
-
return createListActions(featureKey);
|
|
278
|
-
}
|
|
279
|
-
getEntityAdapter() {
|
|
280
|
-
return createListEntityAdapter();
|
|
281
|
-
}
|
|
282
|
-
addReducer(featureKey, actions) {
|
|
283
|
-
const currentReducers = Object.keys(this.reducerManager.currentReducers || {});
|
|
284
|
-
if (!currentReducers.includes(featureKey)) {
|
|
285
|
-
const reducer = createListReducer(this.entityAdapter, actions);
|
|
286
|
-
this.reducerManager.addReducer(featureKey, reducer);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
getSelectors(featureKey) {
|
|
290
|
-
const getState = createFeatureSelector(featureKey);
|
|
291
|
-
return createListSelectors(this.entityAdapter, getState);
|
|
292
|
-
}
|
|
293
|
-
getFeatureActions(featureKey) {
|
|
294
|
-
return this.actions[featureKey];
|
|
295
|
-
}
|
|
296
|
-
getFeatureSelectors(featureKey) {
|
|
297
|
-
return this.selectors[featureKey];
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
303
|
-
type: Injectable
|
|
304
|
-
}], ctorParameters:
|
|
305
|
-
type: Inject,
|
|
306
|
-
args: [LIST_FEATURE_KEYS]
|
|
307
|
-
}] }]
|
|
257
|
+
class ListStateService {
|
|
258
|
+
constructor(reducerManager, featureKeys) {
|
|
259
|
+
this.reducerManager = reducerManager;
|
|
260
|
+
this.actions = {};
|
|
261
|
+
this.selectors = {};
|
|
262
|
+
this.entityAdapter = this.getEntityAdapter();
|
|
263
|
+
featureKeys.forEach(featureKey => {
|
|
264
|
+
if (!this.actions[featureKey]) {
|
|
265
|
+
this.actions[featureKey] = this.getActions(featureKey);
|
|
266
|
+
this.addReducer(featureKey, this.actions[featureKey]);
|
|
267
|
+
this.selectors[featureKey] = this.getSelectors(featureKey);
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
getActions(featureKey) {
|
|
272
|
+
return createListActions(featureKey);
|
|
273
|
+
}
|
|
274
|
+
getEntityAdapter() {
|
|
275
|
+
return createListEntityAdapter();
|
|
276
|
+
}
|
|
277
|
+
addReducer(featureKey, actions) {
|
|
278
|
+
const currentReducers = Object.keys(this.reducerManager.currentReducers || {});
|
|
279
|
+
if (!currentReducers.includes(featureKey)) {
|
|
280
|
+
const reducer = createListReducer(this.entityAdapter, actions);
|
|
281
|
+
this.reducerManager.addReducer(featureKey, reducer);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
getSelectors(featureKey) {
|
|
285
|
+
const getState = createFeatureSelector(featureKey);
|
|
286
|
+
return createListSelectors(this.entityAdapter, getState);
|
|
287
|
+
}
|
|
288
|
+
getFeatureActions(featureKey) {
|
|
289
|
+
return this.actions[featureKey];
|
|
290
|
+
}
|
|
291
|
+
getFeatureSelectors(featureKey) {
|
|
292
|
+
return this.selectors[featureKey];
|
|
293
|
+
}
|
|
294
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: ListStateService, deps: [{ token: i1.ReducerManager }, { token: LIST_FEATURE_KEYS }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
295
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: ListStateService }); }
|
|
296
|
+
}
|
|
297
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: ListStateService, decorators: [{
|
|
298
|
+
type: Injectable
|
|
299
|
+
}], ctorParameters: () => [{ type: i1.ReducerManager }, { type: undefined, decorators: [{
|
|
300
|
+
type: Inject,
|
|
301
|
+
args: [LIST_FEATURE_KEYS]
|
|
302
|
+
}] }] });
|
|
308
303
|
|
|
309
|
-
class AbstractListEffects {
|
|
310
|
-
constructor(actions$, store, service, listActions, listSelectors, notificationService) {
|
|
311
|
-
this.actions$ = actions$;
|
|
312
|
-
this.store = store;
|
|
313
|
-
this.service = service;
|
|
314
|
-
this.listActions = listActions;
|
|
315
|
-
this.listSelectors = listSelectors;
|
|
316
|
-
this.notificationService = notificationService;
|
|
317
|
-
this.
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
};
|
|
321
|
-
this.
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}
|
|
354
|
-
return of(true);
|
|
355
|
-
}), filter(confirmed => confirmed), withLatestFrom(this.store.pipe(select(this.listSelectors.getSelectedResourceIds))), filter(([, resourceIds]) => !!resourceIds.length), map(([, resourceIds]) => this.listActions.delete({ resourceIds }))));
|
|
356
|
-
this.delete$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.delete), exhaustMap(({ resourceIds }) => {
|
|
357
|
-
if (!this.service.deleteResources) {
|
|
358
|
-
throw new Error('deleteResources not implement in the ListService');
|
|
359
|
-
}
|
|
360
|
-
return this.service.deleteResources(resourceIds).pipe(map(() => this.listActions.deleteSuccess({ resourceIds })), catchError((errors) => of(this.listActions.deleteFailure({ errors }))));
|
|
361
|
-
})));
|
|
362
|
-
this.deleteSuccess$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.deleteSuccess), tap(({ resourceIds }) => {
|
|
363
|
-
this.notificationService?.onListDelete(resourceIds);
|
|
364
|
-
})), { dispatch: false });
|
|
365
|
-
this.errorsHandler$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadPageFailure, this.listActions.deleteFailure, this.listActions.patchFailure), tap(({ errors }) => {
|
|
366
|
-
this.notificationService?.onListErrors(errors);
|
|
367
|
-
})), { dispatch: false });
|
|
368
|
-
}
|
|
304
|
+
class AbstractListEffects {
|
|
305
|
+
constructor(actions$, store, service, listActions, listSelectors, notificationService) {
|
|
306
|
+
this.actions$ = actions$;
|
|
307
|
+
this.store = store;
|
|
308
|
+
this.service = service;
|
|
309
|
+
this.listActions = listActions;
|
|
310
|
+
this.listSelectors = listSelectors;
|
|
311
|
+
this.notificationService = notificationService;
|
|
312
|
+
this.reload$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.changePageSize, this.listActions.changeSorting, this.listActions.changeFiltering, this.listActions.changePagingOptions, this.listActions.changeRequestParams, this.listActions.initialize, this.listActions.reset, this.listActions.changePageNumber, this.listActions.patchSuccess, this.listActions.deleteSuccess), map(() => this.listActions.loadPage())));
|
|
313
|
+
this.loadFirstPage$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadFirstPage), map(() => this.listActions.changePageNumber({ pageNumber: 1 }))));
|
|
314
|
+
this.loadPreviousPage$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadPreviousPage), withLatestFrom(this.store.pipe(select(this.listSelectors.getCurrentPageNumber))), filter(([, currentPageNumber]) => currentPageNumber > 1), map(([, currentPageNumber]) => this.listActions.changePageNumber({ pageNumber: currentPageNumber - 1 }))));
|
|
315
|
+
this.loadNextPage$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadNextPage), withLatestFrom(this.store.pipe(select(this.listSelectors.isLastPage)), this.store.pipe(select(this.listSelectors.getCurrentPageNumber))), filter(([, isLastPage]) => !isLastPage), map(([, , currentPageNumber]) => this.listActions.changePageNumber({ pageNumber: currentPageNumber + 1 }))));
|
|
316
|
+
this.loadPage$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadPage), withLatestFrom(this.store.pipe(select(this.listSelectors.getPagingOptions)), this.store.pipe(select(this.listSelectors.getSortingOptions)), this.store.pipe(select(this.listSelectors.getFilteringOptions)), this.store.pipe(select(this.listSelectors.getRequestParameters))), switchMap(([, pagingOptions, sortingOptions, filteringOptions, requestParameters]) => {
|
|
317
|
+
return this.service
|
|
318
|
+
.loadResources({
|
|
319
|
+
pagingOptions,
|
|
320
|
+
sortingOptions,
|
|
321
|
+
filteringOptions,
|
|
322
|
+
requestParameters
|
|
323
|
+
})
|
|
324
|
+
.pipe(map(resources => this.listActions.loadPageSuccess({
|
|
325
|
+
resources,
|
|
326
|
+
pagingOptions
|
|
327
|
+
})), catchError((errors) => of(this.listActions.loadPageFailure({ errors }))));
|
|
328
|
+
})));
|
|
329
|
+
this.patch$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.patch), exhaustMap(action => {
|
|
330
|
+
if (!this.service.patchResources) {
|
|
331
|
+
throw new Error('patchResources not implement in the ListService');
|
|
332
|
+
}
|
|
333
|
+
return this.service.patchResources(action.resourceIds, action.resource).pipe(map(resources => this.listActions.patchSuccess({ resources })), catchError((errors) => of(this.listActions.patchFailure({ errors }))));
|
|
334
|
+
})));
|
|
335
|
+
this.delete$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.delete), exhaustMap(({ resourceIds }) => {
|
|
336
|
+
if (!this.service.deleteResources) {
|
|
337
|
+
throw new Error('deleteResources not implement in the ListService');
|
|
338
|
+
}
|
|
339
|
+
return this.service.deleteResources(resourceIds).pipe(map(() => this.listActions.deleteSuccess({ resourceIds })), catchError((errors) => of(this.listActions.deleteFailure({ errors }))));
|
|
340
|
+
})));
|
|
341
|
+
this.deleteSuccess$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.deleteSuccess), tap(({ resourceIds }) => {
|
|
342
|
+
this.notificationService?.onListDelete(resourceIds);
|
|
343
|
+
})), { dispatch: false });
|
|
344
|
+
this.errorsHandler$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadPageFailure, this.listActions.deleteFailure, this.listActions.patchFailure), tap(({ errors }) => {
|
|
345
|
+
this.notificationService?.onListErrors(errors);
|
|
346
|
+
})), { dispatch: false });
|
|
347
|
+
}
|
|
369
348
|
}
|
|
370
349
|
|
|
371
|
-
let ListEffects = class ListEffects extends AbstractListEffects {
|
|
372
|
-
constructor(actions$, store, listStateService, featureKey, service, notificationService) {
|
|
373
|
-
super(actions$, store, service, listStateService.getFeatureActions(featureKey), listStateService.getFeatureSelectors(featureKey), notificationService);
|
|
374
|
-
this.featureKey = featureKey;
|
|
375
|
-
}
|
|
376
|
-
ngrxOnIdentifyEffects() {
|
|
377
|
-
return this.featureKey;
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
ListEffects = __decorate([
|
|
381
|
-
__param(5, Optional()),
|
|
382
|
-
__metadata("design:paramtypes", [Actions,
|
|
383
|
-
Store,
|
|
384
|
-
ListStateService, String, Object, Object])
|
|
350
|
+
let ListEffects = class ListEffects extends AbstractListEffects {
|
|
351
|
+
constructor(actions$, store, listStateService, featureKey, service, notificationService) {
|
|
352
|
+
super(actions$, store, service, listStateService.getFeatureActions(featureKey), listStateService.getFeatureSelectors(featureKey), notificationService);
|
|
353
|
+
this.featureKey = featureKey;
|
|
354
|
+
}
|
|
355
|
+
ngrxOnIdentifyEffects() {
|
|
356
|
+
return this.featureKey;
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
ListEffects = __decorate([
|
|
360
|
+
__param(5, Optional()),
|
|
361
|
+
__metadata("design:paramtypes", [Actions,
|
|
362
|
+
Store,
|
|
363
|
+
ListStateService, String, Object, Object])
|
|
385
364
|
], ListEffects);
|
|
386
365
|
|
|
387
|
-
class NotificationServicePlaceholder {
|
|
388
|
-
onListErrors(errors) {
|
|
389
|
-
console.error('ERROR', errors);
|
|
390
|
-
}
|
|
391
|
-
onListDelete(ids) {
|
|
392
|
-
console.log(`Resources ${ids.join(', ')} have been deleted.`);
|
|
393
|
-
}
|
|
394
|
-
openConfirmationDialog(data) {
|
|
395
|
-
console.log(data.title, data.message);
|
|
396
|
-
return of(true);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
402
|
-
type: Injectable
|
|
366
|
+
class NotificationServicePlaceholder {
|
|
367
|
+
onListErrors(errors) {
|
|
368
|
+
console.error('ERROR', errors);
|
|
369
|
+
}
|
|
370
|
+
onListDelete(ids) {
|
|
371
|
+
console.log(`Resources ${ids.join(', ')} have been deleted.`);
|
|
372
|
+
}
|
|
373
|
+
openConfirmationDialog(data) {
|
|
374
|
+
console.log(data.title, data.message);
|
|
375
|
+
return of(true);
|
|
376
|
+
}
|
|
377
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NotificationServicePlaceholder, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
378
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NotificationServicePlaceholder }); }
|
|
379
|
+
}
|
|
380
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NotificationServicePlaceholder, decorators: [{
|
|
381
|
+
type: Injectable
|
|
403
382
|
}] });
|
|
404
383
|
|
|
405
|
-
class NgduxListStateModule {
|
|
406
|
-
constructor(registerEffectsService, actions$, store, listStateService, featureKeys, services, notificationServices) {
|
|
407
|
-
featureKeys.forEach((featureKey, index) => {
|
|
408
|
-
const listEffects = new ListEffects(actions$, store, listStateService, featureKey, services[index], notificationServices[index]);
|
|
409
|
-
registerEffectsService.registerEffects([listEffects]);
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
static config(config) {
|
|
413
|
-
return {
|
|
414
|
-
ngModule: NgduxListStateModule,
|
|
415
|
-
providers: [
|
|
416
|
-
{ provide: LIST_SERVICES, multi: true, useClass: config.service },
|
|
417
|
-
{
|
|
418
|
-
provide: LIST_NOTIFICATION_SERVICES,
|
|
419
|
-
multi: true,
|
|
420
|
-
useClass: config.notificationService || NotificationServicePlaceholder
|
|
421
|
-
}
|
|
422
|
-
]
|
|
423
|
-
};
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
430
|
-
type: NgModule,
|
|
431
|
-
args: [{
|
|
432
|
-
providers: [ListStateService]
|
|
433
|
-
}]
|
|
434
|
-
}], ctorParameters:
|
|
435
|
-
type: Inject,
|
|
436
|
-
args: [LIST_FEATURE_KEYS]
|
|
437
|
-
}] }, { type: undefined, decorators: [{
|
|
438
|
-
type: Inject,
|
|
439
|
-
args: [LIST_SERVICES]
|
|
440
|
-
}] }, { type: undefined, decorators: [{
|
|
441
|
-
type: Inject,
|
|
442
|
-
args: [LIST_NOTIFICATION_SERVICES]
|
|
443
|
-
}] }]
|
|
384
|
+
class NgduxListStateModule {
|
|
385
|
+
constructor(registerEffectsService, actions$, store, listStateService, featureKeys, services, notificationServices) {
|
|
386
|
+
featureKeys.forEach((featureKey, index) => {
|
|
387
|
+
const listEffects = new ListEffects(actions$, store, listStateService, featureKey, services[index], notificationServices[index]);
|
|
388
|
+
registerEffectsService.registerEffects([listEffects]);
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
static config(config) {
|
|
392
|
+
return {
|
|
393
|
+
ngModule: NgduxListStateModule,
|
|
394
|
+
providers: [
|
|
395
|
+
{ provide: LIST_SERVICES, multi: true, useClass: config.service },
|
|
396
|
+
{
|
|
397
|
+
provide: LIST_NOTIFICATION_SERVICES,
|
|
398
|
+
multi: true,
|
|
399
|
+
useClass: config.notificationService || NotificationServicePlaceholder
|
|
400
|
+
}
|
|
401
|
+
]
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgduxListStateModule, deps: [{ token: i1$1.RegisterEffectsService }, { token: i2.Actions }, { token: i1.Store }, { token: ListStateService }, { token: LIST_FEATURE_KEYS }, { token: LIST_SERVICES }, { token: LIST_NOTIFICATION_SERVICES }], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
405
|
+
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.2.2", ngImport: i0, type: NgduxListStateModule }); }
|
|
406
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgduxListStateModule, providers: [ListStateService] }); }
|
|
407
|
+
}
|
|
408
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: NgduxListStateModule, decorators: [{
|
|
409
|
+
type: NgModule,
|
|
410
|
+
args: [{
|
|
411
|
+
providers: [ListStateService]
|
|
412
|
+
}]
|
|
413
|
+
}], ctorParameters: () => [{ type: i1$1.RegisterEffectsService }, { type: i2.Actions }, { type: i1.Store }, { type: ListStateService }, { type: undefined, decorators: [{
|
|
414
|
+
type: Inject,
|
|
415
|
+
args: [LIST_FEATURE_KEYS]
|
|
416
|
+
}] }, { type: undefined, decorators: [{
|
|
417
|
+
type: Inject,
|
|
418
|
+
args: [LIST_SERVICES]
|
|
419
|
+
}] }, { type: undefined, decorators: [{
|
|
420
|
+
type: Inject,
|
|
421
|
+
args: [LIST_NOTIFICATION_SERVICES]
|
|
422
|
+
}] }] });
|
|
444
423
|
|
|
445
|
-
class AbstractListReducerManager {
|
|
446
|
-
constructor(reducerManager, featureKey) {
|
|
447
|
-
this.reducerManager = reducerManager;
|
|
448
|
-
this.featureKey = featureKey;
|
|
449
|
-
this.actions = this.getActions();
|
|
450
|
-
this.entityAdapter = this.getEntityAdapter();
|
|
451
|
-
this.addReducer();
|
|
452
|
-
this.selectors = this.getSelectors();
|
|
453
|
-
}
|
|
454
|
-
getActions() {
|
|
455
|
-
return createListActions(this.featureKey);
|
|
456
|
-
}
|
|
457
|
-
getEntityAdapter() {
|
|
458
|
-
return createListEntityAdapter();
|
|
459
|
-
}
|
|
460
|
-
addReducer() {
|
|
461
|
-
const currentReducers = Object.keys(this.reducerManager.currentReducers || {});
|
|
462
|
-
if (!currentReducers.includes(this.featureKey)) {
|
|
463
|
-
const reducer = createListReducer(this.entityAdapter, this.actions);
|
|
464
|
-
this.reducerManager.addReducer(this.featureKey, reducer);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
getSelectors() {
|
|
468
|
-
const getState = createFeatureSelector(this.featureKey);
|
|
469
|
-
return createListSelectors(this.entityAdapter, getState);
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
475
|
-
type: Injectable
|
|
476
|
-
}], ctorParameters:
|
|
477
|
-
type: Inject,
|
|
478
|
-
args: [LIST_FEATURE_KEY]
|
|
479
|
-
}] }]
|
|
424
|
+
class AbstractListReducerManager {
|
|
425
|
+
constructor(reducerManager, featureKey) {
|
|
426
|
+
this.reducerManager = reducerManager;
|
|
427
|
+
this.featureKey = featureKey;
|
|
428
|
+
this.actions = this.getActions();
|
|
429
|
+
this.entityAdapter = this.getEntityAdapter();
|
|
430
|
+
this.addReducer();
|
|
431
|
+
this.selectors = this.getSelectors();
|
|
432
|
+
}
|
|
433
|
+
getActions() {
|
|
434
|
+
return createListActions(this.featureKey);
|
|
435
|
+
}
|
|
436
|
+
getEntityAdapter() {
|
|
437
|
+
return createListEntityAdapter();
|
|
438
|
+
}
|
|
439
|
+
addReducer() {
|
|
440
|
+
const currentReducers = Object.keys(this.reducerManager.currentReducers || {});
|
|
441
|
+
if (!currentReducers.includes(this.featureKey)) {
|
|
442
|
+
const reducer = createListReducer(this.entityAdapter, this.actions);
|
|
443
|
+
this.reducerManager.addReducer(this.featureKey, reducer);
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
getSelectors() {
|
|
447
|
+
const getState = createFeatureSelector(this.featureKey);
|
|
448
|
+
return createListSelectors(this.entityAdapter, getState);
|
|
449
|
+
}
|
|
450
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: AbstractListReducerManager, deps: [{ token: i1.ReducerManager }, { token: LIST_FEATURE_KEY }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
451
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: AbstractListReducerManager }); }
|
|
452
|
+
}
|
|
453
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.2.2", ngImport: i0, type: AbstractListReducerManager, decorators: [{
|
|
454
|
+
type: Injectable
|
|
455
|
+
}], ctorParameters: () => [{ type: i1.ReducerManager }, { type: undefined, decorators: [{
|
|
456
|
+
type: Inject,
|
|
457
|
+
args: [LIST_FEATURE_KEY]
|
|
458
|
+
}] }] });
|
|
480
459
|
|
|
481
|
-
class AbstractListFacade {
|
|
482
|
-
constructor(store, listActions, listSelectors) {
|
|
483
|
-
this.store = store;
|
|
484
|
-
this.listActions = listActions;
|
|
485
|
-
this.listSelectors = listSelectors;
|
|
486
|
-
this.resources$ = this.store.pipe(select(this.listSelectors.getAll));
|
|
487
|
-
this.loadingState$ = this.store.pipe(select(this.listSelectors.getLoadingState));
|
|
488
|
-
this.requestState$ = this.store.pipe(select(this.listSelectors.getRequestState));
|
|
489
|
-
this.errors$ = this.store.pipe(select(this.listSelectors.getErrors));
|
|
490
|
-
this.isReady$ = this.store.pipe(select(this.listSelectors.isReady));
|
|
491
|
-
this.areSelectedReady$ = this.store.pipe(select(this.listSelectors.areSelectedReady));
|
|
492
|
-
this.currentPageData$ = this.store.pipe(select(this.listSelectors.getCurrentPageData));
|
|
493
|
-
this.currentPageNumber$ = this.store.pipe(select(this.listSelectors.getCurrentPageNumber));
|
|
494
|
-
this.filteringOptions$ = this.store.pipe(select(this.listSelectors.getFilteringOptions));
|
|
495
|
-
this.requestParameters$ = this.store.pipe(select(this.listSelectors.getRequestParameters));
|
|
496
|
-
this.lastPageNumber$ = this.store.pipe(select(this.listSelectors.getLastPageNumber));
|
|
497
|
-
this.pagingOptions$ = this.store.pipe(select(this.listSelectors.getPagingOptions));
|
|
498
|
-
this.requestOptions$ = this.store.pipe(select(this.listSelectors.getRequestOptions));
|
|
499
|
-
this.sortingOptions$ = this.store.pipe(select(this.listSelectors.getSortingOptions));
|
|
500
|
-
this.selectedItems$ = this.store.pipe(select(this.listSelectors.getSelectedItems));
|
|
501
|
-
this.totalCount$ = this.store.pipe(select(this.listSelectors.getTotalCount));
|
|
502
|
-
}
|
|
503
|
-
setPageSize(props) {
|
|
504
|
-
this.store.dispatch(this.listActions.setPageSize(props));
|
|
505
|
-
}
|
|
506
|
-
setFiltering(props) {
|
|
507
|
-
this.store.dispatch(this.listActions.setFiltering(props));
|
|
508
|
-
}
|
|
509
|
-
setSorting(props) {
|
|
510
|
-
this.store.dispatch(this.listActions.setSorting(props));
|
|
511
|
-
}
|
|
512
|
-
setRequestParameters(props) {
|
|
513
|
-
this.store.dispatch(this.listActions.setRequestParams(props));
|
|
514
|
-
}
|
|
515
|
-
changeFiltering(props) {
|
|
516
|
-
this.store.dispatch(this.listActions.changeFiltering(props));
|
|
517
|
-
}
|
|
518
|
-
changePagingOptions(props) {
|
|
519
|
-
this.store.dispatch(this.listActions.changePagingOptions(props));
|
|
520
|
-
}
|
|
521
|
-
changePageSize(props) {
|
|
522
|
-
this.store.dispatch(this.listActions.changePageSize(props));
|
|
523
|
-
}
|
|
524
|
-
changePageNumber(props) {
|
|
525
|
-
this.store.dispatch(this.listActions.changePageNumber(props));
|
|
526
|
-
}
|
|
527
|
-
changeSelectedResources(props) {
|
|
528
|
-
this.store.dispatch(this.listActions.changeSelectedResources(props));
|
|
529
|
-
}
|
|
530
|
-
changeSorting(props) {
|
|
531
|
-
this.store.dispatch(this.listActions.changeSorting(props));
|
|
532
|
-
}
|
|
533
|
-
changeRequestParams(props) {
|
|
534
|
-
this.store.dispatch(this.listActions.changeRequestParams(props));
|
|
535
|
-
}
|
|
536
|
-
loadPage() {
|
|
537
|
-
this.store.dispatch(this.listActions.loadPage());
|
|
538
|
-
}
|
|
539
|
-
loadFirstPage() {
|
|
540
|
-
this.store.dispatch(this.listActions.loadFirstPage());
|
|
541
|
-
}
|
|
542
|
-
loadNextPage() {
|
|
543
|
-
this.store.dispatch(this.listActions.loadNextPage());
|
|
544
|
-
}
|
|
545
|
-
loadPreviousPage() {
|
|
546
|
-
this.store.dispatch(this.listActions.loadPreviousPage());
|
|
547
|
-
}
|
|
548
|
-
patch(props) {
|
|
549
|
-
this.store.dispatch(this.listActions.patch(props));
|
|
550
|
-
}
|
|
551
|
-
delete(props) {
|
|
552
|
-
this.store.dispatch(this.listActions.delete(props));
|
|
553
|
-
}
|
|
554
|
-
initialize() {
|
|
555
|
-
this.store.dispatch(this.listActions.initialize());
|
|
556
|
-
}
|
|
557
|
-
reinitialize() {
|
|
558
|
-
this.store.dispatch(this.listActions.reset());
|
|
559
|
-
}
|
|
560
|
-
resetRequestState() {
|
|
561
|
-
this.store.dispatch(this.listActions.resetRequestState());
|
|
562
|
-
}
|
|
563
|
-
/**
|
|
564
|
-
* @deprecated The method will be removed. The AbstractFacade will not be responsible for it anymore
|
|
565
|
-
*/
|
|
566
|
-
showRemovalsConfirmation() {
|
|
567
|
-
this.store.dispatch(this.listActions.showRemovalsConfirmation());
|
|
568
|
-
}
|
|
460
|
+
class AbstractListFacade {
|
|
461
|
+
constructor(store, listActions, listSelectors) {
|
|
462
|
+
this.store = store;
|
|
463
|
+
this.listActions = listActions;
|
|
464
|
+
this.listSelectors = listSelectors;
|
|
465
|
+
this.resources$ = this.store.pipe(select(this.listSelectors.getAll));
|
|
466
|
+
this.loadingState$ = this.store.pipe(select(this.listSelectors.getLoadingState));
|
|
467
|
+
this.requestState$ = this.store.pipe(select(this.listSelectors.getRequestState));
|
|
468
|
+
this.errors$ = this.store.pipe(select(this.listSelectors.getErrors));
|
|
469
|
+
this.isReady$ = this.store.pipe(select(this.listSelectors.isReady));
|
|
470
|
+
this.areSelectedReady$ = this.store.pipe(select(this.listSelectors.areSelectedReady));
|
|
471
|
+
this.currentPageData$ = this.store.pipe(select(this.listSelectors.getCurrentPageData));
|
|
472
|
+
this.currentPageNumber$ = this.store.pipe(select(this.listSelectors.getCurrentPageNumber));
|
|
473
|
+
this.filteringOptions$ = this.store.pipe(select(this.listSelectors.getFilteringOptions));
|
|
474
|
+
this.requestParameters$ = this.store.pipe(select(this.listSelectors.getRequestParameters));
|
|
475
|
+
this.lastPageNumber$ = this.store.pipe(select(this.listSelectors.getLastPageNumber));
|
|
476
|
+
this.pagingOptions$ = this.store.pipe(select(this.listSelectors.getPagingOptions));
|
|
477
|
+
this.requestOptions$ = this.store.pipe(select(this.listSelectors.getRequestOptions));
|
|
478
|
+
this.sortingOptions$ = this.store.pipe(select(this.listSelectors.getSortingOptions));
|
|
479
|
+
this.selectedItems$ = this.store.pipe(select(this.listSelectors.getSelectedItems));
|
|
480
|
+
this.totalCount$ = this.store.pipe(select(this.listSelectors.getTotalCount));
|
|
481
|
+
}
|
|
482
|
+
setPageSize(props) {
|
|
483
|
+
this.store.dispatch(this.listActions.setPageSize(props));
|
|
484
|
+
}
|
|
485
|
+
setFiltering(props) {
|
|
486
|
+
this.store.dispatch(this.listActions.setFiltering(props));
|
|
487
|
+
}
|
|
488
|
+
setSorting(props) {
|
|
489
|
+
this.store.dispatch(this.listActions.setSorting(props));
|
|
490
|
+
}
|
|
491
|
+
setRequestParameters(props) {
|
|
492
|
+
this.store.dispatch(this.listActions.setRequestParams(props));
|
|
493
|
+
}
|
|
494
|
+
changeFiltering(props) {
|
|
495
|
+
this.store.dispatch(this.listActions.changeFiltering(props));
|
|
496
|
+
}
|
|
497
|
+
changePagingOptions(props) {
|
|
498
|
+
this.store.dispatch(this.listActions.changePagingOptions(props));
|
|
499
|
+
}
|
|
500
|
+
changePageSize(props) {
|
|
501
|
+
this.store.dispatch(this.listActions.changePageSize(props));
|
|
502
|
+
}
|
|
503
|
+
changePageNumber(props) {
|
|
504
|
+
this.store.dispatch(this.listActions.changePageNumber(props));
|
|
505
|
+
}
|
|
506
|
+
changeSelectedResources(props) {
|
|
507
|
+
this.store.dispatch(this.listActions.changeSelectedResources(props));
|
|
508
|
+
}
|
|
509
|
+
changeSorting(props) {
|
|
510
|
+
this.store.dispatch(this.listActions.changeSorting(props));
|
|
511
|
+
}
|
|
512
|
+
changeRequestParams(props) {
|
|
513
|
+
this.store.dispatch(this.listActions.changeRequestParams(props));
|
|
514
|
+
}
|
|
515
|
+
loadPage() {
|
|
516
|
+
this.store.dispatch(this.listActions.loadPage());
|
|
517
|
+
}
|
|
518
|
+
loadFirstPage() {
|
|
519
|
+
this.store.dispatch(this.listActions.loadFirstPage());
|
|
520
|
+
}
|
|
521
|
+
loadNextPage() {
|
|
522
|
+
this.store.dispatch(this.listActions.loadNextPage());
|
|
523
|
+
}
|
|
524
|
+
loadPreviousPage() {
|
|
525
|
+
this.store.dispatch(this.listActions.loadPreviousPage());
|
|
526
|
+
}
|
|
527
|
+
patch(props) {
|
|
528
|
+
this.store.dispatch(this.listActions.patch(props));
|
|
529
|
+
}
|
|
530
|
+
delete(props) {
|
|
531
|
+
this.store.dispatch(this.listActions.delete(props));
|
|
532
|
+
}
|
|
533
|
+
initialize() {
|
|
534
|
+
this.store.dispatch(this.listActions.initialize());
|
|
535
|
+
}
|
|
536
|
+
reinitialize() {
|
|
537
|
+
this.store.dispatch(this.listActions.reset());
|
|
538
|
+
}
|
|
539
|
+
resetRequestState() {
|
|
540
|
+
this.store.dispatch(this.listActions.resetRequestState());
|
|
541
|
+
}
|
|
569
542
|
}
|
|
570
543
|
|
|
571
|
-
function createListState(featureName, idKey) {
|
|
572
|
-
const actions = createListActions(featureName);
|
|
573
|
-
const entityAdapter = createListEntityAdapter(idKey);
|
|
574
|
-
const reducer = createListReducer(entityAdapter, actions);
|
|
575
|
-
const getState = createFeatureSelector(featureName);
|
|
576
|
-
const selectors = createListSelectors(entityAdapter, getState);
|
|
577
|
-
return {
|
|
578
|
-
actions,
|
|
579
|
-
reducer: (state, action) => reducer(state, action),
|
|
580
|
-
selectors,
|
|
581
|
-
entityAdapter
|
|
582
|
-
};
|
|
544
|
+
function createListState(featureName, idKey) {
|
|
545
|
+
const actions = createListActions(featureName);
|
|
546
|
+
const entityAdapter = createListEntityAdapter(idKey);
|
|
547
|
+
const reducer = createListReducer(entityAdapter, actions);
|
|
548
|
+
const getState = createFeatureSelector(featureName);
|
|
549
|
+
const selectors = createListSelectors(entityAdapter, getState);
|
|
550
|
+
return {
|
|
551
|
+
actions,
|
|
552
|
+
reducer: (state, action) => reducer(state, action),
|
|
553
|
+
selectors,
|
|
554
|
+
entityAdapter
|
|
555
|
+
};
|
|
583
556
|
}
|
|
584
557
|
|
|
585
|
-
/**
|
|
586
|
-
* Generated bundle index. Do not edit.
|
|
558
|
+
/**
|
|
559
|
+
* Generated bundle index. Do not edit.
|
|
587
560
|
*/
|
|
588
561
|
|
|
589
562
|
export { AbstractListEffects, AbstractListFacade, AbstractListReducerManager, LIST_FEATURE_KEY, LIST_FEATURE_KEYS, LIST_NOTIFICATION_SERVICES, LIST_SERVICES, ListStateService, NgduxListStateModule, createListActions, createListEntityAdapter, createListReducer, createListSelectors, createListState };
|