@ngdux/list 1.3.2 → 1.4.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/index.mjs +10 -8
- package/esm2020/lib/+state/effects.mjs +23 -0
- package/esm2020/lib/+state/state.service.mjs +55 -0
- package/esm2020/lib/models/list.model.mjs +4 -1
- package/esm2020/lib/ngdux-list-state.module.mjs +53 -0
- package/esm2020/lib/services/list-notification-service.mjs +21 -0
- package/esm2020/lib/state-generator/abstract-list-effects.mjs +66 -0
- package/esm2020/lib/state-generator/abstract-list-state.service.mjs +44 -0
- package/esm2020/lib/state-generator/abstract-list.facade.mjs +91 -0
- package/esm2020/lib/state-generator/list-actions.mjs +63 -0
- package/esm2020/lib/state-generator/list-reducer.mjs +104 -0
- package/esm2020/lib/state-generator/list-selectors.mjs +80 -0
- package/esm2020/lib/state-generator/list-state.mjs +18 -0
- package/fesm2015/ngdux-list.mjs +240 -107
- package/fesm2015/ngdux-list.mjs.map +1 -1
- package/fesm2020/ngdux-list.mjs +240 -105
- package/fesm2020/ngdux-list.mjs.map +1 -1
- package/index.d.ts +9 -7
- package/lib/+state/effects.d.ts +14 -0
- package/lib/+state/state.service.d.ts +22 -0
- package/lib/models/list.model.d.ts +18 -6
- 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 +9 -11
- package/lib/{+state → state-generator}/abstract-list-state.service.d.ts +7 -7
- package/lib/{+state → state-generator}/abstract-list.facade.d.ts +20 -17
- package/lib/{+state → state-generator}/list-reducer.d.ts +2 -2
- package/lib/state-generator/list-selectors.d.ts +4 -0
- package/lib/{+state → state-generator}/list-state.d.ts +4 -4
- package/package.json +29 -13
- 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/lib/+state/list-selectors.d.ts +0 -4
- /package/lib/{+state → state-generator}/list-actions.d.ts +0 -0
package/fesm2015/ngdux-list.mjs
CHANGED
|
@@ -1,116 +1,55 @@
|
|
|
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';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.service = service;
|
|
18
|
-
this.listActions = listActions;
|
|
19
|
-
this.listSelectors = listSelectors;
|
|
20
|
-
this.notificationService = notificationService;
|
|
21
|
-
this.texts = {
|
|
22
|
-
deleteConfirmationTitle: 'Delete resources',
|
|
23
|
-
deleteConfirmationMessage: 'Are you sure to delete the selected resources?'
|
|
24
|
-
};
|
|
25
|
-
this.reload$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.changePageSize, this.listActions.changeSorting, this.listActions.changeFiltering, this.listActions.changeRequestParams, this.listActions.initialize, this.listActions.reset, this.listActions.changePageNumber, this.listActions.patchSuccess, this.listActions.deleteSuccess), map(() => this.listActions.loadPage())));
|
|
26
|
-
this.loadFirstPage$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadFirstPage), map(() => this.listActions.changePageNumber({ pageNumber: 1 }))));
|
|
27
|
-
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 }))));
|
|
28
|
-
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 }))));
|
|
29
|
-
this.changePagingOptions$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.changePagingOptions), withLatestFrom(this.store.pipe(select(this.listSelectors.getPagingOptions))), map(([action, pagingOptions]) => {
|
|
30
|
-
if (action.pagingOptions.pageSize !== pagingOptions.pageSize) {
|
|
31
|
-
return this.listActions.changePageSize({ pageSize: action.pagingOptions.pageSize });
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return this.listActions.changePageNumber({ pageNumber: action.pagingOptions.page });
|
|
35
|
-
}
|
|
36
|
-
})));
|
|
37
|
-
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))), concatMap(([, pagingOptions, sortingOptions, filteringOptions, requestParameters]) => {
|
|
38
|
-
return this.service
|
|
39
|
-
.loadResources({
|
|
40
|
-
pagingOptions,
|
|
41
|
-
sortingOptions,
|
|
42
|
-
filteringOptions,
|
|
43
|
-
requestParameters
|
|
44
|
-
})
|
|
45
|
-
.pipe(map(resources => this.listActions.loadPageSuccess({
|
|
46
|
-
resources,
|
|
47
|
-
pagingOptions
|
|
48
|
-
})), catchError((errors) => of(this.listActions.loadPageFailure({ errors }))));
|
|
49
|
-
})));
|
|
50
|
-
this.patch$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.patch), exhaustMap(action => {
|
|
51
|
-
if (!this.service.patchResources) {
|
|
52
|
-
throw new Error('patchResources not implement in the ListService');
|
|
53
|
-
}
|
|
54
|
-
return this.service.patchResources(action.resourceIds, action.resource).pipe(map(resources => this.listActions.patchSuccess({ resources })), catchError((errors) => of(this.listActions.patchFailure({ errors }))));
|
|
55
|
-
})));
|
|
56
|
-
this.showRemovalsDialog$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.showRemovalsConfirmation), switchMap(() => {
|
|
57
|
-
var _a;
|
|
58
|
-
if ((_a = this.notificationService) === null || _a === void 0 ? void 0 : _a.openConfirmationDialog) {
|
|
59
|
-
return this.notificationService.openConfirmationDialog({
|
|
60
|
-
message: this.texts.deleteConfirmationMessage,
|
|
61
|
-
title: this.texts.deleteConfirmationTitle
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return of(true);
|
|
65
|
-
}), filter(confirmed => confirmed), withLatestFrom(this.store.pipe(select(this.listSelectors.getSelectedResourceIds))), map(([, resourceIds]) => this.listActions.delete({ resourceIds }))));
|
|
66
|
-
this.delete$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.delete), exhaustMap(({ resourceIds }) => {
|
|
67
|
-
if (!this.service.deleteResources) {
|
|
68
|
-
throw new Error('deleteResources not implement in the ListService');
|
|
69
|
-
}
|
|
70
|
-
return this.service.deleteResources(resourceIds).pipe(map(() => this.listActions.deleteSuccess({ resourceIds })), catchError((errors) => of(this.listActions.deleteFailure({ errors }))));
|
|
71
|
-
})));
|
|
72
|
-
this.deleteUsersSuccess$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.deleteSuccess), tap(({ resourceIds }) => {
|
|
73
|
-
var _a;
|
|
74
|
-
(_a = this.notificationService) === null || _a === void 0 ? void 0 : _a.onListDelete(resourceIds);
|
|
75
|
-
})), { dispatch: false });
|
|
76
|
-
this.errorsHandler$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadPageFailure, this.listActions.deleteFailure, this.listActions.patchFailure), tap(({ errors }) => {
|
|
77
|
-
var _a;
|
|
78
|
-
(_a = this.notificationService) === null || _a === void 0 ? void 0 : _a.onListErrors(errors);
|
|
79
|
-
})), { dispatch: false });
|
|
80
|
-
}
|
|
81
|
-
}
|
|
10
|
+
import { __decorate, __param, __metadata } from 'tslib';
|
|
11
|
+
import * as i2 from '@ngrx/effects';
|
|
12
|
+
import { createEffect, ofType, Actions } from '@ngrx/effects';
|
|
13
|
+
import { of } from 'rxjs';
|
|
14
|
+
import { map, withLatestFrom, filter, switchMap, catchError, exhaustMap, tap } from 'rxjs/operators';
|
|
82
15
|
|
|
83
16
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
84
|
-
const LIST_FEATURE_KEY = new InjectionToken('LIST_FEATURE_KEY');
|
|
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');
|
|
85
21
|
|
|
86
22
|
function createListActions(featureName) {
|
|
87
|
-
const resetRequestState = createAction(`[${featureName}
|
|
88
|
-
const initialize = createAction(`[${featureName}
|
|
89
|
-
const reset = createAction(`[Organization ${featureName}
|
|
90
|
-
const loadNextPage = createAction(`[${featureName}
|
|
91
|
-
const loadPreviousPage = createAction(`[${featureName}
|
|
92
|
-
const loadFirstPage = createAction(`[${featureName}
|
|
93
|
-
const setPageSize = createAction(`[${featureName}
|
|
94
|
-
const setSorting = createAction(`[${featureName}
|
|
95
|
-
const setFiltering = createAction(`[${featureName}
|
|
96
|
-
const setRequestParams = createAction(`[${featureName}
|
|
97
|
-
const changePageSize = createAction(`[${featureName}
|
|
98
|
-
const changePageNumber = createAction(`[${featureName}
|
|
99
|
-
const changePagingOptions = createAction(`[${featureName}
|
|
100
|
-
const changeSorting = createAction(`[${featureName}
|
|
101
|
-
const changeFiltering = createAction(`[${featureName}
|
|
102
|
-
const changeSelectedResources = createAction(`[${featureName}
|
|
103
|
-
const changeRequestParams = createAction(`[${featureName}
|
|
104
|
-
const loadPage = createAction(`[${featureName}
|
|
105
|
-
const loadPageSuccess = createAction(`[${featureName}
|
|
106
|
-
const loadPageFailure = createAction(`[${featureName}
|
|
107
|
-
const deleteAction = createAction(`[${featureName}
|
|
108
|
-
const deleteSuccess = createAction(`[${featureName}
|
|
109
|
-
const deleteFailure = createAction(`[${featureName}
|
|
110
|
-
const patch = createAction(`[${featureName}
|
|
111
|
-
const patchSuccess = createAction(`[${featureName}
|
|
112
|
-
const patchFailure = createAction(`[${featureName}
|
|
113
|
-
|
|
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
|
+
* @deprecated The method will be removed. The AbstractEffect will not be responsible for it anymore
|
|
51
|
+
*/
|
|
52
|
+
const showRemovalsConfirmation = createAction(`[${featureName} API] Show ${featureName} Removal Confirmation`);
|
|
114
53
|
return {
|
|
115
54
|
initialize,
|
|
116
55
|
reset,
|
|
@@ -152,7 +91,7 @@ function createListReducer(entityAdapter, actions, actionHandlers, initialListSt
|
|
|
152
91
|
return createReducer(initialState, ...createListActionHandlers(initialState, entityAdapter, actions), ...(actionHandlers || []));
|
|
153
92
|
}
|
|
154
93
|
function createInitialListState(entityAdapter) {
|
|
155
|
-
return entityAdapter.getInitialState(Object.assign(Object.assign({},
|
|
94
|
+
return entityAdapter.getInitialState(Object.assign(Object.assign({}, getDefaultRequestOptions()), { lastPageNumber: undefined, selectedResourceIds: [], loadingState: RequestState.IDLE, requestState: RequestState.IDLE, errors: undefined }));
|
|
156
95
|
}
|
|
157
96
|
function createListActionHandlers(initialListState, entityAdapter, actions) {
|
|
158
97
|
return [
|
|
@@ -160,6 +99,7 @@ function createListActionHandlers(initialListState, entityAdapter, actions) {
|
|
|
160
99
|
on(actions.initialize, (state) => entityAdapter.removeAll(Object.assign(Object.assign({}, state), { selectedResourceIds: [], pagingOptions: Object.assign(Object.assign({}, state.pagingOptions), { page: DEFAULT_PAGE }), requestState: RequestState.IDLE }))),
|
|
161
100
|
on(actions.changePageSize, actions.setPageSize, (state, { pageSize }) => (Object.assign(Object.assign({}, state), { pagingOptions: { page: DEFAULT_PAGE, pageSize }, lastPageNumber: undefined }))),
|
|
162
101
|
on(actions.changePageNumber, (state, { pageNumber }) => (Object.assign(Object.assign({}, state), { pagingOptions: Object.assign(Object.assign({}, state.pagingOptions), { page: pageNumber }) }))),
|
|
102
|
+
on(actions.changePagingOptions, (state, { pagingOptions }) => (Object.assign(Object.assign({}, state), { pagingOptions }))),
|
|
163
103
|
on(actions.changeSorting, actions.setSorting, (state, { sortingOptions }) => (Object.assign(Object.assign({}, state), { sortingOptions, pagingOptions: Object.assign(Object.assign({}, state.pagingOptions), { page: DEFAULT_PAGE }) }))),
|
|
164
104
|
on(actions.changeFiltering, actions.setFiltering, (state, { filteringOptions }) => (Object.assign(Object.assign({}, state), { filteringOptions, pagingOptions: Object.assign(Object.assign({}, state.pagingOptions), { page: DEFAULT_PAGE }), lastPageNumber: undefined }))),
|
|
165
105
|
on(actions.changeRequestParams, actions.setRequestParams, (state, { params }) => (Object.assign(Object.assign({}, state), { requestParameters: params, pagingOptions: Object.assign(Object.assign({}, state.pagingOptions), { page: DEFAULT_PAGE }) }))),
|
|
@@ -257,6 +197,196 @@ function createListSelectors(entityAdapter, getListState) {
|
|
|
257
197
|
};
|
|
258
198
|
}
|
|
259
199
|
|
|
200
|
+
class ListStateService {
|
|
201
|
+
constructor(reducerManager, featureKeys) {
|
|
202
|
+
this.reducerManager = reducerManager;
|
|
203
|
+
this.actions = {};
|
|
204
|
+
this.selectors = {};
|
|
205
|
+
this.entityAdapter = this.getEntityAdapter();
|
|
206
|
+
featureKeys.forEach(featureKey => {
|
|
207
|
+
if (!this.actions[featureKey]) {
|
|
208
|
+
this.actions[featureKey] = this.getActions(featureKey);
|
|
209
|
+
this.addReducer(featureKey, this.actions[featureKey]);
|
|
210
|
+
this.selectors[featureKey] = this.getSelectors(featureKey);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
getActions(featureKey) {
|
|
215
|
+
return createListActions(featureKey);
|
|
216
|
+
}
|
|
217
|
+
getEntityAdapter() {
|
|
218
|
+
return createListEntityAdapter();
|
|
219
|
+
}
|
|
220
|
+
addReducer(featureKey, actions) {
|
|
221
|
+
const currentReducers = Object.keys(this.reducerManager.currentReducers || {});
|
|
222
|
+
if (!currentReducers.includes(featureKey)) {
|
|
223
|
+
const reducer = createListReducer(this.entityAdapter, actions);
|
|
224
|
+
this.reducerManager.addReducer(featureKey, reducer);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
getSelectors(featureKey) {
|
|
228
|
+
const getState = createFeatureSelector(featureKey);
|
|
229
|
+
return createListSelectors(this.entityAdapter, getState);
|
|
230
|
+
}
|
|
231
|
+
getFeatureActions(featureKey) {
|
|
232
|
+
return this.actions[featureKey];
|
|
233
|
+
}
|
|
234
|
+
getFeatureSelectors(featureKey) {
|
|
235
|
+
return this.selectors[featureKey];
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
ListStateService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ListStateService, deps: [{ token: i1.ReducerManager }, { token: LIST_FEATURE_KEYS }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
239
|
+
ListStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ListStateService });
|
|
240
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ListStateService, decorators: [{
|
|
241
|
+
type: Injectable
|
|
242
|
+
}], ctorParameters: function () {
|
|
243
|
+
return [{ type: i1.ReducerManager }, { type: undefined, decorators: [{
|
|
244
|
+
type: Inject,
|
|
245
|
+
args: [LIST_FEATURE_KEYS]
|
|
246
|
+
}] }];
|
|
247
|
+
} });
|
|
248
|
+
|
|
249
|
+
class AbstractListEffects {
|
|
250
|
+
constructor(actions$, store, service, listActions, listSelectors, notificationService) {
|
|
251
|
+
this.actions$ = actions$;
|
|
252
|
+
this.store = store;
|
|
253
|
+
this.service = service;
|
|
254
|
+
this.listActions = listActions;
|
|
255
|
+
this.listSelectors = listSelectors;
|
|
256
|
+
this.notificationService = notificationService;
|
|
257
|
+
this.texts = {
|
|
258
|
+
deleteConfirmationTitle: 'Delete resources',
|
|
259
|
+
deleteConfirmationMessage: 'Are you sure to delete the selected resources?'
|
|
260
|
+
};
|
|
261
|
+
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())));
|
|
262
|
+
this.loadFirstPage$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadFirstPage), map(() => this.listActions.changePageNumber({ pageNumber: 1 }))));
|
|
263
|
+
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 }))));
|
|
264
|
+
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 }))));
|
|
265
|
+
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]) => {
|
|
266
|
+
return this.service
|
|
267
|
+
.loadResources({
|
|
268
|
+
pagingOptions,
|
|
269
|
+
sortingOptions,
|
|
270
|
+
filteringOptions,
|
|
271
|
+
requestParameters
|
|
272
|
+
})
|
|
273
|
+
.pipe(map(resources => this.listActions.loadPageSuccess({
|
|
274
|
+
resources,
|
|
275
|
+
pagingOptions
|
|
276
|
+
})), catchError((errors) => of(this.listActions.loadPageFailure({ errors }))));
|
|
277
|
+
})));
|
|
278
|
+
this.patch$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.patch), exhaustMap(action => {
|
|
279
|
+
if (!this.service.patchResources) {
|
|
280
|
+
throw new Error('patchResources not implement in the ListService');
|
|
281
|
+
}
|
|
282
|
+
return this.service.patchResources(action.resourceIds, action.resource).pipe(map(resources => this.listActions.patchSuccess({ resources })), catchError((errors) => of(this.listActions.patchFailure({ errors }))));
|
|
283
|
+
})));
|
|
284
|
+
/**
|
|
285
|
+
* @deprecated The method will be removed. THe AbstractEffect will not be responsible for it anymore
|
|
286
|
+
*/
|
|
287
|
+
this.showRemovalsDialog$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.showRemovalsConfirmation), switchMap(() => {
|
|
288
|
+
var _a;
|
|
289
|
+
if ((_a = this.notificationService) === null || _a === void 0 ? void 0 : _a.openConfirmationDialog) {
|
|
290
|
+
return this.notificationService.openConfirmationDialog({
|
|
291
|
+
message: this.texts.deleteConfirmationMessage,
|
|
292
|
+
title: this.texts.deleteConfirmationTitle
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
return of(true);
|
|
296
|
+
}), filter(confirmed => confirmed), withLatestFrom(this.store.pipe(select(this.listSelectors.getSelectedResourceIds))), filter(([, resourceIds]) => !!resourceIds.length), map(([, resourceIds]) => this.listActions.delete({ resourceIds }))));
|
|
297
|
+
this.delete$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.delete), exhaustMap(({ resourceIds }) => {
|
|
298
|
+
if (!this.service.deleteResources) {
|
|
299
|
+
throw new Error('deleteResources not implement in the ListService');
|
|
300
|
+
}
|
|
301
|
+
return this.service.deleteResources(resourceIds).pipe(map(() => this.listActions.deleteSuccess({ resourceIds })), catchError((errors) => of(this.listActions.deleteFailure({ errors }))));
|
|
302
|
+
})));
|
|
303
|
+
this.deleteSuccess$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.deleteSuccess), tap(({ resourceIds }) => {
|
|
304
|
+
var _a;
|
|
305
|
+
(_a = this.notificationService) === null || _a === void 0 ? void 0 : _a.onListDelete(resourceIds);
|
|
306
|
+
})), { dispatch: false });
|
|
307
|
+
this.errorsHandler$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadPageFailure, this.listActions.deleteFailure, this.listActions.patchFailure), tap(({ errors }) => {
|
|
308
|
+
var _a;
|
|
309
|
+
(_a = this.notificationService) === null || _a === void 0 ? void 0 : _a.onListErrors(errors);
|
|
310
|
+
})), { dispatch: false });
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
let ListEffects = class ListEffects extends AbstractListEffects {
|
|
315
|
+
constructor(actions$, store, listStateService, featureKey, service, notificationService) {
|
|
316
|
+
super(actions$, store, service, listStateService.getFeatureActions(featureKey), listStateService.getFeatureSelectors(featureKey), notificationService);
|
|
317
|
+
this.featureKey = featureKey;
|
|
318
|
+
}
|
|
319
|
+
ngrxOnIdentifyEffects() {
|
|
320
|
+
return this.featureKey;
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
ListEffects = __decorate([
|
|
324
|
+
__param(5, Optional()),
|
|
325
|
+
__metadata("design:paramtypes", [Actions,
|
|
326
|
+
Store,
|
|
327
|
+
ListStateService, String, Object, Object])
|
|
328
|
+
], ListEffects);
|
|
329
|
+
|
|
330
|
+
class NotificationServicePlaceholder {
|
|
331
|
+
onListErrors(errors) {
|
|
332
|
+
console.error('ERROR', errors);
|
|
333
|
+
}
|
|
334
|
+
onListDelete(ids) {
|
|
335
|
+
console.log(`Resources ${ids.join(', ')} have been deleted.`);
|
|
336
|
+
}
|
|
337
|
+
openConfirmationDialog(data) {
|
|
338
|
+
console.log(data.title, data.message);
|
|
339
|
+
return of(true);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
NotificationServicePlaceholder.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NotificationServicePlaceholder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
343
|
+
NotificationServicePlaceholder.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NotificationServicePlaceholder });
|
|
344
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NotificationServicePlaceholder, decorators: [{
|
|
345
|
+
type: Injectable
|
|
346
|
+
}] });
|
|
347
|
+
|
|
348
|
+
class NgduxListStateModule {
|
|
349
|
+
constructor(registerEffectsService, actions$, store, listStateService, featureKeys, services, notificationServices) {
|
|
350
|
+
featureKeys.forEach((featureKey, index) => {
|
|
351
|
+
const listEffects = new ListEffects(actions$, store, listStateService, featureKey, services[index], notificationServices[index]);
|
|
352
|
+
registerEffectsService.registerEffects([listEffects]);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
static config(config) {
|
|
356
|
+
return {
|
|
357
|
+
ngModule: NgduxListStateModule,
|
|
358
|
+
providers: [
|
|
359
|
+
{ provide: LIST_SERVICES, multi: true, useClass: config.service },
|
|
360
|
+
{
|
|
361
|
+
provide: LIST_NOTIFICATION_SERVICES,
|
|
362
|
+
multi: true,
|
|
363
|
+
useClass: config.notificationService || NotificationServicePlaceholder
|
|
364
|
+
}
|
|
365
|
+
]
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
NgduxListStateModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", 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 });
|
|
370
|
+
NgduxListStateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: NgduxListStateModule });
|
|
371
|
+
NgduxListStateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NgduxListStateModule, providers: [ListStateService] });
|
|
372
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NgduxListStateModule, decorators: [{
|
|
373
|
+
type: NgModule,
|
|
374
|
+
args: [{
|
|
375
|
+
providers: [ListStateService]
|
|
376
|
+
}]
|
|
377
|
+
}], ctorParameters: function () {
|
|
378
|
+
return [{ type: i1$1.RegisterEffectsService }, { type: i2.Actions }, { type: i1.Store }, { type: ListStateService }, { type: undefined, decorators: [{
|
|
379
|
+
type: Inject,
|
|
380
|
+
args: [LIST_FEATURE_KEYS]
|
|
381
|
+
}] }, { type: undefined, decorators: [{
|
|
382
|
+
type: Inject,
|
|
383
|
+
args: [LIST_SERVICES]
|
|
384
|
+
}] }, { type: undefined, decorators: [{
|
|
385
|
+
type: Inject,
|
|
386
|
+
args: [LIST_NOTIFICATION_SERVICES]
|
|
387
|
+
}] }];
|
|
388
|
+
} });
|
|
389
|
+
|
|
260
390
|
class AbstractListReducerManager {
|
|
261
391
|
constructor(reducerManager, featureKey) {
|
|
262
392
|
this.reducerManager = reducerManager;
|
|
@@ -377,6 +507,9 @@ class AbstractListFacade {
|
|
|
377
507
|
resetRequestState() {
|
|
378
508
|
this.store.dispatch(this.listActions.resetRequestState());
|
|
379
509
|
}
|
|
510
|
+
/**
|
|
511
|
+
* @deprecated The method will be removed. The AbstractFacade will not be responsible for it anymore
|
|
512
|
+
*/
|
|
380
513
|
showRemovalsConfirmation() {
|
|
381
514
|
this.store.dispatch(this.listActions.showRemovalsConfirmation());
|
|
382
515
|
}
|
|
@@ -400,5 +533,5 @@ function createListState(featureName, idKey) {
|
|
|
400
533
|
* Generated bundle index. Do not edit.
|
|
401
534
|
*/
|
|
402
535
|
|
|
403
|
-
export { AbstractListEffects, AbstractListFacade, AbstractListReducerManager, LIST_FEATURE_KEY, createListActions, createListEntityAdapter, createListReducer, createListSelectors, createListState };
|
|
536
|
+
export { AbstractListEffects, AbstractListFacade, AbstractListReducerManager, LIST_FEATURE_KEY, LIST_FEATURE_KEYS, LIST_NOTIFICATION_SERVICES, LIST_SERVICES, ListStateService, NgduxListStateModule, createListActions, createListEntityAdapter, createListReducer, createListSelectors, createListState };
|
|
404
537
|
//# sourceMappingURL=ngdux-list.mjs.map
|