@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.
Files changed (39) hide show
  1. package/esm2020/index.mjs +10 -8
  2. package/esm2020/lib/+state/effects.mjs +23 -0
  3. package/esm2020/lib/+state/state.service.mjs +55 -0
  4. package/esm2020/lib/models/list.model.mjs +4 -1
  5. package/esm2020/lib/ngdux-list-state.module.mjs +53 -0
  6. package/esm2020/lib/services/list-notification-service.mjs +21 -0
  7. package/esm2020/lib/state-generator/abstract-list-effects.mjs +66 -0
  8. package/esm2020/lib/state-generator/abstract-list-state.service.mjs +44 -0
  9. package/esm2020/lib/state-generator/abstract-list.facade.mjs +91 -0
  10. package/esm2020/lib/state-generator/list-actions.mjs +63 -0
  11. package/esm2020/lib/state-generator/list-reducer.mjs +104 -0
  12. package/esm2020/lib/state-generator/list-selectors.mjs +80 -0
  13. package/esm2020/lib/state-generator/list-state.mjs +18 -0
  14. package/fesm2015/ngdux-list.mjs +240 -107
  15. package/fesm2015/ngdux-list.mjs.map +1 -1
  16. package/fesm2020/ngdux-list.mjs +240 -105
  17. package/fesm2020/ngdux-list.mjs.map +1 -1
  18. package/index.d.ts +9 -7
  19. package/lib/+state/effects.d.ts +14 -0
  20. package/lib/+state/state.service.d.ts +22 -0
  21. package/lib/models/list.model.d.ts +18 -6
  22. package/lib/ngdux-list-state.module.d.ts +23 -0
  23. package/lib/services/list-notification-service.d.ts +13 -0
  24. package/lib/{+state → state-generator}/abstract-list-effects.d.ts +9 -11
  25. package/lib/{+state → state-generator}/abstract-list-state.service.d.ts +7 -7
  26. package/lib/{+state → state-generator}/abstract-list.facade.d.ts +20 -17
  27. package/lib/{+state → state-generator}/list-reducer.d.ts +2 -2
  28. package/lib/state-generator/list-selectors.d.ts +4 -0
  29. package/lib/{+state → state-generator}/list-state.d.ts +4 -4
  30. package/package.json +29 -13
  31. package/esm2020/lib/+state/abstract-list-effects.mjs +0 -71
  32. package/esm2020/lib/+state/abstract-list-state.service.mjs +0 -44
  33. package/esm2020/lib/+state/abstract-list.facade.mjs +0 -88
  34. package/esm2020/lib/+state/list-actions.mjs +0 -60
  35. package/esm2020/lib/+state/list-reducer.mjs +0 -97
  36. package/esm2020/lib/+state/list-selectors.mjs +0 -80
  37. package/esm2020/lib/+state/list-state.mjs +0 -18
  38. package/lib/+state/list-selectors.d.ts +0 -4
  39. /package/lib/{+state → state-generator}/list-actions.d.ts +0 -0
