@ngrx-traits/common 12.1.0 → 12.2.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/async-action/async-action.trait.d.ts +7 -2
- package/bundles/ngrx-traits-common.umd.js +160 -92
- package/bundles/ngrx-traits-common.umd.js.map +1 -1
- package/crud-entities/crud-entities.trait.d.ts +6 -2
- package/entities-pagination/entities-pagination.trait.d.ts +26 -12
- package/entities-pagination/entities-pagination.trait.reducer.d.ts +3 -2
- package/esm2015/async-action/async-action.trait.js +7 -2
- package/esm2015/async-action/async-action.trait.js.map +1 -1
- package/esm2015/crud-entities/crud-entities.trait.js +6 -2
- package/esm2015/crud-entities/crud-entities.trait.js.map +1 -1
- package/esm2015/entities-pagination/entities-pagination.trait.effects.js +3 -3
- package/esm2015/entities-pagination/entities-pagination.trait.effects.js.map +1 -1
- package/esm2015/entities-pagination/entities-pagination.trait.js +27 -13
- package/esm2015/entities-pagination/entities-pagination.trait.js.map +1 -1
- package/esm2015/entities-pagination/entities-pagination.trait.reducer.js +1 -1
- package/esm2015/entities-pagination/entities-pagination.trait.reducer.js.map +1 -1
- package/esm2015/filter-entities/filter-entities.trait.effect.js +3 -3
- package/esm2015/filter-entities/filter-entities.trait.effect.js.map +1 -1
- package/esm2015/filter-entities/filter-entities.trait.js +7 -2
- package/esm2015/filter-entities/filter-entities.trait.js.map +1 -1
- package/esm2015/load-entities/load-entities.trait.js +15 -10
- package/esm2015/load-entities/load-entities.trait.js.map +1 -1
- package/esm2015/load-entity/load-entity.traits.js +12 -6
- package/esm2015/load-entity/load-entity.traits.js.map +1 -1
- package/esm2015/reset/reset.trait.js +24 -21
- package/esm2015/reset/reset.trait.js.map +1 -1
- package/esm2015/select-entities/select-entities.trait.js +6 -2
- package/esm2015/select-entities/select-entities.trait.js.map +1 -1
- package/esm2015/select-entity/select-entity.trait.js +6 -2
- package/esm2015/select-entity/select-entity.trait.js.map +1 -1
- package/esm2015/set-entity/set-entity.trait.js +6 -3
- package/esm2015/set-entity/set-entity.trait.js.map +1 -1
- package/esm2015/sort-entities/sort-entities.model.js.map +1 -1
- package/esm2015/sort-entities/sort-entities.trait.effect.js +3 -3
- package/esm2015/sort-entities/sort-entities.trait.effect.js.map +1 -1
- package/esm2015/sort-entities/sort-entities.trait.js +11 -5
- package/esm2015/sort-entities/sort-entities.trait.js.map +1 -1
- package/esm2015/sort-entities/sort-entities.utils.js +2 -0
- package/esm2015/sort-entities/sort-entities.utils.js.map +1 -1
- package/fesm2015/ngrx-traits-common.js +140 -79
- package/fesm2015/ngrx-traits-common.js.map +1 -1
- package/filter-entities/filter-entities.trait.d.ts +7 -2
- package/load-entities/load-entities.trait.d.ts +15 -10
- package/load-entity/load-entity.traits.d.ts +12 -6
- package/package.json +2 -2
- package/reset/reset.trait.d.ts +3 -2
- package/select-entities/select-entities.trait.d.ts +6 -2
- package/select-entity/select-entity.trait.d.ts +6 -2
- package/set-entity/set-entity.trait.d.ts +6 -3
- package/sort-entities/sort-entities.model.d.ts +1 -1
- package/sort-entities/sort-entities.trait.d.ts +10 -4
- package/sort-entities/sort-entities.utils.d.ts +2 -0
|
@@ -3,7 +3,8 @@ import { ActionCreatorWithOptionalProps } from './async-action.model';
|
|
|
3
3
|
/**
|
|
4
4
|
* Generates the typical ngrx code need to make a async action with
|
|
5
5
|
* a request, success and failure actions, plus a status property to track its progress
|
|
6
|
-
* and selectors to query the status.
|
|
6
|
+
* and selectors to query the status. This trait can be added more thant once as long
|
|
7
|
+
* as the name prop is different.
|
|
7
8
|
*
|
|
8
9
|
* @param options - Config object for the trait factory
|
|
9
10
|
* @param options.name - Name of the main request action, should be in camel case
|
|
@@ -30,10 +31,14 @@ import { ActionCreatorWithOptionalProps } from './async-action.model';
|
|
|
30
31
|
* 'client',
|
|
31
32
|
* ),
|
|
32
33
|
* });
|
|
33
|
-
* //
|
|
34
|
+
* // adds following props to the state:
|
|
35
|
+
* // createClientStatus?: 'loading' | 'success' | 'fail';
|
|
36
|
+
*
|
|
37
|
+
* // generated actions
|
|
34
38
|
* traits.actions.createClient({name:'Pedro'})
|
|
35
39
|
* traits.actions.createClientSuccess({id:'123'})
|
|
36
40
|
* traits.actions.createClientFail();
|
|
41
|
+
* //generated selectors
|
|
37
42
|
* traits.selectors.isLoadingCreateClient
|
|
38
43
|
* traits.selectors.isSuccessCreateClient
|
|
39
44
|
* traits.selectors.isFailCreateClient
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ngrx/store'), require('@ngrx-traits/core'), require('@ngrx/entity'), require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@ngrx/effects')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define('@ngrx-traits/common', ['exports', '@ngrx/store', '@ngrx-traits/core', '@ngrx/entity', '@angular/core', 'rxjs', 'rxjs/operators', '@ngrx/effects'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global[
|
|
5
|
-
}(this, (function (exports, i2, core, entity, i0, rxjs, operators, i1) { 'use strict';
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global["ngrx-traits"] = global["ngrx-traits"] || {}, global["ngrx-traits"].common = {}), global.i2, global.core, global.entity, global.ng.core, global.rxjs, global.rxjs.operators, global.i1));
|
|
5
|
+
})(this, (function (exports, i2, core, entity, i0, rxjs, operators, i1) { 'use strict';
|
|
6
6
|
|
|
7
7
|
function _interopNamespace(e) {
|
|
8
8
|
if (e && e.__esModule) return e;
|
|
@@ -13,14 +13,12 @@
|
|
|
13
13
|
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
14
14
|
Object.defineProperty(n, k, d.get ? d : {
|
|
15
15
|
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return e[k];
|
|
18
|
-
}
|
|
16
|
+
get: function () { return e[k]; }
|
|
19
17
|
});
|
|
20
18
|
}
|
|
21
19
|
});
|
|
22
20
|
}
|
|
23
|
-
n[
|
|
21
|
+
n["default"] = e;
|
|
24
22
|
return Object.freeze(n);
|
|
25
23
|
}
|
|
26
24
|
|
|
@@ -30,7 +28,7 @@
|
|
|
30
28
|
|
|
31
29
|
var loadEntitiesTraitKey = 'loadEntities';
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
/******************************************************************************
|
|
34
32
|
Copyright (c) Microsoft Corporation.
|
|
35
33
|
|
|
36
34
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
@@ -192,7 +190,11 @@
|
|
|
192
190
|
var __createBinding = Object.create ? (function (o, m, k, k2) {
|
|
193
191
|
if (k2 === undefined)
|
|
194
192
|
k2 = k;
|
|
195
|
-
Object.
|
|
193
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
194
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
195
|
+
desc = { enumerable: true, get: function () { return m[k]; } };
|
|
196
|
+
}
|
|
197
|
+
Object.defineProperty(o, k2, desc);
|
|
196
198
|
}) : (function (o, m, k, k2) {
|
|
197
199
|
if (k2 === undefined)
|
|
198
200
|
k2 = k;
|
|
@@ -265,7 +267,7 @@
|
|
|
265
267
|
ar[i] = from[i];
|
|
266
268
|
}
|
|
267
269
|
}
|
|
268
|
-
return to.concat(ar || from);
|
|
270
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
269
271
|
}
|
|
270
272
|
function __await(v) {
|
|
271
273
|
return this instanceof __await ? (this.v = v, this) : new __await(v);
|
|
@@ -347,6 +349,11 @@
|
|
|
347
349
|
throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
348
350
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
349
351
|
}
|
|
352
|
+
function __classPrivateFieldIn(state, receiver) {
|
|
353
|
+
if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
|
|
354
|
+
throw new TypeError("Cannot use 'in' operator on non-object");
|
|
355
|
+
return typeof state === "function" ? receiver === state : state.has(receiver);
|
|
356
|
+
}
|
|
350
357
|
|
|
351
358
|
function createLoadEntitiesInitialState(previousInitialState, allConfigs) {
|
|
352
359
|
if (previousInitialState === void 0) { previousInitialState = {}; }
|
|
@@ -429,12 +436,10 @@
|
|
|
429
436
|
}
|
|
430
437
|
|
|
431
438
|
/**
|
|
432
|
-
* Generates the ngrx code needed to load a list of entities from the backend
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
436
|
-
* to a list of entities, the other will call loadEntities when needing data.
|
|
437
|
-
* @param traitConfig - Config object fot the trait factory
|
|
439
|
+
* Generates the ngrx code needed to load a list of entities from the backend. This trait is the base for all other traits related
|
|
440
|
+
* to a list of entities, the other will call loadEntities when needing data. See the example for the list of actions and selectors this generates
|
|
441
|
+
*
|
|
442
|
+
* @param traitConfig - Config object for the trait factory
|
|
438
443
|
* @param traitConfig.selectId - Function that returns the id of an entity
|
|
439
444
|
* @param traitConfig.sortComparer - Default sort function for to @ngrx/entity EntityAdapter
|
|
440
445
|
*
|
|
@@ -453,17 +458,24 @@
|
|
|
453
458
|
* 'todos',
|
|
454
459
|
* ),
|
|
455
460
|
* });
|
|
456
|
-
*
|
|
461
|
+
*
|
|
462
|
+
* // adds following props to the state:
|
|
463
|
+
* // ids: string[] | number[];
|
|
464
|
+
* // entities: Dictionary<Todo>;
|
|
465
|
+
* // status?: 'loading' | 'success' | 'fail';
|
|
466
|
+
*
|
|
467
|
+
* // generated actions
|
|
457
468
|
* traits.actions.loadTodos()
|
|
458
469
|
* traits.actions.loadTodosSuccess({entities: todos})
|
|
459
470
|
* traits.actions.loadTodosFail();
|
|
471
|
+
* // generated selectors
|
|
460
472
|
* traits.selectors.selectTodosList
|
|
461
473
|
* traits.selectors.selectTodosMap
|
|
462
474
|
* traits.selectors.selectTodosIds
|
|
463
475
|
* traits.selectors.selectTodosTotal
|
|
464
|
-
* traits.selectors.
|
|
465
|
-
* traits.selectors.
|
|
466
|
-
* traits.selectors.
|
|
476
|
+
* traits.selectors.isTodosLoading
|
|
477
|
+
* traits.selectors.isTodosLoadingSuccess
|
|
478
|
+
* traits.selectors.isTodosLoadingFail
|
|
467
479
|
*/
|
|
468
480
|
function addLoadEntitiesTrait(traitConfig) {
|
|
469
481
|
var adapter = entity.createEntityAdapter(traitConfig);
|
|
@@ -546,9 +558,9 @@
|
|
|
546
558
|
}
|
|
547
559
|
return FilterEffect;
|
|
548
560
|
}(core.TraitEffect));
|
|
549
|
-
FilterEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.
|
|
550
|
-
FilterEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.
|
|
551
|
-
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.
|
|
561
|
+
FilterEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: FilterEffect, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
562
|
+
FilterEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: FilterEffect });
|
|
563
|
+
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: FilterEffect, decorators: [{
|
|
552
564
|
type: i0.Injectable
|
|
553
565
|
}] });
|
|
554
566
|
return [FilterEffect];
|
|
@@ -609,7 +621,7 @@
|
|
|
609
621
|
* // The following trait config
|
|
610
622
|
*
|
|
611
623
|
* export interface TestState
|
|
612
|
-
* extends
|
|
624
|
+
* extends LoadEntitiesState<Todo>, FilterEntitiesState<TodoFilter>{}
|
|
613
625
|
*
|
|
614
626
|
* const traits = createEntityFeatureFactory(
|
|
615
627
|
* addLoadEntitiesTrait<Todo>(),
|
|
@@ -625,8 +637,13 @@
|
|
|
625
637
|
* 'todos',
|
|
626
638
|
* ),
|
|
627
639
|
* });
|
|
628
|
-
*
|
|
640
|
+
*
|
|
641
|
+
* // adds following props to the state:
|
|
642
|
+
* // filters?: TodoFilter;
|
|
643
|
+
*
|
|
644
|
+
* // generated actions
|
|
629
645
|
* traits.actions.filterTodos()
|
|
646
|
+
* // generated selectors
|
|
630
647
|
* traits.selectors.selectTodosFilter()
|
|
631
648
|
*/
|
|
632
649
|
function addFilterEntitiesTrait(_a) {
|
|
@@ -794,7 +811,7 @@
|
|
|
794
811
|
}); }))), __read(core.insertIf(allActions.removeEntities, function () { return i2.on(allActions.removeEntities, function (state, _b) {
|
|
795
812
|
var keys = _b.keys;
|
|
796
813
|
return addToCacheTotal(state, -keys.length);
|
|
797
|
-
}); }))), __read(core.insertIf(
|
|
814
|
+
}); }))), __read(core.insertIf(allActions.storeEntitiesFilter, function () { return i2.on(allActions.storeEntitiesFilter, function (state) { return recalculateTotal(state); }); }))), __read(core.insertIf(allActions.removeAllEntities, function () { return i2.on(allActions.removeAllEntities, function (state) { return clearPagesCache(state); }); }))));
|
|
798
815
|
}
|
|
799
816
|
|
|
800
817
|
function createPaginationTraitEffects(allActions, allSelectors) {
|
|
@@ -844,9 +861,9 @@
|
|
|
844
861
|
}
|
|
845
862
|
return PaginationEffect;
|
|
846
863
|
}(core.TraitEffect));
|
|
847
|
-
PaginationEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.
|
|
848
|
-
PaginationEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.
|
|
849
|
-
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.
|
|
864
|
+
PaginationEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: PaginationEffect, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
865
|
+
PaginationEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: PaginationEffect });
|
|
866
|
+
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: PaginationEffect, decorators: [{
|
|
850
867
|
type: i0.Injectable
|
|
851
868
|
}] });
|
|
852
869
|
return [PaginationEffect];
|
|
@@ -884,11 +901,11 @@
|
|
|
884
901
|
* - 'grow': Similar to partial that the backend returns partial result, but in this case the cache grows,
|
|
885
902
|
* after each loadEntities the cache is appended to the previous cache, this mode is ideal for infinite scrolls,
|
|
886
903
|
* where you will only call loadNextPage.
|
|
887
|
-
* To make the pagination experience smoother the loadEntities
|
|
888
|
-
* the last cached page.
|
|
904
|
+
* To make the pagination experience smoother the loadEntities action is fired when the current page is equal
|
|
905
|
+
* to the last cached page, so while the user is reading the page more pages are being loading in the background.
|
|
889
906
|
* @param config
|
|
890
907
|
* @param config.cacheType - Default to 'partial', change the cache mode
|
|
891
|
-
* @param config.pageSize - Default to
|
|
908
|
+
* @param config.pageSize - Default to 10, number of entities on each page
|
|
892
909
|
* @param config.currentPage - Default to 0, starting page
|
|
893
910
|
* @param config.pagesToCache - Default to 3, used in partial and grow cache mode, is the number of
|
|
894
911
|
* extra pages kept in cache to avoid calling the backend on each page
|
|
@@ -908,7 +925,22 @@
|
|
|
908
925
|
* 'todos',
|
|
909
926
|
* ),
|
|
910
927
|
* });
|
|
911
|
-
*
|
|
928
|
+
*
|
|
929
|
+
* // adds following props to the state:
|
|
930
|
+
* // pagination: {
|
|
931
|
+
* // currentPage: number;
|
|
932
|
+
* // requestPage: number;
|
|
933
|
+
* // pageSize: number;
|
|
934
|
+
* // total?: number;
|
|
935
|
+
* // pagesToCache: number;
|
|
936
|
+
* // cache: {
|
|
937
|
+
* // type: 'full' | 'partial' | 'grow';
|
|
938
|
+
* // start: number;
|
|
939
|
+
* // end: number;
|
|
940
|
+
* // }
|
|
941
|
+
* // }
|
|
942
|
+
*
|
|
943
|
+
* // generated actions
|
|
912
944
|
* traits.actions.loadTodosPage({index})
|
|
913
945
|
* traits.actions.loadTodosPageSuccess()
|
|
914
946
|
* traits.actions.loadTodosPageFail()
|
|
@@ -917,19 +949,18 @@
|
|
|
917
949
|
* traits.actions.loadTodosFirstPage()
|
|
918
950
|
* traits.actions.loadTodosLastPage()
|
|
919
951
|
* traits.actions.clearTodosPagesCache()
|
|
920
|
-
*
|
|
921
|
-
*
|
|
922
|
-
* traits.selectors.
|
|
923
|
-
* traits.selectors.
|
|
924
|
-
*
|
|
925
|
-
* //
|
|
926
|
-
*
|
|
927
|
-
* traits.selectors.selectTodosPage({page})
|
|
952
|
+
* // generated selectors
|
|
953
|
+
* traits.selectors.isTodosPageInCache()
|
|
954
|
+
* traits.selectors.selectPageTodosList()
|
|
955
|
+
* traits.selectors.isLoadingTodosPage()
|
|
956
|
+
* // use isLoadingTodosPage over isLoadingTodos (which will return true even
|
|
957
|
+
* // if the page loading is not the current one)
|
|
958
|
+
* traits.selectors.selectTodosPage()
|
|
928
959
|
* traits.selectors.selectTodosPagedRequest()// use in effects to get paging parameter
|
|
929
960
|
* traits.selectors.selectTodosPageInfo()
|
|
930
961
|
*/
|
|
931
962
|
function addEntitiesPaginationTrait(_a) {
|
|
932
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.cacheType, cacheType = _c === void 0 ? 'partial' : _c, _d = _b.pageSize, pageSize = _d === void 0 ?
|
|
963
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.cacheType, cacheType = _c === void 0 ? 'partial' : _c, _d = _b.pageSize, pageSize = _d === void 0 ? 10 : _d, _e = _b.currentPage, currentPage = _e === void 0 ? 0 : _e, _f = _b.pagesToCache, pagesToCache = _f === void 0 ? 3 : _f;
|
|
933
964
|
return core.createTraitFactory({
|
|
934
965
|
key: entitiesPaginationTraitKey,
|
|
935
966
|
depends: [loadEntitiesTraitKey],
|
|
@@ -1116,13 +1147,17 @@
|
|
|
1116
1147
|
* 'todos',
|
|
1117
1148
|
* ),
|
|
1118
1149
|
* });
|
|
1119
|
-
*
|
|
1150
|
+
*
|
|
1151
|
+
* // adds following props to the state:
|
|
1152
|
+
* // selectedIds: Dictionary<boolean>;
|
|
1153
|
+
*
|
|
1154
|
+
* // generated actions
|
|
1120
1155
|
* traits.actions.selectTodos({id})
|
|
1121
1156
|
* traits.actions.deselectTodos({id})
|
|
1122
1157
|
* traits.actions.toggleSectTodos({id})
|
|
1123
1158
|
* traits.actions.toggleSelectAllTodos()
|
|
1124
1159
|
* traits.actions.clearTodosSelection()
|
|
1125
|
-
*
|
|
1160
|
+
* //generated selectors
|
|
1126
1161
|
* traits.selectors.isAllTodosSelected()
|
|
1127
1162
|
* traits.selectors.selectTodosIdsSelectedMap()
|
|
1128
1163
|
* traits.selectors.selectTodosIdsSelectedList()
|
|
@@ -1247,11 +1282,15 @@
|
|
|
1247
1282
|
* 'todos',
|
|
1248
1283
|
* ),
|
|
1249
1284
|
* });
|
|
1250
|
-
*
|
|
1285
|
+
*
|
|
1286
|
+
* // adds following props to the state:
|
|
1287
|
+
* // selectedId?: number | string;
|
|
1288
|
+
*
|
|
1289
|
+
* // generated actions
|
|
1251
1290
|
* traits.actions.selectTodo({id})
|
|
1252
1291
|
* traits.actions.deselectTodo()
|
|
1253
1292
|
* traits.actions.toggleSelectTodo({id})
|
|
1254
|
-
*
|
|
1293
|
+
* //generated selectors
|
|
1255
1294
|
* traits.selectors.selectTodoIdSelected()
|
|
1256
1295
|
* traits.selectors.selectTodoSelected()
|
|
1257
1296
|
*/
|
|
@@ -1534,13 +1573,17 @@
|
|
|
1534
1573
|
* 'todos',
|
|
1535
1574
|
* ),
|
|
1536
1575
|
* });
|
|
1537
|
-
*
|
|
1576
|
+
*
|
|
1577
|
+
* // adds following props to the state:
|
|
1578
|
+
* // changes: Change<Todo>[];
|
|
1579
|
+
*
|
|
1580
|
+
* // generated actions
|
|
1538
1581
|
* traits.actions.addTodos(entity1,entity2...)
|
|
1539
1582
|
* traits.actions.updateTodos({id: id1, changes:{prop1}},{id: id2, changes:{prop2}} ...)
|
|
1540
1583
|
* traits.actions.upsertTodos(entity1,entity2...)
|
|
1541
1584
|
* traits.actions.removeAllTodos()
|
|
1542
1585
|
* traits.actions.clearTodosChanges()
|
|
1543
|
-
*
|
|
1586
|
+
* // generated selectors
|
|
1544
1587
|
* traits.selectors.selectTodosChangesList()
|
|
1545
1588
|
* traits.selectors.selectFilteredTodosChangesList()
|
|
1546
1589
|
* traits.selectors.selectAllFilteredChanges()
|
|
@@ -1594,6 +1637,8 @@
|
|
|
1594
1637
|
return value;
|
|
1595
1638
|
}
|
|
1596
1639
|
/**
|
|
1640
|
+
* @internal
|
|
1641
|
+
* @ignore
|
|
1597
1642
|
* Gets a sorted copy of the data array based on the state of the Sort.
|
|
1598
1643
|
* @param data The array of data that should be sorted.
|
|
1599
1644
|
* @param sort The connected MatSort that holds the current sort state.
|
|
@@ -1703,9 +1748,9 @@
|
|
|
1703
1748
|
}
|
|
1704
1749
|
return SortEffect;
|
|
1705
1750
|
}(core.TraitEffect));
|
|
1706
|
-
SortEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.
|
|
1707
|
-
SortEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.
|
|
1708
|
-
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.
|
|
1751
|
+
SortEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SortEffect, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
1752
|
+
SortEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SortEffect });
|
|
1753
|
+
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: SortEffect, decorators: [{
|
|
1709
1754
|
type: i0.Injectable
|
|
1710
1755
|
}] });
|
|
1711
1756
|
return remote ? [SortEffect] : [];
|
|
@@ -1721,8 +1766,8 @@
|
|
|
1721
1766
|
/**
|
|
1722
1767
|
* Generates ngrx code to sort locally or remotely a list of entities
|
|
1723
1768
|
* @param config
|
|
1724
|
-
* @param config.defaultSort - Required, Default entity prop for the sort
|
|
1725
|
-
* @param config.remote -
|
|
1769
|
+
* @param config.defaultSort - Required field, Default entity prop for the sort
|
|
1770
|
+
* @param config.remote - Required field, default to false, when true disables local
|
|
1726
1771
|
* sorting and every sort action call will now trigger a loadEntities action and the backend
|
|
1727
1772
|
* should sort the data, use selectSort in the effect that call backend to get the requested sort,
|
|
1728
1773
|
* when false all sorting is done in memory when the sort action is fired
|
|
@@ -1743,14 +1788,20 @@
|
|
|
1743
1788
|
* 'todos',
|
|
1744
1789
|
* ),
|
|
1745
1790
|
* });
|
|
1746
|
-
* //
|
|
1791
|
+
* // adds following props to the state:
|
|
1792
|
+
* // sort: {
|
|
1793
|
+
* // current: Sort<Todo>;
|
|
1794
|
+
* // default: Sort<Todo>;
|
|
1795
|
+
* // }
|
|
1796
|
+
*
|
|
1797
|
+
* // generated actions
|
|
1747
1798
|
* traits.actions.sortTodos({active:'id', direction:'desc'})
|
|
1748
1799
|
* traits.actions.resetTodosSort()
|
|
1749
|
-
*
|
|
1800
|
+
* //generated selectors
|
|
1750
1801
|
* traits.selectors.selectTodosSort()
|
|
1751
1802
|
*/
|
|
1752
1803
|
function addSortEntitiesTrait(_a) {
|
|
1753
|
-
var
|
|
1804
|
+
var remote = _a.remote, defaultSort = _a.defaultSort;
|
|
1754
1805
|
return core.createTraitFactory({
|
|
1755
1806
|
key: sortTraitKey,
|
|
1756
1807
|
depends: [loadEntitiesTraitKey],
|
|
@@ -1800,7 +1851,7 @@
|
|
|
1800
1851
|
* 'todos',
|
|
1801
1852
|
* ),
|
|
1802
1853
|
* });
|
|
1803
|
-
* //
|
|
1854
|
+
* // generated actions
|
|
1804
1855
|
* traits.actions.resetTodosState()
|
|
1805
1856
|
*/
|
|
1806
1857
|
function addResetEntitiesStateTrait(traitConfig) {
|
|
@@ -1820,38 +1871,42 @@
|
|
|
1820
1871
|
},
|
|
1821
1872
|
effects: function (_b) {
|
|
1822
1873
|
var allActions = _b.allActions;
|
|
1823
|
-
|
|
1824
|
-
var ResetEffect = /** @class */ (function (_super) {
|
|
1825
|
-
__extends(ResetEffect, _super);
|
|
1826
|
-
//TODO: not sure why Im forced to override this constructor
|
|
1827
|
-
// or test wont pass, strangely doesnt happen in other files
|
|
1828
|
-
// with similar case like pagination.effects.ts
|
|
1829
|
-
function ResetEffect(actions$, store) {
|
|
1830
|
-
var _this = this;
|
|
1831
|
-
var _a;
|
|
1832
|
-
_this = _super.call(this, actions$, store) || this;
|
|
1833
|
-
_this.externalReset$ = ((_a = traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.resetOn) === null || _a === void 0 ? void 0 : _a.length) &&
|
|
1834
|
-
i1.createEffect(function () {
|
|
1835
|
-
return _this.actions$.pipe(i1.ofType.apply(void 0, __spreadArray([], __read(traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.resetOn))), operators.mapTo(allActions.resetEntitiesState()));
|
|
1836
|
-
});
|
|
1837
|
-
return _this;
|
|
1838
|
-
}
|
|
1839
|
-
return ResetEffect;
|
|
1840
|
-
}(core.TraitEffect));
|
|
1841
|
-
ResetEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: ResetEffect, deps: [{ token: i1__namespace.Actions }, { token: i2__namespace.Store }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
1842
|
-
ResetEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: ResetEffect });
|
|
1843
|
-
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: ResetEffect, decorators: [{
|
|
1844
|
-
type: i0.Injectable
|
|
1845
|
-
}], ctorParameters: function () { return [{ type: i1__namespace.Actions }, { type: i2__namespace.Store }]; } });
|
|
1846
|
-
return ((_a = traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.resetOn) === null || _a === void 0 ? void 0 : _a.length) ? [ResetEffect] : [];
|
|
1874
|
+
return createResetTraitEffect(allActions, traitConfig);
|
|
1847
1875
|
},
|
|
1848
1876
|
});
|
|
1849
1877
|
}
|
|
1878
|
+
function createResetTraitEffect(allActions, traitConfig) {
|
|
1879
|
+
var _a;
|
|
1880
|
+
var ResetEffect = /** @class */ (function (_super) {
|
|
1881
|
+
__extends(ResetEffect, _super);
|
|
1882
|
+
//TODO: not sure why Im forced to override this constructor
|
|
1883
|
+
// or test wont pass, strangely doesnt happen in other files
|
|
1884
|
+
// with similar case like pagination.effects.ts
|
|
1885
|
+
function ResetEffect(actions$, store) {
|
|
1886
|
+
var _this = this;
|
|
1887
|
+
var _a;
|
|
1888
|
+
_this = _super.call(this, actions$, store) || this;
|
|
1889
|
+
_this.externalReset$ = ((_a = traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.resetOn) === null || _a === void 0 ? void 0 : _a.length) &&
|
|
1890
|
+
i1.createEffect(function () {
|
|
1891
|
+
return _this.actions$.pipe(i1.ofType.apply(void 0, __spreadArray([], __read(traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.resetOn))), operators.mapTo(allActions.resetEntitiesState()));
|
|
1892
|
+
});
|
|
1893
|
+
return _this;
|
|
1894
|
+
}
|
|
1895
|
+
return ResetEffect;
|
|
1896
|
+
}(core.TraitEffect));
|
|
1897
|
+
ResetEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: ResetEffect, deps: [{ token: i1__namespace.Actions }, { token: i2__namespace.Store }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
|
|
1898
|
+
ResetEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: ResetEffect });
|
|
1899
|
+
i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: ResetEffect, decorators: [{
|
|
1900
|
+
type: i0.Injectable
|
|
1901
|
+
}], ctorParameters: function () { return [{ type: i1__namespace.Actions }, { type: i2__namespace.Store }]; } });
|
|
1902
|
+
return ((_a = traitConfig === null || traitConfig === void 0 ? void 0 : traitConfig.resetOn) === null || _a === void 0 ? void 0 : _a.length) ? [ResetEffect] : [];
|
|
1903
|
+
}
|
|
1850
1904
|
|
|
1851
1905
|
/**
|
|
1852
1906
|
* Generates the typical ngrx code need to make a async action with
|
|
1853
1907
|
* a request, success and failure actions, plus a status property to track its progress
|
|
1854
|
-
* and selectors to query the status.
|
|
1908
|
+
* and selectors to query the status. This trait can be added more thant once as long
|
|
1909
|
+
* as the name prop is different.
|
|
1855
1910
|
*
|
|
1856
1911
|
* @param options - Config object for the trait factory
|
|
1857
1912
|
* @param options.name - Name of the main request action, should be in camel case
|
|
@@ -1878,10 +1933,14 @@
|
|
|
1878
1933
|
* 'client',
|
|
1879
1934
|
* ),
|
|
1880
1935
|
* });
|
|
1881
|
-
* //
|
|
1936
|
+
* // adds following props to the state:
|
|
1937
|
+
* // createClientStatus?: 'loading' | 'success' | 'fail';
|
|
1938
|
+
*
|
|
1939
|
+
* // generated actions
|
|
1882
1940
|
* traits.actions.createClient({name:'Pedro'})
|
|
1883
1941
|
* traits.actions.createClientSuccess({id:'123'})
|
|
1884
1942
|
* traits.actions.createClientFail();
|
|
1943
|
+
* //generated selectors
|
|
1885
1944
|
* traits.selectors.isLoadingCreateClient
|
|
1886
1945
|
* traits.selectors.isSuccessCreateClient
|
|
1887
1946
|
* traits.selectors.isFailCreateClient
|
|
@@ -1960,7 +2019,8 @@
|
|
|
1960
2019
|
}
|
|
1961
2020
|
|
|
1962
2021
|
/**
|
|
1963
|
-
* Generates ngrx code needed to load and entity and store it in a state
|
|
2022
|
+
* Generates ngrx code needed to load and entity and store it in a state. This action can be added
|
|
2023
|
+
* more than once as long as the entityName para is different
|
|
1964
2024
|
* @param entityName - Entity name, should be in camel case
|
|
1965
2025
|
* @param options.actionProps - Optional param for the main request action,
|
|
1966
2026
|
* use the props() function for its value, if not present action will have no params,
|
|
@@ -1984,14 +2044,19 @@
|
|
|
1984
2044
|
* >('client'),
|
|
1985
2045
|
* });
|
|
1986
2046
|
*
|
|
1987
|
-
* //
|
|
2047
|
+
* // adds following props to the state:
|
|
2048
|
+
* // loadClientStatus?: 'loading' | 'success' | 'fail';
|
|
2049
|
+
* // client?: Client;
|
|
2050
|
+
*
|
|
2051
|
+
* // generated actions
|
|
1988
2052
|
* traits.actions.loadClient({id:123});
|
|
1989
2053
|
* traits.actions.loadClientSuccess({client: {id: '123', name: 'gabs'}});
|
|
1990
2054
|
* traits.actions.loadClientFail();
|
|
1991
|
-
*
|
|
1992
|
-
* traits.selectors.
|
|
1993
|
-
* traits.selectors.
|
|
1994
|
-
* traits.selectors.
|
|
2055
|
+
* // generated selectors
|
|
2056
|
+
* traits.selectors.selectClient()
|
|
2057
|
+
* traits.selectors.isLoadingLoadClient()
|
|
2058
|
+
* traits.selectors.isSuccessLoadClient()
|
|
2059
|
+
* traits.selectors.isFailLoadClient()
|
|
1995
2060
|
*/
|
|
1996
2061
|
function addLoadEntityTraits(_a) {
|
|
1997
2062
|
var entityName = _a.entityName, actionProps = _a.actionProps, actionSuccessProps = _a.actionSuccessProps, actionFailProps = _a.actionFailProps;
|
|
@@ -2041,7 +2106,7 @@
|
|
|
2041
2106
|
* const traits = createEntityFeatureFactory(
|
|
2042
2107
|
* addSetEntityTraits({
|
|
2043
2108
|
* entityName: 'client',
|
|
2044
|
-
* actionProps: props<{ client:
|
|
2109
|
+
* actionProps: props<{ client: Client }
|
|
2045
2110
|
* }),
|
|
2046
2111
|
* )({
|
|
2047
2112
|
* actionsGroupKey: 'Client',
|
|
@@ -2049,10 +2114,13 @@
|
|
|
2049
2114
|
* SetEntityState<Client, 'client'>
|
|
2050
2115
|
* >('client'),
|
|
2051
2116
|
* });
|
|
2117
|
+
* // adds following props to the state:
|
|
2118
|
+
* // client?: Client;
|
|
2052
2119
|
*
|
|
2053
|
-
* //
|
|
2120
|
+
* // generated actions
|
|
2054
2121
|
* traits.actions.setClient({client: {id:123, name: 'gabs'}});
|
|
2055
|
-
*
|
|
2122
|
+
* //generated selectors
|
|
2123
|
+
* traits.selectors.selectClient()
|
|
2056
2124
|
*/
|
|
2057
2125
|
function addSetEntityTrait(_a) {
|
|
2058
2126
|
var entityName = _a.entityName, actionProps = _a.actionProps;
|
|
@@ -2122,5 +2190,5 @@
|
|
|
2122
2190
|
|
|
2123
2191
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2124
2192
|
|
|
2125
|
-
}))
|
|
2193
|
+
}));
|
|
2126
2194
|
//# sourceMappingURL=ngrx-traits-common.umd.js.map
|