@ngrx-traits/core 12.0.0 → 12.1.2

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.
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ngrx-traits/core'), require('@angular/core'), require('@ngrx/effects'), require('@ngrx/store/testing')) :
3
3
  typeof define === 'function' && define.amd ? define('@ngrx-traits/core/testing', ['exports', '@ngrx-traits/core', '@angular/core', '@ngrx/effects', '@ngrx/store/testing'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngrx-traits'] = global['ngrx-traits'] || {}, global['ngrx-traits'].core = global['ngrx-traits'].core || {}, global['ngrx-traits'].core.testing = {}), global['ngrx-traits'].core, global.ng.core, global.effects, global.testing));
5
- }(this, (function (exports, core, core$1, effects, testing) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global["ngrx-traits"] = global["ngrx-traits"] || {}, global["ngrx-traits"].core = global["ngrx-traits"].core || {}, global["ngrx-traits"].core.testing = {}), global["ngrx-traits"].core, global.ng.core, global.effects, global.testing));
5
+ })(this, (function (exports, core, core$1, effects, testing) { 'use strict';
6
6
 
7
7
  /*
8
8
  * NOTE: provideMockStore({initialState}) initialState will be ignored with local traits store!
@@ -48,5 +48,5 @@
48
48
 
49
49
  Object.defineProperty(exports, '__esModule', { value: true });
50
50
 
51
- })));
51
+ }));
52
52
  //# sourceMappingURL=ngrx-traits-core-testing.umd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ngrx-traits-core-testing.umd.js","sources":["../../../../../libs/ngrx-traits/core/testing/src/provide-mock-local-traits.ts","../../../../../libs/ngrx-traits/core/testing/src/ngrx-traits-core-testing.ts"],"sourcesContent":["import {\n EntityFeatureFactory,\n TraitsLocalStore,\n DISABLE_LOCAL_TRAIT_EFFECTS,\n} from '@ngrx-traits/core';\nimport { Injector, Provider, Type } from '@angular/core';\nimport { EffectSources } from '@ngrx/effects';\nimport { MockStore } from '@ngrx/store/testing';\n\n/*\n * NOTE: provideMockStore({initialState}) initialState will be ignored with local traits store!\n * Override selectors instead\n *\n * You still need to provideMockStore and provideMockActions\n * */\nexport function provideMockLocalTraits<\n T extends TraitsLocalStore<EntityFeatureFactory<any, any>>\n>({\n traitFactory,\n selectors,\n}: {\n traitFactory: Type<T>;\n selectors?: {\n [key in keyof T['localSelectors']]?: ReturnType<T['localSelectors'][key]>;\n };\n}): Provider[] {\n return [\n { provide: DISABLE_LOCAL_TRAIT_EFFECTS, useValue: true },\n {\n provide: EffectSources,\n useValue: {\n addEffects: () => {\n return;\n },\n },\n },\n {\n provide: traitFactory,\n deps: [Injector, MockStore],\n useFactory: (injector: Injector, mockStore: MockStore) => {\n const trait = new traitFactory(injector);\n if (selectors) {\n Object.keys(selectors).forEach(\n (key) =>\n trait.localSelectors?.[key] &&\n mockStore.overrideSelector(\n trait.localSelectors[key],\n selectors?.[key]\n )\n );\n }\n return trait;\n },\n },\n ];\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["DISABLE_LOCAL_TRAIT_EFFECTS","EffectSources","Injector","MockStore"],"mappings":";;;;;;IASA;;;;;;aAMgB,sBAAsB,CAEpC,EAQD;YAPC,YAAY,kBAAA,EACZ,SAAS,eAAA;QAOT,OAAO;YACL,EAAE,OAAO,EAAEA,gCAA2B,EAAE,QAAQ,EAAE,IAAI,EAAE;YACxD;gBACE,OAAO,EAAEC,qBAAa;gBACtB,QAAQ,EAAE;oBACR,UAAU,EAAE;wBACV,OAAO;qBACR;iBACF;aACF;YACD;gBACE,OAAO,EAAE,YAAY;gBACrB,IAAI,EAAE,CAACC,eAAQ,EAAEC,iBAAS,CAAC;gBAC3B,UAAU,EAAE,UAAC,QAAkB,EAAE,SAAoB;oBACnD,IAAM,KAAK,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC;oBACzC,IAAI,SAAS,EAAE;wBACb,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAC5B,UAAC,GAAG;;4BACF,OAAA,CAAA,MAAA,KAAK,CAAC,cAAc,0CAAG,GAAG,CAAC;gCAC3B,SAAS,CAAC,gBAAgB,CACxB,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EACzB,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAG,GAAG,CAAC,CACjB,CAAA;yBAAA,CACJ,CAAC;qBACH;oBACD,OAAO,KAAK,CAAC;iBACd;aACF;SACF,CAAC;IACJ;;ICvDA;;;;;;;;;;;;"}
1
+ {"version":3,"file":"ngrx-traits-core-testing.umd.js","sources":["../../../../../libs/ngrx-traits/core/testing/src/provide-mock-local-traits.ts","../../../../../libs/ngrx-traits/core/testing/src/ngrx-traits-core-testing.ts"],"sourcesContent":["import {\n EntityFeatureFactory,\n TraitsLocalStore,\n DISABLE_LOCAL_TRAIT_EFFECTS,\n} from '@ngrx-traits/core';\nimport { Injector, Provider, Type } from '@angular/core';\nimport { EffectSources } from '@ngrx/effects';\nimport { MockStore } from '@ngrx/store/testing';\n\n/*\n * NOTE: provideMockStore({initialState}) initialState will be ignored with local traits store!\n * Override selectors instead\n *\n * You still need to provideMockStore and provideMockActions\n * */\nexport function provideMockLocalTraits<\n T extends TraitsLocalStore<EntityFeatureFactory<any, any>>\n>({\n traitFactory,\n selectors,\n}: {\n traitFactory: Type<T>;\n selectors?: {\n [key in keyof T['localSelectors']]?: ReturnType<T['localSelectors'][key]>;\n };\n}): Provider[] {\n return [\n { provide: DISABLE_LOCAL_TRAIT_EFFECTS, useValue: true },\n {\n provide: EffectSources,\n useValue: {\n addEffects: () => {\n return;\n },\n },\n },\n {\n provide: traitFactory,\n deps: [Injector, MockStore],\n useFactory: (injector: Injector, mockStore: MockStore) => {\n const trait = new traitFactory(injector);\n if (selectors) {\n Object.keys(selectors).forEach(\n (key) =>\n trait.localSelectors?.[key] &&\n mockStore.overrideSelector(\n trait.localSelectors[key],\n selectors?.[key]\n )\n );\n }\n return trait;\n },\n },\n ];\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":["DISABLE_LOCAL_TRAIT_EFFECTS","EffectSources","Injector","MockStore"],"mappings":";;;;;;IASA;;;;;IAKK;IACC,SAAU,sBAAsB,CAEpC,EAQD,EAAA;YAPC,YAAY,GAAA,EAAA,CAAA,YAAA,EACZ,SAAS,GAAA,EAAA,CAAA,SAAA,CAAA;QAOT,OAAO;IACL,QAAA,EAAE,OAAO,EAAEA,gCAA2B,EAAE,QAAQ,EAAE,IAAI,EAAE;IACxD,QAAA;IACE,YAAA,OAAO,EAAEC,qBAAa;IACtB,YAAA,QAAQ,EAAE;IACR,gBAAA,UAAU,EAAE,YAAA;wBACV,OAAO;qBACR;IACF,aAAA;IACF,SAAA;IACD,QAAA;IACE,YAAA,OAAO,EAAE,YAAY;IACrB,YAAA,IAAI,EAAE,CAACC,eAAQ,EAAEC,iBAAS,CAAC;IAC3B,YAAA,UAAU,EAAE,UAAC,QAAkB,EAAE,SAAoB,EAAA;IACnD,gBAAA,IAAM,KAAK,GAAG,IAAI,YAAY,CAAC,QAAQ,CAAC,CAAC;IACzC,gBAAA,IAAI,SAAS,EAAE;wBACb,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAC5B,UAAC,GAAG,EAAA;;4BACF,OAAA,CAAA,CAAA,EAAA,GAAA,KAAK,CAAC,cAAc,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAG,GAAG,CAAC;IAC3B,4BAAA,SAAS,CAAC,gBAAgB,CACxB,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,EACzB,SAAS,KAAA,IAAA,IAAT,SAAS,KAAT,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,SAAS,CAAG,GAAG,CAAC,CACjB,CAAA;IAAA,qBAAA,CACJ,CAAC;IACH,iBAAA;IACD,gBAAA,OAAO,KAAK,CAAC;iBACd;IACF,SAAA;SACF,CAAC;IACJ;;ICvDA;;IAEG;;;;;;;;;;"}
@@ -1,8 +1,8 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@ngrx/store'), require('@angular/core'), require('@ngrx/effects'), require('rxjs/operators'), require('rxjs')) :
3
3
  typeof define === 'function' && define.amd ? define('@ngrx-traits/core', ['exports', '@ngrx/store', '@angular/core', '@ngrx/effects', 'rxjs/operators', 'rxjs'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ngrx-traits'] = global['ngrx-traits'] || {}, global['ngrx-traits'].core = {}), global.i2, global.ng.core, global.i1, global.rxjs.operators, global.rxjs));
5
- }(this, (function (exports, i2, i0, i1, operators, rxjs) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global["ngrx-traits"] = global["ngrx-traits"] || {}, global["ngrx-traits"].core = {}), global.i2, global.ng.core, global.i1, global.rxjs.operators, global.rxjs));
5
+ })(this, (function (exports, i2, i0, i1, operators, rxjs) { '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['default'] = e;
21
+ n["default"] = e;
24
22
  return Object.freeze(n);
25
23
  }
26
24
 
@@ -28,7 +26,7 @@
28
26
  var i0__namespace = /*#__PURE__*/_interopNamespace(i0);
29
27
  var i1__namespace = /*#__PURE__*/_interopNamespace(i1);
30
28
 
31
- /*! *****************************************************************************
29
+ /******************************************************************************
32
30
  Copyright (c) Microsoft Corporation.
33
31
 
34
32
  Permission to use, copy, modify, and/or distribute this software for any
@@ -190,7 +188,11 @@
190
188
  var __createBinding = Object.create ? (function (o, m, k, k2) {
191
189
  if (k2 === undefined)
192
190
  k2 = k;
193
- Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
191
+ var desc = Object.getOwnPropertyDescriptor(m, k);
192
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
193
+ desc = { enumerable: true, get: function () { return m[k]; } };
194
+ }
195
+ Object.defineProperty(o, k2, desc);
194
196
  }) : (function (o, m, k, k2) {
195
197
  if (k2 === undefined)
196
198
  k2 = k;
@@ -263,7 +265,7 @@
263
265
  ar[i] = from[i];
264
266
  }
265
267
  }
266
- return to.concat(ar || from);
268
+ return to.concat(ar || Array.prototype.slice.call(from));
267
269
  }
268
270
  function __await(v) {
269
271
  return this instanceof __await ? (this.v = v, this) : new __await(v);
@@ -345,6 +347,11 @@
345
347
  throw new TypeError("Cannot write private member to an object whose class did not declare it");
346
348
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
347
349
  }
350
+ function __classPrivateFieldIn(state, receiver) {
351
+ if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function"))
352
+ throw new TypeError("Cannot use 'in' operator on non-object");
353
+ return typeof state === "function" ? receiver === state : state.has(receiver);
354
+ }
348
355
 
349
356
  function insertIf(condition, getElement) {
350
357
  return condition ? [getElement()] : [];
@@ -362,10 +369,85 @@
362
369
  var result = text.replace(/([A-Z])/g, ' $1');
363
370
  return result.charAt(0).toUpperCase() + result.slice(1);
364
371
  }
365
-
366
- function createTraitFactory(f) {
367
- return f;
372
+ /**
373
+ * Set propertyReducer in sourceReducer in a property of the source state,
374
+ * @param sourceReducer
375
+ * @param property
376
+ * @param propertyReducer
377
+ *
378
+ * @example
379
+ *
380
+ * const newReducer = setPropertyReducer(productsReducer, 'selectedProduct', selectedProductReducer)
381
+ */
382
+ function setPropertyReducer(sourceReducer, property, propertyReducer) {
383
+ return function reducer(state, action) {
384
+ var _a;
385
+ var sourceState = sourceReducer(state, action);
386
+ return Object.assign(Object.assign({}, sourceState), (_a = {}, _a[property] = propertyReducer(sourceState[property], action), _a));
387
+ };
388
+ }
389
+ /**
390
+ * Set propertyReducers in sourceReducer each in a property of the source state,
391
+ * @param sourceReducer
392
+ * @param property
393
+ * @param propertyReducer
394
+ *
395
+ * @example
396
+ *
397
+ * const newReducer = setPropertyReducer(productsReducer,
398
+ * {
399
+ * selectedProduct: selectedProductReducer
400
+ * favoriteProduct: favoriteProductReducer
401
+ * })
402
+ */
403
+ function setPropertiesReducer(sourceReducer, propertiesReducers) {
404
+ return function reducer(state, action) {
405
+ var newState = Object.assign({}, sourceReducer(state, action));
406
+ for (var property in propertiesReducers) {
407
+ newState[property] = propertiesReducers[property](newState[property], action);
408
+ }
409
+ return newState;
410
+ };
411
+ }
412
+ /**
413
+ * joins two reducers so the work in the same state
414
+ * @param firstReducer
415
+ * @param secondReducer
416
+ */
417
+ function joinReducers(firstReducer, secondReducer) {
418
+ return function reducer(state, action) {
419
+ var sourceState = firstReducer(state, action);
420
+ return secondReducer(sourceState, action);
421
+ };
368
422
  }
423
+
424
+ /**
425
+ * Creates a function that when execute will combine all the traits, and return a EntityFeatureFactory
426
+ * which combines all the traits actions, selectors , reducers and effects,
427
+ * the names param will replace any action and selector with the word Entity or Entities,
428
+ * with the corresponding entityName and entitiesName param (entityName+'s' if entitiesName is omitted).
429
+ * @param namesConfig - Optional Names for entities
430
+ * @param namesConfig.entityName - singular name for entity
431
+ * @param [namesConfig.entitiesName] - plural name for entities, defaults to entityName + 's'
432
+ * @param traits set of traits to be combined
433
+ *
434
+ * @example
435
+ *
436
+ * const featureFactory = createEntityFeatureFactory(
437
+ * { entityName: 'product' },
438
+ * addLoadEntitiesTrait<Product>(),
439
+ * addSelectEntityTrait<Product>(),
440
+ * addAsyncActionTrait({
441
+ * name: 'checkout',
442
+ * actionSuccessProps: props<{ orderId: string }>(),
443
+ * })
444
+ * );
445
+ *
446
+ * export const productsFeature = featureFactory({
447
+ * actionsGroupKey: '[Products]',
448
+ * featureSelector: 'products',
449
+ * });
450
+ */
369
451
  function createEntityFeatureFactory(namesOrFactory) {
370
452
  var traits = [];
371
453
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -565,28 +647,45 @@
565
647
  }
566
648
  return ss;
567
649
  }
568
- function setPropertyReducer(sourceReducer, property, propertyReducer) {
569
- return function reducer(state, action) {
570
- var _d;
571
- var sourceState = sourceReducer(state, action);
572
- return Object.assign(Object.assign({}, sourceState), (_d = {}, _d[property] = propertyReducer(sourceState[property], action), _d));
573
- };
574
- }
575
- function setPropertiesReducer(sourceReducer, propertiesReducers) {
576
- return function reducer(state, action) {
577
- var newState = Object.assign({}, sourceReducer(state, action));
578
- for (var property in propertiesReducers) {
579
- newState[property] = propertiesReducers[property](newState[property], action);
580
- }
581
- return newState;
582
- };
583
- }
584
- function joinReducers(firstReducer, secondReducer) {
585
- return function reducer(state, action) {
586
- var sourceState = firstReducer(state, action);
587
- return secondReducer(sourceState, action);
588
- };
589
- }
650
+ /**
651
+ * Combine a map entityFeatureFactories into one,
652
+ * grouping the actions and selectors by the key of the respective entityFeatureFactory
653
+ * @param traitFactoriesMap
654
+ *
655
+ * @example
656
+ *
657
+ * const clientsFeatureFactory = createEntityFeatureFactory(
658
+ * { entityName: 'client', entitiesName: 'clients' },
659
+ * addLoadEntitiesTrait<Client>(),
660
+ * addCrudEntitiesTrait<Client>()
661
+ * );
662
+ *
663
+ * const productOrderFeatureFactory = createEntityFeatureFactory(
664
+ * { entityName: 'productOrder' },
665
+ * addLoadEntitiesTrait<ProductOrder>(),
666
+ * addSelectEntitiesTrait<ProductOrder>()
667
+ * );
668
+ *
669
+ * const productFeatureFactory = createEntityFeatureFactory(
670
+ * { entityName: 'product' },
671
+ * addLoadEntitiesTrait<Product>(),
672
+ * addSelectEntitiesTrait<Product>()
673
+ * );
674
+ *
675
+ * const productCombinedFactory = combineEntityFeatures({
676
+ * products: productFeatureFactory,
677
+ * productOrders: productOrderFeatureFactory,
678
+ * clients: clientsFeatureFactory,
679
+ * });
680
+ *
681
+ * const combinedFeature = productCombinedFactory({
682
+ * actionsGroupKey: '[Combined]',
683
+ * featureSelector: 'combined',
684
+ * });
685
+ *
686
+ * combinedFeature.actions.client.loadClients();
687
+ * combinedFeature.actions.product.loadProducts();
688
+ */
590
689
  function combineEntityFeatures(traitFactoriesMap) {
591
690
  return (function (config) {
592
691
  var e_3, _d;
@@ -629,6 +728,45 @@
629
728
  };
630
729
  });
631
730
  }
731
+ /**
732
+ * Mix a map entityFeatureFactories into one, different from combine the actions and selectors a mix, not group by key like in combine, the keys are still use
733
+ * internal in the reducers and selector to separate the state
734
+ * @param traitFactoriesMap
735
+ *
736
+ * @example
737
+ *
738
+ * const clientsFeatureFactory = createEntityFeatureFactory(
739
+ * { entityName: 'client', entitiesName: 'clients' },
740
+ * addLoadEntitiesTrait<Client>(),
741
+ * addCrudEntitiesTrait<Client>()
742
+ * );
743
+ *
744
+ * const productOrderFeatureFactory = createEntityFeatureFactory(
745
+ * { entityName: 'productOrder' },
746
+ * addLoadEntitiesTrait<ProductOrder>(),
747
+ * addSelectEntitiesTrait<ProductOrder>()
748
+ * );
749
+ *
750
+ * const productFeatureFactory = createEntityFeatureFactory(
751
+ * { entityName: 'product' },
752
+ * addLoadEntitiesTrait<Product>(),
753
+ * addSelectEntitiesTrait<Product>()
754
+ * );
755
+ *
756
+ * const productMixedFactory = mixEntityFeatures({
757
+ * products: productFeatureFactory,
758
+ * productOrders: productOrderFeatureFactory,
759
+ * clients: clientsFeatureFactory,
760
+ * });
761
+ *
762
+ * const mixedFeature = productMixedFactory({
763
+ * actionsGroupKey: '[Mixed]',
764
+ * featureSelector: 'mixed',
765
+ * });
766
+ * mixedFeature.actions.loadClients();
767
+ * mixedFeature.actions.loadProducts();
768
+ *
769
+ */
632
770
  function mixEntityFeatures(traitFactoriesMap) {
633
771
  return (function (config) {
634
772
  var e_4, _d;
@@ -671,6 +809,49 @@
671
809
  };
672
810
  });
673
811
  }
812
+ /**
813
+ * Combines targetTraitFactory with the traitFactoriesMap using the keys as props for the targetTraitFactory state,
814
+ * and grouping the combined actions by key
815
+ * @param targetTraitFactory
816
+ * @param traitFactoriesMap
817
+ *
818
+ * @example
819
+ *
820
+ * const clientsFeatureFactory = createEntityFeatureFactory(
821
+ * { entityName: 'client', entitiesName: 'clients' },
822
+ * addLoadEntitiesTrait<Client>(),
823
+ * addCrudEntitiesTrait<Client>()
824
+ * );
825
+ *
826
+ * const productOrderFeatureFactory = createEntityFeatureFactory(
827
+ * { entityName: 'productOrder' },
828
+ * addLoadEntitiesTrait<ProductOrder>(),
829
+ * addSelectEntitiesTrait<ProductOrder>()
830
+ * );
831
+ *
832
+ * const productFeatureFactory = createEntityFeatureFactory(
833
+ * { entityName: 'product' },
834
+ * addLoadEntitiesTrait<Product>(),
835
+ * addSelectEntitiesTrait<Product>()
836
+ * );
837
+ *
838
+ * const productAddEntityPropertiesFactory = addEntityFeaturesProperties(
839
+ * productFeatureFactory,
840
+ * {
841
+ * productOrders: productOrderFeatureFactory,
842
+ * clients: clientsFeatureFactory,
843
+ * }
844
+ * );
845
+ *
846
+ * const combinedFeature = productAddEntityPropertiesFactory({
847
+ * actionsGroupKey: '[addEntityFeatures]',
848
+ * featureSelector: 'addEntityFeatures',
849
+ * });
850
+ *
851
+ * combinedFeature.actions.loadProducts();
852
+ * combinedFeature.actions.clients.loadClients();
853
+ * combinedFeature.actions.productOrders.loadProductOrders();
854
+ */
674
855
  function addEntityFeaturesProperties(targetTraitFactory, traitFactoriesMap) {
675
856
  return (function (config) {
676
857
  var e_5, _d;
@@ -717,38 +898,13 @@
717
898
  };
718
899
  });
719
900
  }