@@ -1,113 +1,55 @@
1
- import { DEFAULT_REQUEST_OPTIONS, RequestState, DEFAULT_PAGE } from '@ngdux/data-model-common';
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
- class AbstractListEffects {
14
- constructor(actions$, store, service, listActions, listSelectors, notificationService) {
15
- this.actions$ = actions$;
16
- this.store = store;
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
- if (this.notificationService?.openConfirmationDialog) {
58
- return this.notificationService.openConfirmationDialog({
59
- message: this.texts.deleteConfirmationMessage,
60
- title: this.texts.deleteConfirmationTitle
61
- });
62
- }
63
- return of(true);
64
- }), filter(confirmed => confirmed), withLatestFrom(this.store.pipe(select(this.listSelectors.getSelectedResourceIds))), map(([, resourceIds]) => this.listActions.delete({ resourceIds }))));
65
- this.delete$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.delete), exhaustMap(({ resourceIds }) => {
66
- if (!this.service.deleteResources) {
67
- throw new Error('deleteResources not implement in the ListService');
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
- }
78
- }
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';
79
15
 
80
16
  /* eslint-disable @typescript-eslint/ban-types */
81
- 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');
82
21
 
83
22
  function createListActions(featureName) {
84
- const resetRequestState = createAction(`[${featureName} Page] Reset ${featureName} Request State`);
85
- const initialize = createAction(`[${featureName} Page] Initialize ${featureName}`);
86
- const reset = createAction(`[Organization ${featureName} Page] Reset ${featureName}`);
87
- const loadNextPage = createAction(`[${featureName} Page] Load Next ${featureName} Page`);
88
- const loadPreviousPage = createAction(`[${featureName} Page] Load Previous ${featureName} Page`);
89
- const loadFirstPage = createAction(`[${featureName} Page] Load First ${featureName} Page`);
90
- const setPageSize = createAction(`[${featureName} Page] Set ${featureName} Page Size`, props());
91
- const setSorting = createAction(`[${featureName} Page] Set ${featureName} Sorting`, props());
92
- const setFiltering = createAction(`[${featureName} Page] Set ${featureName} Filtering`, props());
93
- const setRequestParams = createAction(`[${featureName} Page] Set ${featureName} Request Params`, props());
94
- const changePageSize = createAction(`[${featureName} Page] Change ${featureName} Page Size`, props());
95
- const changePageNumber = createAction(`[${featureName} Page] Change ${featureName} Page Number`, props());
96
- const changePagingOptions = createAction(`[${featureName} Page] Change ${featureName} Page Options`, props());
97
- const changeSorting = createAction(`[${featureName} Page] Change ${featureName} Sorting`, props());
98
- const changeFiltering = createAction(`[${featureName} Page] Change ${featureName} Filtering`, props());
99
- const changeSelectedResources = createAction(`[${featureName} Page] Change Selected Resources ${featureName}`, props());
100
- const changeRequestParams = createAction(`[${featureName} Page] Change ${featureName} Request Params`, props());
101
- const loadPage = createAction(`[${featureName} Page] Load ${featureName} Page`);
102
- const loadPageSuccess = createAction(`[${featureName} Page] Load ${featureName} Page Success`, props());
103
- const loadPageFailure = createAction(`[${featureName} Page] Load ${featureName} Page Failure`, props());
104
- const deleteAction = createAction(`[${featureName} Page] Delete ${featureName}`, props());
105
- const deleteSuccess = createAction(`[${featureName} Page] Delete ${featureName} Success`, props());
106
- const deleteFailure = createAction(`[${featureName} Page] Delete ${featureName} Failure`, props());
107
- const patch = createAction(`[${featureName} Page] Patch ${featureName}`, props());
108
- const patchSuccess = createAction(`[${featureName} Page] Patch ${featureName} Success`, props());
109
- const patchFailure = createAction(`[${featureName} Page] Patch ${featureName} Failure`, props());
110
- const showRemovalsConfirmation = createAction(`[${featureName} Page] Show ${featureName} Removal Confirmation`);
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`);
111
53
  return {
112
54
  initialize,
113
55
  reset,
@@ -145,12 +87,15 @@ function createListEntityAdapter(idKey = 'id') {
145
87
  });
146
88
  }
147
89
  function createListReducer(entityAdapter, actions, actionHandlers, initialListState) {
148
- const initialState = { ...createInitialListState(entityAdapter), ...initialListState };
90
+ const initialState = {
91
+ ...createInitialListState(entityAdapter),
92
+ ...initialListState
93
+ };
149
94
  return createReducer(initialState, ...createListActionHandlers(initialState, entityAdapter, actions), ...(actionHandlers || []));
150
95
  }
151
96
  function createInitialListState(entityAdapter) {
152
97
  return entityAdapter.getInitialState({
153
- ...DEFAULT_REQUEST_OPTIONS,
98
+ ...getDefaultRequestOptions(),
154
99
  lastPageNumber: undefined,
155
100
  selectedResourceIds: [],
156
101
  loadingState: RequestState.IDLE,
@@ -179,6 +124,10 @@ function createListActionHandlers(initialListState, entityAdapter, actions) {
179
124
  ...state,
180
125
  pagingOptions: { ...state.pagingOptions, page: pageNumber }
181
126
  })),
127
+ on(actions.changePagingOptions, (state, { pagingOptions }) => ({
128
+ ...state,
129
+ pagingOptions
130
+ })),
182
131
  on(actions.changeSorting, actions.setSorting, (state, { sortingOptions }) => ({
183
132
  ...state,
184
133
  sortingOptions,
@@ -310,6 +259,189 @@ function createListSelectors(entityAdapter, getListState) {
310
259
  };
311
260
  }
312
261
 
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
+ 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 });
301
+ ListStateService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ListStateService });
302
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: ListStateService, decorators: [{
303
+ type: Injectable
304
+ }], ctorParameters: function () { return [{ type: i1.ReducerManager }, { type: undefined, decorators: [{
305
+ type: Inject,
306
+ args: [LIST_FEATURE_KEYS]
307
+ }] }]; } });
308
+
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.texts = {
318
+ deleteConfirmationTitle: 'Delete resources',
319
+ deleteConfirmationMessage: 'Are you sure to delete the selected resources?'
320
+ };
321
+ 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())));
322
+ this.loadFirstPage$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.loadFirstPage), map(() => this.listActions.changePageNumber({ pageNumber: 1 }))));
323
+ 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 }))));
324
+ 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 }))));
325
+ 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]) => {
326
+ return this.service
327
+ .loadResources({
328
+ pagingOptions,
329
+ sortingOptions,
330
+ filteringOptions,
331
+ requestParameters
332
+ })
333
+ .pipe(map(resources => this.listActions.loadPageSuccess({
334
+ resources,
335
+ pagingOptions
336
+ })), catchError((errors) => of(this.listActions.loadPageFailure({ errors }))));
337
+ })));
338
+ this.patch$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.patch), exhaustMap(action => {
339
+ if (!this.service.patchResources) {
340
+ throw new Error('patchResources not implement in the ListService');
341
+ }
342
+ return this.service.patchResources(action.resourceIds, action.resource).pipe(map(resources => this.listActions.patchSuccess({ resources })), catchError((errors) => of(this.listActions.patchFailure({ errors }))));
343
+ })));
344
+ /**
345
+ * @deprecated The method will be removed. THe AbstractEffect will not be responsible for it anymore
346
+ */
347
+ this.showRemovalsDialog$ = createEffect(() => this.actions$.pipe(ofType(this.listActions.showRemovalsConfirmation), switchMap(() => {
348
+ if (this.notificationService?.openConfirmationDialog) {
349
+ return this.notificationService.openConfirmationDialog({
350
+ message: this.texts.deleteConfirmationMessage,
351
+ title: this.texts.deleteConfirmationTitle
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
+ }
369
+ }
370
+
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])
385
+ ], ListEffects);
386
+
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
+ NotificationServicePlaceholder.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NotificationServicePlaceholder, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
400
+ NotificationServicePlaceholder.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NotificationServicePlaceholder });
401
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NotificationServicePlaceholder, decorators: [{
402
+ type: Injectable
403
+ }] });
404
+
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
+ 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 });
427
+ NgduxListStateModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.9", ngImport: i0, type: NgduxListStateModule });
428
+ NgduxListStateModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NgduxListStateModule, providers: [ListStateService] });
429
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImport: i0, type: NgduxListStateModule, decorators: [{
430
+ type: NgModule,
431
+ args: [{
432
+ providers: [ListStateService]
433
+ }]
434
+ }], ctorParameters: function () { return [{ type: i1$1.RegisterEffectsService }, { type: i2.Actions }, { type: i1.Store }, { type: ListStateService }, { type: undefined, decorators: [{
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
+ }] }]; } });
444
+
313
445
  class AbstractListReducerManager {
314
446
  constructor(reducerManager, featureKey) {
315
447
  this.reducerManager = reducerManager;
@@ -428,6 +560,9 @@ class AbstractListFacade {
428
560
  resetRequestState() {
429
561
  this.store.dispatch(this.listActions.resetRequestState());
430
562
  }
563
+ /**
564
+ * @deprecated The method will be removed. The AbstractFacade will not be responsible for it anymore
565
+ */
431
566
  showRemovalsConfirmation() {
432
567
  this.store.dispatch(this.listActions.showRemovalsConfirmation());
433
568
  }
@@ -451,5 +586,5 @@ function createListState(featureName, idKey) {
451
586
  * Generated bundle index. Do not edit.
452
587
  */
453
588
 
454
- export { AbstractListEffects, AbstractListFacade, AbstractListReducerManager, LIST_FEATURE_KEY, createListActions, createListEntityAdapter, createListReducer, createListSelectors, createListState };
589
+ export { AbstractListEffects, AbstractListFacade, AbstractListReducerManager, LIST_FEATURE_KEY, LIST_FEATURE_KEYS, LIST_NOTIFICATION_SERVICES, LIST_SERVICES, ListStateService, NgduxListStateModule, createListActions, createListEntityAdapter, createListReducer, createListSelectors, createListState };
455
590
  //# sourceMappingURL=ngdux-list.mjs.map