@ngdux/list 1.3.2 → 2.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/esm2022/index.mjs +12 -0
- package/esm2022/lib/+state/effects.mjs +22 -0
- package/esm2022/lib/+state/state.service.mjs +55 -0
- package/esm2022/lib/models/list.model.mjs +7 -0
- package/esm2022/lib/ngdux-list-state.module.mjs +53 -0
- package/esm2022/lib/services/list-notification-service.mjs +21 -0
- package/esm2022/lib/state-generator/abstract-list-effects.mjs +50 -0
- package/esm2022/lib/state-generator/abstract-list-state.service.mjs +44 -0
- package/esm2022/lib/state-generator/abstract-list.facade.mjs +85 -0
- package/esm2022/lib/state-generator/list-actions.mjs +58 -0
- package/esm2022/lib/state-generator/list-reducer.mjs +104 -0
- package/esm2022/lib/state-generator/list-selectors.mjs +80 -0
- package/esm2022/lib/state-generator/list-state.mjs +18 -0
- package/{esm2020 → esm2022}/ngdux-list.mjs +4 -4
- package/{fesm2020 → fesm2022}/ngdux-list.mjs +540 -432
- package/fesm2022/ngdux-list.mjs.map +1 -0
- package/index.d.ts +11 -9
- package/lib/+state/effects.d.ts +14 -0
- package/lib/+state/state.service.d.ts +22 -0
- package/lib/models/list.model.d.ts +191 -183
- package/lib/ngdux-list-state.module.d.ts +23 -0
- package/lib/services/list-notification-service.d.ts +13 -0
- package/lib/{+state → state-generator}/abstract-list-effects.d.ts +49 -61
- package/lib/{+state → state-generator}/abstract-list-state.service.d.ts +21 -21
- package/lib/{+state → state-generator}/abstract-list.facade.d.ts +45 -46
- package/lib/{+state → state-generator}/list-actions.d.ts +2 -2
- package/lib/{+state → state-generator}/list-reducer.d.ts +10 -10
- package/lib/state-generator/list-selectors.d.ts +4 -0
- package/lib/{+state → state-generator}/list-state.d.ts +12 -12
- package/package.json +9 -102
- package/esm2020/index.mjs +0 -10
- package/esm2020/lib/+state/abstract-list-effects.mjs +0 -71
- package/esm2020/lib/+state/abstract-list-state.service.mjs +0 -44
- package/esm2020/lib/+state/abstract-list.facade.mjs +0 -88
- package/esm2020/lib/+state/list-actions.mjs +0 -60
- package/esm2020/lib/+state/list-reducer.mjs +0 -97
- package/esm2020/lib/+state/list-selectors.mjs +0 -80
- package/esm2020/lib/+state/list-state.mjs +0 -18
- package/esm2020/lib/models/list.model.mjs +0 -4
- package/fesm2015/ngdux-list.mjs +0 -404
- package/fesm2015/ngdux-list.mjs.map +0 -1
- package/fesm2020/ngdux-list.mjs.map +0 -1
- package/lib/+state/list-selectors.d.ts +0 -4
|
@@ -1,455 +1,563 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getDefaultRequestOptions, RequestState, DEFAULT_PAGE } from '@ngdux/data-model-common';
|
|
2
2
|
export { RequestState } from '@ngdux/data-model-common';
|
|
3
|
-
import { createEffect, ofType } from '@ngrx/effects';
|
|
4
|
-
import * as i1 from '@ngrx/store';
|
|
5
|
-
import { select, createAction, props, createReducer, on, createSelector, createFeatureSelector } from '@ngrx/store';
|
|
6
|
-
import { of } from 'rxjs';
|
|
7
|
-
import { map, withLatestFrom, filter, concatMap, catchError, exhaustMap, switchMap, tap } from 'rxjs/operators';
|
|
8
3
|
import * as i0 from '@angular/core';
|
|
9
|
-
import { InjectionToken, Injectable, Inject } from '@angular/core';
|
|
4
|
+
import { InjectionToken, Injectable, Inject, Optional, NgModule } from '@angular/core';
|
|
5
|
+
import * as i1 from '@ngrx/store';
|
|
6
|
+
import { createAction, props, createReducer, on, createSelector, createFeatureSelector, select, Store } from '@ngrx/store';
|
|
7
|
+
import * as i1$1 from '@ngdux/store-common';
|
|
10
8
|
import { getLastPageNumber, createLoadingStateActionHandlers, createRequestStateActionHandlers } from '@ngdux/store-common';
|
|
11
9
|
import { createEntityAdapter } from '@ngrx/entity';
|
|
10
|
+
import * as i2 from '@ngrx/effects';
|
|
11
|
+
import { createEffect, ofType, Actions } from '@ngrx/effects';
|
|
12
|
+
import { __decorate, __param, __metadata } from 'tslib';
|
|
13
|
+
import { of } from 'rxjs';
|
|
14
|
+
import { map, withLatestFrom, filter, switchMap, catchError, exhaustMap, tap } from 'rxjs/operators';
|
|
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');
|
|
20
|
+
const LIST_NOTIFICATION_SERVICES = new InjectionToken('LIST_NOTIFICATION_SERVICES');
|
|
12
21
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
return this.service.deleteResources(resourceIds).pipe(map(() => this.listActions.deleteSuccess({ resourceIds })), catchError((errors) => of(this.listActions.deleteFailure({ errors }))));
|
|
70
|
-
})));
|
|
71
|
-
this.deleteUsersSuccess$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.deleteSuccess), tap(({ resourceIds }) => {
|
|
72
|
-
this.notificationService?.onListDelete(resourceIds);
|
|
73
|
-
})), { dispatch: false });
|
|
74
|
-
this.errorsHandler$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadPageFailure, this.listActions.deleteFailure, this.listActions.patchFailure), tap(({ errors }) => {
|
|
75
|
-
this.notificationService?.onListErrors(errors);
|
|
76
|
-
})), { dispatch: false });
|
|
77
|
-
}
|
|
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
|
+
};
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
];
|
|
177
|
+
}
|
|
82
178
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
const
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
+
};
|
|
140
255
|
}
|
|
141
256
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
})),
|
|
182
|
-
on(actions.changeSorting, actions.setSorting, (state, { sortingOptions }) => ({
|
|
183
|
-
...state,
|
|
184
|
-
sortingOptions,
|
|
185
|
-
pagingOptions: { ...state.pagingOptions, page: DEFAULT_PAGE }
|
|
186
|
-
})),
|
|
187
|
-
on(actions.changeFiltering, actions.setFiltering, (state, { filteringOptions }) => ({
|
|
188
|
-
...state,
|
|
189
|
-
filteringOptions,
|
|
190
|
-
pagingOptions: { ...state.pagingOptions, page: DEFAULT_PAGE },
|
|
191
|
-
lastPageNumber: undefined
|
|
192
|
-
})),
|
|
193
|
-
on(actions.changeRequestParams, actions.setRequestParams, (state, { params }) => ({
|
|
194
|
-
...state,
|
|
195
|
-
requestParameters: params,
|
|
196
|
-
pagingOptions: { ...state.pagingOptions, page: DEFAULT_PAGE }
|
|
197
|
-
})),
|
|
198
|
-
on(actions.changeSelectedResources, (state, { selectedResourceIds }) => ({
|
|
199
|
-
...state,
|
|
200
|
-
selectedResourceIds
|
|
201
|
-
})),
|
|
202
|
-
on(actions.loadFirstPage, (state) => ({
|
|
203
|
-
...state,
|
|
204
|
-
pagingOptions: { ...state.pagingOptions, page: 1 }
|
|
205
|
-
})),
|
|
206
|
-
on(actions.loadPageSuccess, (state, { resources, pagingOptions }) => {
|
|
207
|
-
const lastPageNumber = getLastPageNumber(resources, pagingOptions) || state.lastPageNumber;
|
|
208
|
-
if (lastPageNumber && pagingOptions.page > lastPageNumber) {
|
|
209
|
-
return {
|
|
210
|
-
...state,
|
|
211
|
-
pagingOptions: {
|
|
212
|
-
...state.pagingOptions,
|
|
213
|
-
page: lastPageNumber
|
|
214
|
-
},
|
|
215
|
-
lastPageNumber,
|
|
216
|
-
selectedResourceIds: []
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
return entityAdapter.setAll(resources, {
|
|
220
|
-
...state,
|
|
221
|
-
lastPageNumber,
|
|
222
|
-
selectedResourceIds: []
|
|
223
|
-
});
|
|
224
|
-
}),
|
|
225
|
-
on(actions.deleteSuccess, (state) => ({
|
|
226
|
-
...state,
|
|
227
|
-
selectedResourceIds: []
|
|
228
|
-
})),
|
|
229
|
-
...createLoadingStateActionHandlers(actions.loadPage, actions.loadPageSuccess, actions.loadPageFailure),
|
|
230
|
-
...createRequestStateActionHandlers(undefined, actions.delete, actions.deleteSuccess, actions.deleteFailure),
|
|
231
|
-
...createRequestStateActionHandlers(actions.resetRequestState, actions.patch, actions.patchSuccess, actions.patchFailure)
|
|
232
|
-
];
|
|
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: "16.2.12", 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: "16.2.12", ngImport: i0, type: ListStateService }); }
|
|
233
296
|
}
|
|
297
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: ListStateService, decorators: [{
|
|
298
|
+
type: Injectable
|
|
299
|
+
}], ctorParameters: function () { return [{ type: i1.ReducerManager }, { type: undefined, decorators: [{
|
|
300
|
+
type: Inject,
|
|
301
|
+
args: [LIST_FEATURE_KEYS]
|
|
302
|
+
}] }]; } });
|
|
303
|
+
|
|
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
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
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])
|
|
364
|
+
], ListEffects);
|
|
234
365
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
});
|
|
248
|
-
const getCurrentPageData = createSelector(getAll, resources => {
|
|
249
|
-
return resources;
|
|
250
|
-
});
|
|
251
|
-
const getSortingOptions = createSelector(getListState, state => state.sortingOptions);
|
|
252
|
-
const getRequestParameters = createSelector(getListState, state => state.requestParameters);
|
|
253
|
-
const getFilteringOptions = createSelector(getListState, state => state.filteringOptions);
|
|
254
|
-
const getCurrentPageNumber = createSelector(getPagingOptions, options => options?.page);
|
|
255
|
-
const getSelectedResourceIds = createSelector(getListState, state => state.selectedResourceIds);
|
|
256
|
-
const getLoadingState = createSelector(getListState, state => state.loadingState);
|
|
257
|
-
const getSelectedItems = createSelector(getSelectedResourceIds, createSelector(getListState, entityAdapter.getSelectors().selectEntities), (selectedResourceIds, resources) => selectedResourceIds.reduce((acc, selectedResourceId) => {
|
|
258
|
-
const resource = resources[selectedResourceId];
|
|
259
|
-
if (resource) {
|
|
260
|
-
acc.push(resource);
|
|
261
|
-
}
|
|
262
|
-
return acc;
|
|
263
|
-
}, []));
|
|
264
|
-
const getSelectionRecord = createSelector(getSelectedResourceIds, createSelector(getListState, entityAdapter.getSelectors().selectEntities), (selectedResourceIds, resources) => selectedResourceIds.reduce((selected, selectedResourceId) => {
|
|
265
|
-
const resource = resources[selectedResourceId];
|
|
266
|
-
if (resource) {
|
|
267
|
-
selected[selectedResourceId] = resource;
|
|
268
|
-
}
|
|
269
|
-
return selected;
|
|
270
|
-
}, {}));
|
|
271
|
-
const getRequestState = createSelector(getListState, state => state.requestState);
|
|
272
|
-
const getErrors = createSelector(getListState, state => state.errors);
|
|
273
|
-
const isReady = createSelector(getAll, getLoadingState, (users, loadingState) => !!users && loadingState === RequestState.SUCCESS);
|
|
274
|
-
const areSelectedReady = createSelector(getSelectedResourceIds, getSelectionRecord, getLoadingState, (selectedResourceIds, resources, loadingState) => {
|
|
275
|
-
return selectedResourceIds.every(resourceId => !!resources[resourceId]) && loadingState === RequestState.SUCCESS;
|
|
276
|
-
});
|
|
277
|
-
const isDeleteDisabled = createSelector(getSelectedResourceIds, selectedResourceIds => !selectedResourceIds.length);
|
|
278
|
-
const isCopyDisabled = createSelector(getSelectedResourceIds, selectedResourceIds => selectedResourceIds.length !== 1);
|
|
279
|
-
const getTotalCount = createSelector(getPagingOptions, isLastPage, getCurrentPageData, (pagingOptions, isLastPage, currentPageData) => {
|
|
280
|
-
if (!pagingOptions) {
|
|
281
|
-
return 0;
|
|
282
|
-
}
|
|
283
|
-
if (isLastPage) {
|
|
284
|
-
return (pagingOptions.page - 1) * pagingOptions.pageSize + currentPageData.length;
|
|
285
|
-
}
|
|
286
|
-
return (pagingOptions.page + 1) * pagingOptions.pageSize;
|
|
287
|
-
});
|
|
288
|
-
return {
|
|
289
|
-
getAll,
|
|
290
|
-
getRequestOptions,
|
|
291
|
-
isLastPage,
|
|
292
|
-
getCurrentPageData,
|
|
293
|
-
getPagingOptions,
|
|
294
|
-
getSortingOptions,
|
|
295
|
-
getFilteringOptions,
|
|
296
|
-
getRequestParameters,
|
|
297
|
-
getCurrentPageNumber,
|
|
298
|
-
getLastPageNumber,
|
|
299
|
-
getLoadingState,
|
|
300
|
-
getSelectedResourceIds,
|
|
301
|
-
getSelectedItems,
|
|
302
|
-
getSelectionRecord,
|
|
303
|
-
getRequestState,
|
|
304
|
-
getErrors,
|
|
305
|
-
areSelectedReady,
|
|
306
|
-
isReady,
|
|
307
|
-
isDeleteDisabled,
|
|
308
|
-
isCopyDisabled,
|
|
309
|
-
getTotalCount
|
|
310
|
-
};
|
|
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: "16.2.12", ngImport: i0, type: NotificationServicePlaceholder, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
378
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NotificationServicePlaceholder }); }
|
|
311
379
|
}
|
|
380
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NotificationServicePlaceholder, decorators: [{
|
|
381
|
+
type: Injectable
|
|
382
|
+
}] });
|
|
312
383
|
|
|
313
|
-
class
|
|
314
|
-
constructor(
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
-
|
|
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: "16.2.12", 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: "16.2.12", ngImport: i0, type: NgduxListStateModule }); }
|
|
406
|
+
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgduxListStateModule, providers: [ListStateService] }); }
|
|
407
|
+
}
|
|
408
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NgduxListStateModule, decorators: [{
|
|
409
|
+
type: NgModule,
|
|
410
|
+
args: [{
|
|
411
|
+
providers: [ListStateService]
|
|
412
|
+
}]
|
|
413
|
+
}], ctorParameters: function () { return [{ 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
|
+
}] }]; } });
|
|
423
|
+
|
|
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: "16.2.12", 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: "16.2.12", ngImport: i0, type: AbstractListReducerManager }); }
|
|
452
|
+
}
|
|
453
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: AbstractListReducerManager, decorators: [{
|
|
454
|
+
type: Injectable
|
|
455
|
+
}], ctorParameters: function () { return [{ type: i1.ReducerManager }, { type: undefined, decorators: [{
|
|
456
|
+
type: Inject,
|
|
457
|
+
args: [LIST_FEATURE_KEY]
|
|
347
458
|
}] }]; } });
|
|
348
459
|
|
|
349
|
-
class AbstractListFacade {
|
|
350
|
-
constructor(store, listActions, listSelectors) {
|
|
351
|
-
this.store = store;
|
|
352
|
-
this.listActions = listActions;
|
|
353
|
-
this.listSelectors = listSelectors;
|
|
354
|
-
this.resources$ = this.store.pipe(select(this.listSelectors.getAll));
|
|
355
|
-
this.loadingState$ = this.store.pipe(select(this.listSelectors.getLoadingState));
|
|
356
|
-
this.requestState$ = this.store.pipe(select(this.listSelectors.getRequestState));
|
|
357
|
-
this.errors$ = this.store.pipe(select(this.listSelectors.getErrors));
|
|
358
|
-
this.isReady$ = this.store.pipe(select(this.listSelectors.isReady));
|
|
359
|
-
this.areSelectedReady$ = this.store.pipe(select(this.listSelectors.areSelectedReady));
|
|
360
|
-
this.currentPageData$ = this.store.pipe(select(this.listSelectors.getCurrentPageData));
|
|
361
|
-
this.currentPageNumber$ = this.store.pipe(select(this.listSelectors.getCurrentPageNumber));
|
|
362
|
-
this.filteringOptions$ = this.store.pipe(select(this.listSelectors.getFilteringOptions));
|
|
363
|
-
this.requestParameters$ = this.store.pipe(select(this.listSelectors.getRequestParameters));
|
|
364
|
-
this.lastPageNumber$ = this.store.pipe(select(this.listSelectors.getLastPageNumber));
|
|
365
|
-
this.pagingOptions$ = this.store.pipe(select(this.listSelectors.getPagingOptions));
|
|
366
|
-
this.requestOptions$ = this.store.pipe(select(this.listSelectors.getRequestOptions));
|
|
367
|
-
this.sortingOptions$ = this.store.pipe(select(this.listSelectors.getSortingOptions));
|
|
368
|
-
this.selectedItems$ = this.store.pipe(select(this.listSelectors.getSelectedItems));
|
|
369
|
-
this.totalCount$ = this.store.pipe(select(this.listSelectors.getTotalCount));
|
|
370
|
-
}
|
|
371
|
-
setPageSize(props) {
|
|
372
|
-
this.store.dispatch(this.listActions.setPageSize(props));
|
|
373
|
-
}
|
|
374
|
-
setFiltering(props) {
|
|
375
|
-
this.store.dispatch(this.listActions.setFiltering(props));
|
|
376
|
-
}
|
|
377
|
-
setSorting(props) {
|
|
378
|
-
this.store.dispatch(this.listActions.setSorting(props));
|
|
379
|
-
}
|
|
380
|
-
setRequestParameters(props) {
|
|
381
|
-
this.store.dispatch(this.listActions.setRequestParams(props));
|
|
382
|
-
}
|
|
383
|
-
changeFiltering(props) {
|
|
384
|
-
this.store.dispatch(this.listActions.changeFiltering(props));
|
|
385
|
-
}
|
|
386
|
-
changePagingOptions(props) {
|
|
387
|
-
this.store.dispatch(this.listActions.changePagingOptions(props));
|
|
388
|
-
}
|
|
389
|
-
changePageSize(props) {
|
|
390
|
-
this.store.dispatch(this.listActions.changePageSize(props));
|
|
391
|
-
}
|
|
392
|
-
changePageNumber(props) {
|
|
393
|
-
this.store.dispatch(this.listActions.changePageNumber(props));
|
|
394
|
-
}
|
|
395
|
-
changeSelectedResources(props) {
|
|
396
|
-
this.store.dispatch(this.listActions.changeSelectedResources(props));
|
|
397
|
-
}
|
|
398
|
-
changeSorting(props) {
|
|
399
|
-
this.store.dispatch(this.listActions.changeSorting(props));
|
|
400
|
-
}
|
|
401
|
-
changeRequestParams(props) {
|
|
402
|
-
this.store.dispatch(this.listActions.changeRequestParams(props));
|
|
403
|
-
}
|
|
404
|
-
loadPage() {
|
|
405
|
-
this.store.dispatch(this.listActions.loadPage());
|
|
406
|
-
}
|
|
407
|
-
loadFirstPage() {
|
|
408
|
-
this.store.dispatch(this.listActions.loadFirstPage());
|
|
409
|
-
}
|
|
410
|
-
loadNextPage() {
|
|
411
|
-
this.store.dispatch(this.listActions.loadNextPage());
|
|
412
|
-
}
|
|
413
|
-
loadPreviousPage() {
|
|
414
|
-
this.store.dispatch(this.listActions.loadPreviousPage());
|
|
415
|
-
}
|
|
416
|
-
patch(props) {
|
|
417
|
-
this.store.dispatch(this.listActions.patch(props));
|
|
418
|
-
}
|
|
419
|
-
delete(props) {
|
|
420
|
-
this.store.dispatch(this.listActions.delete(props));
|
|
421
|
-
}
|
|
422
|
-
initialize() {
|
|
423
|
-
this.store.dispatch(this.listActions.initialize());
|
|
424
|
-
}
|
|
425
|
-
reinitialize() {
|
|
426
|
-
this.store.dispatch(this.listActions.reset());
|
|
427
|
-
}
|
|
428
|
-
resetRequestState() {
|
|
429
|
-
this.store.dispatch(this.listActions.resetRequestState());
|
|
430
|
-
}
|
|
431
|
-
showRemovalsConfirmation() {
|
|
432
|
-
this.store.dispatch(this.listActions.showRemovalsConfirmation());
|
|
433
|
-
}
|
|
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
|
+
}
|
|
434
542
|
}
|
|
435
543
|
|
|
436
|
-
function createListState(featureName, idKey) {
|
|
437
|
-
const actions = createListActions(featureName);
|
|
438
|
-
const entityAdapter = createListEntityAdapter(idKey);
|
|
439
|
-
const reducer = createListReducer(entityAdapter, actions);
|
|
440
|
-
const getState = createFeatureSelector(featureName);
|
|
441
|
-
const selectors = createListSelectors(entityAdapter, getState);
|
|
442
|
-
return {
|
|
443
|
-
actions,
|
|
444
|
-
reducer: (state, action) => reducer(state, action),
|
|
445
|
-
selectors,
|
|
446
|
-
entityAdapter
|
|
447
|
-
};
|
|
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
|
+
};
|
|
448
556
|
}
|
|
449
557
|
|
|
450
|
-
/**
|
|
451
|
-
* Generated bundle index. Do not edit.
|
|
558
|
+
/**
|
|
559
|
+
* Generated bundle index. Do not edit.
|
|
452
560
|
*/
|
|
453
561
|
|
|
454
|
-
export { AbstractListEffects, AbstractListFacade, AbstractListReducerManager, LIST_FEATURE_KEY, createListActions, createListEntityAdapter, createListReducer, createListSelectors, createListState };
|
|
562
|
+
export { AbstractListEffects, AbstractListFacade, AbstractListReducerManager, LIST_FEATURE_KEY, LIST_FEATURE_KEYS, LIST_NOTIFICATION_SERVICES, LIST_SERVICES, ListStateService, NgduxListStateModule, createListActions, createListEntityAdapter, createListReducer, createListSelectors, createListState };
|
|
455
563
|
//# sourceMappingURL=ngdux-list.mjs.map
|