720
- // export
721
- /// products:{actions, selectors, }, orders: {actions,slectors}
722
- /// { actions: {ProductActions, OrderActions}, selectors: {ProductSelectors, OrderSelectors}
723
- // TODO finish implementing combineTrais and addPropertiesTraits
724
- // TODO finish renaming traits
725
-
726
- // type G = ReplaceProps<
727
- // ReplaceProps<
728
- // {
729
- // loadEntities: 1;
730
- // loadEntitiesSuccess: 2;
731
- // selectEntities: 3;
732
- // selectEntity: 4;
733
- // },
734
- // 'Entities',
735
- // 'products'
736
- // >,
737
- // 'Entity',
738
- // 'product'
739
- // >;
740
- //
741
- // const g: G = {};
742
- // // g.
743
- // type F= ReplaceEntityNames<{
744
- // loadEntities: 1;
745
- // loadEntitiesSuccess: 2;
746
- // selectEntities: 3;
747
- // selectEntity: 4;
748
- // }, 'product','products'>;
749
- // const f: F = {};
750
- // f.
751
- // TODO clean up file
901
+ /**
902
+ * Helper function to create an implementation a TraitFactory
903
+ * @param f TraitFactory implementation
904
+ */
905
+ function createTraitFactory(f) {
906
+ return f;
907
+ }
752
908
 
753
909
  var TraitEffect = /** @class */ (function () {
754
910
  function TraitEffect(actions$, store) {
@@ -767,9 +923,9 @@
767
923
  };
768
924
  return TraitEffect;
769
925
  }());
770
- TraitEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: TraitEffect, deps: [{ token: i1__namespace.Actions }, { token: i2__namespace.Store }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
771
- TraitEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: TraitEffect });
772
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: TraitEffect, decorators: [{
926
+ TraitEffect.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TraitEffect, deps: [{ token: i1__namespace.Actions }, { token: i2__namespace.Store }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
927
+ TraitEffect.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TraitEffect });
928
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TraitEffect, decorators: [{
773
929
  type: i0.Injectable
774
930
  }], ctorParameters: function () { return [{ type: i1__namespace.Actions }, { type: i2__namespace.Store }]; } });
775
931
  function getDestroyActionName(id) {
@@ -777,6 +933,7 @@
777
933
  }
778
934
 
779
935
  /**
936
+ * @ignore
780
937
  * @internal
781
938
  */
782
939
  var DISABLE_LOCAL_TRAIT_EFFECTS = new i0.InjectionToken('disableLocalTraitEffects');
@@ -785,6 +942,18 @@
785
942
  function uniqueComponentId() {
786
943
  return id++;
787
944
  }
945
+ /**
946
+ * Builds traitFactory and registers effects and reducers with
947
+ * a generated component id, returns build actions and selectors
948
+ * and a destroy method that will unergister the effects and reducers
949
+ * when called, and a addEffect which can be use to register extra effects
950
+ *
951
+ * Used inside TraitsLocalStore, can be used to create your
952
+ * own Component Service without extending TraitsLocalStore
953
+ * @param injector
954
+ * @param componentName
955
+ * @param traitFactory
956
+ */
788
957
  function buildLocalTraits(injector, componentName, traitFactory) {
789
958
  var _a;
790
959
  var reducers = injector.get(i2.ReducerManager);
@@ -831,6 +1000,67 @@
831
1000
  },
832
1001
  };
833
1002
  }
1003
+ /**
1004
+ * Class used to create local traits service, receives a trait factory, which will be
1005
+ * built and its reducers and effect register using a dynamic id when the service is built
1006
+ * and get destroyed when the onDestroy lifecycle method of the service is called, if the service
1007
+ * has effects this.traits.addEffects(this) should be call in the constructor
1008
+ *
1009
+ * @example
1010
+ * const productFeatureFactory = createEntityFeatureFactory(
1011
+ * { entityName: 'product' },
1012
+ * addLoadEntitiesTrait<Product>(),
1013
+ * addSelectEntityTrait<Product>(),
1014
+ * );
1015
+ *
1016
+ * Injectable()
1017
+ * export class ProductsLocalTraits extends TraitsLocalStore<
1018
+ * typeof productFeatureFactory
1019
+ * > {
1020
+ * loadProducts$ = createEffect(() =>
1021
+ * this.actions$.pipe(
1022
+ * ofType(this.localActions.loadProducts),
1023
+ * switchMap(() =>
1024
+ * //call your service to get the products data
1025
+ * this.productService.getProducts().pipe(
1026
+ * map((res) =>
1027
+ * this.localActions.loadProductsSuccess({ entities: res.resultList })
1028
+ * ),
1029
+ * catchError(() => of(this.localActions.loadProductsFail()))
1030
+ * )
1031
+ * )
1032
+ * )
1033
+ * );
1034
+ *
1035
+ * constructor(injector: Injector, private productService: ProductService) {
1036
+ * super(injector);
1037
+ * this.traits.addEffects(this); // IMPORTANT! add this line if the service has effects
1038
+ * }
1039
+ *
1040
+ * setup(): LocalTraitsConfig<typeof productFeatureFactory> {
1041
+ * return {
1042
+ * componentName: 'ProductsPickerComponent',
1043
+ * traitsFactory: productFeatureFactory,
1044
+ * };
1045
+ * }
1046
+ * }
1047
+ *
1048
+ * // use in component later
1049
+ *
1050
+ * Component({
1051
+ * selector: 'some-component',
1052
+ * template: `<div> some content</div> `,
1053
+ * providers: [ProductsLocalTraits],
1054
+ * changeDetection: ChangeDetectionStrategy.OnPush,
1055
+ * })
1056
+ * export class ProductSelectDialogComponent implements OnInit {
1057
+ * constructor(private store: Store, private traits: ProductsLocalTraits) {}
1058
+ *
1059
+ * ngOnInit() {
1060
+ * this.store.dispatch(this.traits.localActions.loadProducts());
1061
+ * }
1062
+ * }
1063
+ */
834
1064
  var TraitsLocalStore = /** @class */ (function (_super) {
835
1065
  __extends(TraitsLocalStore, _super);
836
1066
  function TraitsLocalStore(injector) {
@@ -847,9 +1077,9 @@
847
1077
  };
848
1078
  return TraitsLocalStore;
849
1079
  }(TraitEffect));
850
- TraitsLocalStore.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: TraitsLocalStore, deps: [{ token: i0__namespace.Injector }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
851
- TraitsLocalStore.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: TraitsLocalStore });
852
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: TraitsLocalStore, decorators: [{
1080
+ TraitsLocalStore.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TraitsLocalStore, deps: [{ token: i0__namespace.Injector }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1081
+ TraitsLocalStore.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TraitsLocalStore });
1082
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: TraitsLocalStore, decorators: [{
853
1083
  type: i0.Injectable
854
1084
  }], ctorParameters: function () { return [{ type: i0__namespace.Injector }]; } });
855
1085
 
@@ -1166,10 +1396,10 @@
1166
1396
  }
1167
1397
  return CacheModule;
1168
1398
  }());
1169
- CacheModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: CacheModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1170
- CacheModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: CacheModule, imports: [i2__namespace.StoreFeatureModule] });
1171
- CacheModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: CacheModule, providers: [], imports: [[i2.StoreModule.forFeature('cache', cacheReducer)]] });
1172
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.1.2", ngImport: i0__namespace, type: CacheModule, decorators: [{
1399
+ CacheModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: CacheModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
1400
+ CacheModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: CacheModule, imports: [i2__namespace.StoreFeatureModule] });
1401
+ CacheModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: CacheModule, providers: [], imports: [[i2.StoreModule.forFeature('cache', cacheReducer)]] });
1402
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.16", ngImport: i0__namespace, type: CacheModule, decorators: [{
1173
1403
  type: i0.NgModule,
1174
1404
  args: [{
1175
1405
  imports: [i2.StoreModule.forFeature('cache', cacheReducer)],
@@ -1208,5 +1438,5 @@
1208
1438
 
1209
1439
  Object.defineProperty(exports, '__esModule', { value: true });
1210
1440
 
1211
- })));
1441
+ }));
1212
1442
  //# sourceMappingURL=ngrx-traits-core.umd.js.map