@ngxs/store 3.8.0 → 3.8.1

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 (31) hide show
  1. package/bundles/ngxs-store-internals.umd.js +11 -7
  2. package/bundles/ngxs-store-internals.umd.js.map +1 -1
  3. package/bundles/ngxs-store.umd.js +222 -214
  4. package/bundles/ngxs-store.umd.js.map +1 -1
  5. package/esm2015/internals/initial-state.js +9 -6
  6. package/esm2015/internals/ngxs-bootstrapper.js +4 -3
  7. package/esm2015/src/actions-stream.js +7 -5
  8. package/esm2015/src/decorators/select/select-factory.js +4 -3
  9. package/esm2015/src/execution/internal-ngxs-execution-strategy.js +4 -3
  10. package/esm2015/src/internal/custom-rxjs-subjects.js +16 -5
  11. package/esm2015/src/internal/dispatcher.js +7 -5
  12. package/esm2015/src/internal/lifecycle-state-manager.js +4 -3
  13. package/esm2015/src/internal/state-context-factory.js +4 -3
  14. package/esm2015/src/internal/state-factory.js +24 -23
  15. package/esm2015/src/internal/state-operations.js +4 -4
  16. package/esm2015/src/internal/state-stream.js +4 -3
  17. package/esm2015/src/ivy/ivy-enabled-in-dev-mode.js +13 -6
  18. package/esm2015/src/module.js +6 -42
  19. package/esm2015/src/store.js +4 -3
  20. package/esm2015/src/symbols.js +10 -3
  21. package/fesm2015/ngxs-store-internals.js +11 -7
  22. package/fesm2015/ngxs-store-internals.js.map +1 -1
  23. package/fesm2015/ngxs-store.js +208 -200
  24. package/fesm2015/ngxs-store.js.map +1 -1
  25. package/internals/initial-state.d.ts +2 -2
  26. package/package.json +2 -2
  27. package/src/internal/custom-rxjs-subjects.d.ts +7 -2
  28. package/src/internal/state-factory.d.ts +10 -11
  29. package/src/internal/state-operations.d.ts +0 -1
  30. package/src/module.d.ts +0 -3
  31. package/src/symbols.d.ts +1 -0
@@ -1,11 +1,103 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { NgZone, PLATFORM_ID, Injectable, Inject, InjectionToken, inject, INJECTOR, ɵglobal, ErrorHandler, Optional, SkipSelf, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
3
3
  import * as i5 from '@ngxs/store/internals';
4
- import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY, InitialState } from '@ngxs/store/internals';
4
+ import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY } from '@ngxs/store/internals';
5
5
  import { isPlatformServer } from '@angular/common';
6
6
  import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable } from 'rxjs';
7
7
  import { filter, map, share, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
8
8
 
9
+ /**
10
+ * Returns the type from an action instance/class.
11
+ * @ignore
12
+ */
13
+ function getActionTypeFromInstance(action) {
14
+ if (action.constructor && action.constructor.type) {
15
+ return action.constructor.type;
16
+ }
17
+ else {
18
+ return action.type;
19
+ }
20
+ }
21
+ /**
22
+ * Matches a action
23
+ * @ignore
24
+ */
25
+ function actionMatcher(action1) {
26
+ const type1 = getActionTypeFromInstance(action1);
27
+ return function (action2) {
28
+ return type1 === getActionTypeFromInstance(action2);
29
+ };
30
+ }
31
+ /**
32
+ * Set a deeply nested value. Example:
33
+ *
34
+ * setValue({ foo: { bar: { eat: false } } },
35
+ * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
36
+ *
37
+ * While it traverses it also creates new objects from top down.
38
+ *
39
+ * @ignore
40
+ */
41
+ const setValue = (obj, prop, val) => {
42
+ obj = Object.assign({}, obj);
43
+ const split = prop.split('.');
44
+ const lastIndex = split.length - 1;
45
+ split.reduce((acc, part, index) => {
46
+ if (index === lastIndex) {
47
+ acc[part] = val;
48
+ }
49
+ else {
50
+ acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
51
+ }
52
+ return acc && acc[part];
53
+ }, obj);
54
+ return obj;
55
+ };
56
+ /**
57
+ * Get a deeply nested value. Example:
58
+ *
59
+ * getValue({ foo: bar: [] }, 'foo.bar') //=> []
60
+ *
61
+ * @ignore
62
+ */
63
+ const getValue = (obj, prop) => prop.split('.').reduce((acc, part) => acc && acc[part], obj);
64
+ /**
65
+ * Simple object check.
66
+ *
67
+ * isObject({a:1}) //=> true
68
+ * isObject(1) //=> false
69
+ *
70
+ * @ignore
71
+ */
72
+ const isObject$1 = (item) => {
73
+ return item && typeof item === 'object' && !Array.isArray(item);
74
+ };
75
+ /**
76
+ * Deep merge two objects.
77
+ *
78
+ * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
79
+ *
80
+ * @param base base object onto which `sources` will be applied
81
+ */
82
+ const mergeDeep = (base, ...sources) => {
83
+ if (!sources.length)
84
+ return base;
85
+ const source = sources.shift();
86
+ if (isObject$1(base) && isObject$1(source)) {
87
+ for (const key in source) {
88
+ if (isObject$1(source[key])) {
89
+ if (!base[key])
90
+ Object.assign(base, { [key]: {} });
91
+ mergeDeep(base[key], source[key]);
92
+ }
93
+ else {
94
+ Object.assign(base, { [key]: source[key] });
95
+ }
96
+ }
97
+ }
98
+ return mergeDeep(base, ...sources);
99
+ };
100
+
9
101
  function throwStateNameError(name) {
10
102
  throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
11
103
  }
@@ -95,6 +187,7 @@ function verifyZoneIsNotNooped(ngZone) {
95
187
  console.warn(getZoneWarningMessage());
96
188
  }
97
189
 
190
+ const ROOT_OPTIONS = new InjectionToken('ROOT_OPTIONS');
98
191
  const ROOT_STATE_TOKEN = new InjectionToken('ROOT_STATE_TOKEN');
99
192
  const FEATURE_STATE_TOKEN = new InjectionToken('FEATURE_STATE_TOKEN');
100
193
  const NGXS_PLUGINS = new InjectionToken('NGXS_PLUGINS');
@@ -127,9 +220,14 @@ class NgxsConfig {
127
220
  }
128
221
  }
129
222
  /** @nocollapse */ NgxsConfig.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
130
- /** @nocollapse */ NgxsConfig.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig });
223
+ /** @nocollapse */ NgxsConfig.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: (options) => mergeDeep(new NgxsConfig(), options), deps: [{ token: ROOT_OPTIONS }] });
131
224
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, decorators: [{
132
- type: Injectable
225
+ type: Injectable,
226
+ args: [{
227
+ providedIn: 'root',
228
+ useFactory: (options) => mergeDeep(new NgxsConfig(), options),
229
+ deps: [ROOT_OPTIONS]
230
+ }]
133
231
  }], ctorParameters: function () { return []; } });
134
232
  /**
135
233
  * Represents a basic change from a previous to a new value for a single state instance.
@@ -421,102 +519,10 @@ function topologicalSort(graph) {
421
519
  *
422
520
  * @ignore
423
521
  */
424
- function isObject$1(obj) {
522
+ function isObject(obj) {
425
523
  return (typeof obj === 'object' && obj !== null) || typeof obj === 'function';
426
524
  }
427
525
 
428
- /**
429
- * Returns the type from an action instance/class.
430
- * @ignore
431
- */
432
- function getActionTypeFromInstance(action) {
433
- if (action.constructor && action.constructor.type) {
434
- return action.constructor.type;
435
- }
436
- else {
437
- return action.type;
438
- }
439
- }
440
- /**
441
- * Matches a action
442
- * @ignore
443
- */
444
- function actionMatcher(action1) {
445
- const type1 = getActionTypeFromInstance(action1);
446
- return function (action2) {
447
- return type1 === getActionTypeFromInstance(action2);
448
- };
449
- }
450
- /**
451
- * Set a deeply nested value. Example:
452
- *
453
- * setValue({ foo: { bar: { eat: false } } },
454
- * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
455
- *
456
- * While it traverses it also creates new objects from top down.
457
- *
458
- * @ignore
459
- */
460
- const setValue = (obj, prop, val) => {
461
- obj = Object.assign({}, obj);
462
- const split = prop.split('.');
463
- const lastIndex = split.length - 1;
464
- split.reduce((acc, part, index) => {
465
- if (index === lastIndex) {
466
- acc[part] = val;
467
- }
468
- else {
469
- acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
470
- }
471
- return acc && acc[part];
472
- }, obj);
473
- return obj;
474
- };
475
- /**
476
- * Get a deeply nested value. Example:
477
- *
478
- * getValue({ foo: bar: [] }, 'foo.bar') //=> []
479
- *
480
- * @ignore
481
- */
482
- const getValue = (obj, prop) => prop.split('.').reduce((acc, part) => acc && acc[part], obj);
483
- /**
484
- * Simple object check.
485
- *
486
- * isObject({a:1}) //=> true
487
- * isObject(1) //=> false
488
- *
489
- * @ignore
490
- */
491
- const isObject = (item) => {
492
- return item && typeof item === 'object' && !Array.isArray(item);
493
- };
494
- /**
495
- * Deep merge two objects.
496
- *
497
- * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
498
- *
499
- * @param base base object onto which `sources` will be applied
500
- */
501
- const mergeDeep = (base, ...sources) => {
502
- if (!sources.length)
503
- return base;
504
- const source = sources.shift();
505
- if (isObject(base) && isObject(source)) {
506
- for (const key in source) {
507
- if (isObject(source[key])) {
508
- if (!base[key])
509
- Object.assign(base, { [key]: {} });
510
- mergeDeep(base[key], source[key]);
511
- }
512
- else {
513
- Object.assign(base, { [key]: source[key] });
514
- }
515
- }
516
- }
517
- return mergeDeep(base, ...sources);
518
- };
519
-
520
526
  /**
521
527
  * RxJS operator for selecting out specific actions.
522
528
  *
@@ -651,9 +657,10 @@ class InternalNgxsExecutionStrategy {
651
657
  }
652
658
  }
653
659
  /** @nocollapse */ InternalNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [{ token: NGXS_EXECUTION_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
654
- /** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy });
660
+ /** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' });
655
661
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
656
- type: Injectable
662
+ type: Injectable,
663
+ args: [{ providedIn: 'root' }]
657
664
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
658
665
  type: Inject,
659
666
  args: [NGXS_EXECUTION_STRATEGY]
@@ -714,7 +721,10 @@ function orderedQueueOperation(operation) {
714
721
  class OrderedSubject extends Subject {
715
722
  constructor() {
716
723
  super(...arguments);
717
- this.next = orderedQueueOperation((value) => super.next(value));
724
+ this._orderedNext = orderedQueueOperation((value) => super.next(value));
725
+ }
726
+ next(value) {
727
+ this._orderedNext(value);
718
728
  }
719
729
  }
720
730
  /**
@@ -733,9 +743,17 @@ class OrderedSubject extends Subject {
733
743
  * When `subject` is a `OrderedBehaviorSubject<T>` the second subscriber would recieve `start` and then `end`.
734
744
  */
735
745
  class OrderedBehaviorSubject extends BehaviorSubject {
736
- constructor() {
737
- super(...arguments);
738
- this.next = orderedQueueOperation((value) => super.next(value));
746
+ constructor(value) {
747
+ super(value);
748
+ this._orderedNext = orderedQueueOperation((value) => super.next(value));
749
+ this._currentValue = value;
750
+ }
751
+ getValue() {
752
+ return this._currentValue;
753
+ }
754
+ next(value) {
755
+ this._currentValue = value;
756
+ this._orderedNext(value);
739
757
  }
740
758
  }
741
759
 
@@ -748,9 +766,10 @@ class InternalActions extends OrderedSubject {
748
766
  }
749
767
  }
750
768
  /** @nocollapse */ InternalActions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
751
- /** @nocollapse */ InternalActions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions });
769
+ /** @nocollapse */ InternalActions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, providedIn: 'root' });
752
770
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, decorators: [{
753
- type: Injectable
771
+ type: Injectable,
772
+ args: [{ providedIn: 'root' }]
754
773
  }] });
755
774
  /**
756
775
  * Action stream that is emitted anytime an action is dispatched.
@@ -776,9 +795,10 @@ class Actions extends Observable {
776
795
  }
777
796
  }
778
797
  /** @nocollapse */ Actions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, deps: [{ token: InternalActions }, { token: InternalNgxsExecutionStrategy }], target: i0.ɵɵFactoryTarget.Injectable });
779
- /** @nocollapse */ Actions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions });
798
+ /** @nocollapse */ Actions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, providedIn: 'root' });
780
799
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, decorators: [{
781
- type: Injectable
800
+ type: Injectable,
801
+ args: [{ providedIn: 'root' }]
782
802
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalNgxsExecutionStrategy }]; } });
783
803
 
784
804
  /**
@@ -883,9 +903,10 @@ class StateStream extends OrderedBehaviorSubject {
883
903
  }
884
904
  }
885
905
  /** @nocollapse */ StateStream.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
886
- /** @nocollapse */ StateStream.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream });
906
+ /** @nocollapse */ StateStream.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, providedIn: 'root' });
887
907
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, decorators: [{
888
- type: Injectable
908
+ type: Injectable,
909
+ args: [{ providedIn: 'root' }]
889
910
  }], ctorParameters: function () { return []; } });
890
911
 
891
912
  class PluginManager {
@@ -931,9 +952,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
931
952
  class InternalDispatchedActionResults extends Subject {
932
953
  }
933
954
  /** @nocollapse */ InternalDispatchedActionResults.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
934
- /** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults });
955
+ /** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults, providedIn: 'root' });
935
956
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults, decorators: [{
936
- type: Injectable
957
+ type: Injectable,
958
+ args: [{ providedIn: 'root' }]
937
959
  }] });
938
960
  class InternalDispatcher {
939
961
  constructor(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
@@ -1003,9 +1025,10 @@ class InternalDispatcher {
1003
1025
  }
1004
1026
  }
1005
1027
  /** @nocollapse */ InternalDispatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher, deps: [{ token: InternalActions }, { token: InternalDispatchedActionResults }, { token: PluginManager }, { token: StateStream }, { token: InternalNgxsExecutionStrategy }, { token: InternalErrorReporter }], target: i0.ɵɵFactoryTarget.Injectable });
1006
- /** @nocollapse */ InternalDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher });
1028
+ /** @nocollapse */ InternalDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher, providedIn: 'root' });
1007
1029
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher, decorators: [{
1008
- type: Injectable
1030
+ type: Injectable,
1031
+ args: [{ providedIn: 'root' }]
1009
1032
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalDispatchedActionResults }, { type: PluginManager }, { type: StateStream }, { type: InternalNgxsExecutionStrategy }, { type: InternalErrorReporter }]; } });
1010
1033
 
1011
1034
  /**
@@ -1029,7 +1052,6 @@ const deepFreeze = (o) => {
1029
1052
  };
1030
1053
 
1031
1054
  /**
1032
- * State Context factory class
1033
1055
  * @ignore
1034
1056
  */
1035
1057
  class InternalStateOperations {
@@ -1065,9 +1087,10 @@ class InternalStateOperations {
1065
1087
  }
1066
1088
  }
1067
1089
  /** @nocollapse */ InternalStateOperations.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations, deps: [{ token: StateStream }, { token: InternalDispatcher }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
1068
- /** @nocollapse */ InternalStateOperations.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations });
1090
+ /** @nocollapse */ InternalStateOperations.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations, providedIn: 'root' });
1069
1091
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations, decorators: [{
1070
- type: Injectable
1092
+ type: Injectable,
1093
+ args: [{ providedIn: 'root' }]
1071
1094
  }], ctorParameters: function () { return [{ type: StateStream }, { type: InternalDispatcher }, { type: NgxsConfig }]; } });
1072
1095
  function ensureStateAndActionsAreImmutable(root) {
1073
1096
  return {
@@ -1159,9 +1182,10 @@ class StateContextFactory {
1159
1182
  }
1160
1183
  }
1161
1184
  /** @nocollapse */ StateContextFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory, deps: [{ token: InternalStateOperations }], target: i0.ɵɵFactoryTarget.Injectable });
1162
- /** @nocollapse */ StateContextFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory });
1185
+ /** @nocollapse */ StateContextFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory, providedIn: 'root' });
1163
1186
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory, decorators: [{
1164
- type: Injectable
1187
+ type: Injectable,
1188
+ args: [{ providedIn: 'root' }]
1165
1189
  }], ctorParameters: function () { return [{ type: InternalStateOperations }]; } });
1166
1190
 
1167
1191
  class StoreValidators {
@@ -1195,15 +1219,22 @@ StoreValidators.stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
1195
1219
  * if another decorator was used, e.g. pipes).
1196
1220
  */
1197
1221
  function ensureStateClassIsInjectable(stateClass) {
1222
+ if (jit_hasInjectableAnnotation(stateClass) || aot_hasNgInjectableDef(stateClass)) {
1223
+ return;
1224
+ }
1225
+ console.warn(getUndecoratedStateInIvyWarningMessage(stateClass.name));
1226
+ }
1227
+ function aot_hasNgInjectableDef(stateClass) {
1198
1228
  // `ɵprov` is a static property added by the NGCC compiler. It always exists in
1199
1229
  // AOT mode because this property is added before runtime. If an application is running in
1200
1230
  // JIT mode then this property can be added by the `@Injectable()` decorator. The `@Injectable()`
1201
1231
  // decorator has to go after the `@State()` decorator, thus we prevent users from unwanted DI errors.
1202
- const ngInjectableDef = stateClass.ɵprov;
1203
- if (!ngInjectableDef) {
1204
- // Don't warn if Ivy is disabled or `ɵprov` exists on the class
1205
- console.warn(getUndecoratedStateInIvyWarningMessage(stateClass.name));
1206
- }
1232
+ return !!stateClass.ɵprov;
1233
+ }
1234
+ function jit_hasInjectableAnnotation(stateClass) {
1235
+ // `ɵprov` doesn't exist in JIT mode (for instance when running unit tests with Jest).
1236
+ const annotations = stateClass.__annotations__ || [];
1237
+ return annotations.some((annotation) => (annotation === null || annotation === void 0 ? void 0 : annotation.ngMetadataName) === 'Injectable');
1207
1238
  }
1208
1239
 
1209
1240
  /**
@@ -1274,8 +1305,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
1274
1305
  args: [NGXS_DEVELOPMENT_OPTIONS]
1275
1306
  }] }]; } });
1276
1307
 
1308
+ const NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
1277
1309
  /**
1278
- * State factory class
1310
+ * The `StateFactory` class adds root and feature states to the graph.
1311
+ * This extracts state names from state classes, checks if they already
1312
+ * exist in the global graph, throws errors if their names are invalid, etc.
1313
+ * See its constructor, state factories inject state factories that are
1314
+ * parent-level providers. This is required to get feature states from the
1315
+ * injector on the same level.
1316
+ *
1317
+ * The `NgxsModule.forFeature(...)` returns `providers: [StateFactory, ...states]`.
1318
+ * The `StateFactory` is initialized on the feature level and goes through `...states`
1319
+ * to get them from the injector through `injector.get(state)`.
1279
1320
  * @ignore
1280
1321
  */
1281
1322
  class StateFactory {
@@ -1336,7 +1377,7 @@ class StateFactory {
1336
1377
  if (Array.isArray(defaults)) {
1337
1378
  value = defaults.slice();
1338
1379
  }
1339
- else if (isObject$1(defaults)) {
1380
+ else if (isObject(defaults)) {
1340
1381
  value = Object.assign({}, defaults);
1341
1382
  }
1342
1383
  else if (defaults === undefined) {
@@ -1348,17 +1389,14 @@ class StateFactory {
1348
1389
  return value;
1349
1390
  }
1350
1391
  ngOnDestroy() {
1351
- // This is being non-null asserted since `_actionsSubscrition` is
1352
- // initialized within the constructor.
1353
- this._actionsSubscription.unsubscribe();
1392
+ var _a;
1393
+ (_a = this._actionsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1354
1394
  }
1355
1395
  /**
1356
1396
  * Add a new state to the global defs.
1357
1397
  */
1358
1398
  add(stateClasses) {
1359
- // Caretaker note: we have still left the `typeof` condition in order to avoid
1360
- // creating a breaking change for projects that still use the View Engine.
1361
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
1399
+ if (NG_DEV_MODE) {
1362
1400
  StoreValidators.checkThatStateClassesHaveBeenDecorated(stateClasses);
1363
1401
  }
1364
1402
  const { newStates } = this.addToStatesMap(stateClasses);
@@ -1408,12 +1446,13 @@ class StateFactory {
1408
1446
  const defaults = mappedStores.reduce((result, mappedStore) => setValue(result, mappedStore.path, mappedStore.defaults), {});
1409
1447
  return { defaults, states: mappedStores };
1410
1448
  }
1411
- /**
1412
- * Bind the actions to the handlers
1413
- */
1414
1449
  connectActionHandlers() {
1415
- if (this._actionsSubscription !== null)
1450
+ // Note: We have to connect actions only once when the `StateFactory`
1451
+ // is being created for the first time. This checks if we're in
1452
+ // a child state factory and the parent state factory already exists.
1453
+ if (this._parentFactory || this._actionsSubscription !== null) {
1416
1454
  return;
1455
+ }
1417
1456
  const dispatched$ = new Subject();
1418
1457
  this._actionsSubscription = this._actions
1419
1458
  .pipe(filter((ctx) => ctx.status === "DISPATCHED" /* Dispatched */), mergeMap(ctx => {
@@ -1479,7 +1518,7 @@ class StateFactory {
1479
1518
  }
1480
1519
  // The `NgxsUnhandledActionsLogger` is a tree-shakable class which functions
1481
1520
  // only during development.
1482
- if ((typeof ngDevMode === 'undefined' || ngDevMode) && !actionHasBeenHandled) {
1521
+ if (NG_DEV_MODE && !actionHasBeenHandled) {
1483
1522
  const unhandledActionsLogger = this._injector.get(NgxsUnhandledActionsLogger, null);
1484
1523
  // The `NgxsUnhandledActionsLogger` will not be resolved by the injector if the
1485
1524
  // `NgxsDevelopmentModule` is not provided. It's enough to check whether the `injector.get`
@@ -1498,9 +1537,7 @@ class StateFactory {
1498
1537
  const statesMap = this.statesByName;
1499
1538
  for (const stateClass of stateClasses) {
1500
1539
  const stateName = getStoreMetadata$1(stateClass).name;
1501
- // Caretaker note: we have still left the `typeof` condition in order to avoid
1502
- // creating a breaking change for projects that still use the View Engine.
1503
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
1540
+ if (NG_DEV_MODE) {
1504
1541
  StoreValidators.checkThatStateNameIsUnique(stateName, stateClass, statesMap);
1505
1542
  }
1506
1543
  const unmountedState = !statesMap[stateName];
@@ -1518,15 +1555,10 @@ class StateFactory {
1518
1555
  // We will need to come up with an alternative in v4 because this is used by many plugins
1519
1556
  meta.path = path;
1520
1557
  }
1521
- /**
1522
- * @description
1523
- * the method checks if the state has already been added to the tree
1524
- * and completed the life cycle
1525
- * @param name
1526
- * @param path
1527
- */
1528
1558
  hasBeenMountedAndBootstrapped(name, path) {
1529
1559
  const valueIsBootstrappedInInitialState = getValue(this._initialState, path) !== undefined;
1560
+ // This checks whether a state has been already added to the global graph and
1561
+ // its lifecycle is in 'bootstrapped' state.
1530
1562
  return this.statesByName[name] && valueIsBootstrappedInInitialState;
1531
1563
  }
1532
1564
  }
@@ -1696,9 +1728,10 @@ class Store {
1696
1728
  }
1697
1729
  }
1698
1730
  /** @nocollapse */ Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store, deps: [{ token: StateStream }, { token: InternalStateOperations }, { token: NgxsConfig }, { token: InternalNgxsExecutionStrategy }, { token: StateFactory }, { token: INITIAL_STATE_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
1699
- /** @nocollapse */ Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store });
1731
+ /** @nocollapse */ Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store, providedIn: 'root' });
1700
1732
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store, decorators: [{
1701
- type: Injectable
1733
+ type: Injectable,
1734
+ args: [{ providedIn: 'root' }]
1702
1735
  }], ctorParameters: function () { return [{ type: StateStream }, { type: InternalStateOperations }, { type: NgxsConfig }, { type: InternalNgxsExecutionStrategy }, { type: StateFactory }, { type: undefined, decorators: [{
1703
1736
  type: Optional
1704
1737
  }, {
@@ -1706,6 +1739,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
1706
1739
  args: [INITIAL_STATE_TOKEN]
1707
1740
  }] }]; } });
1708
1741
 
1742
+ /**
1743
+ * Allows the select decorator to get access to the DI store, this is used internally
1744
+ * in `@Select` decorator.
1745
+ */
1746
+ class SelectFactory {
1747
+ constructor(store, config) {
1748
+ SelectFactory.store = store;
1749
+ SelectFactory.config = config;
1750
+ }
1751
+ ngOnDestroy() {
1752
+ SelectFactory.store = null;
1753
+ SelectFactory.config = null;
1754
+ }
1755
+ }
1756
+ SelectFactory.store = null;
1757
+ SelectFactory.config = null;
1758
+ /** @nocollapse */ SelectFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, deps: [{ token: Store }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
1759
+ /** @nocollapse */ SelectFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, providedIn: 'root' });
1760
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, decorators: [{
1761
+ type: Injectable,
1762
+ args: [{ providedIn: 'root' }]
1763
+ }], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
1764
+
1709
1765
  class LifecycleStateManager {
1710
1766
  constructor(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
1711
1767
  this._store = _store;
@@ -1763,33 +1819,12 @@ class LifecycleStateManager {
1763
1819
  }
1764
1820
  }
1765
1821
  /** @nocollapse */ LifecycleStateManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager, deps: [{ token: Store }, { token: InternalErrorReporter }, { token: InternalStateOperations }, { token: StateContextFactory }, { token: i5.NgxsBootstrapper }], target: i0.ɵɵFactoryTarget.Injectable });
1766
- /** @nocollapse */ LifecycleStateManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager });
1822
+ /** @nocollapse */ LifecycleStateManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager, providedIn: 'root' });
1767
1823
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager, decorators: [{
1768
- type: Injectable
1824
+ type: Injectable,
1825
+ args: [{ providedIn: 'root' }]
1769
1826
  }], ctorParameters: function () { return [{ type: Store }, { type: InternalErrorReporter }, { type: InternalStateOperations }, { type: StateContextFactory }, { type: i5.NgxsBootstrapper }]; } });
1770
1827
 
1771
- /**
1772
- * Allows the select decorator to get access to the DI store, this is used internally
1773
- * in `@Select` decorator.
1774
- */
1775
- class SelectFactory {
1776
- constructor(store, config) {
1777
- SelectFactory.store = store;
1778
- SelectFactory.config = config;
1779
- }
1780
- ngOnDestroy() {
1781
- SelectFactory.store = null;
1782
- SelectFactory.config = null;
1783
- }
1784
- }
1785
- SelectFactory.store = null;
1786
- SelectFactory.config = null;
1787
- /** @nocollapse */ SelectFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, deps: [{ token: Store }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
1788
- /** @nocollapse */ SelectFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory });
1789
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, decorators: [{
1790
- type: Injectable
1791
- }], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
1792
-
1793
1828
  /**
1794
1829
  * Root module
1795
1830
  * @ignore
@@ -1862,18 +1897,6 @@ class NgxsModule {
1862
1897
  ngModule: NgxsRootModule,
1863
1898
  providers: [
1864
1899
  StateFactory,
1865
- StateContextFactory,
1866
- Actions,
1867
- InternalActions,
1868
- NgxsBootstrapper,
1869
- LifecycleStateManager,
1870
- InternalDispatcher,
1871
- InternalDispatchedActionResults,
1872
- InternalStateOperations,
1873
- InternalNgxsExecutionStrategy,
1874
- Store,
1875
- StateStream,
1876
- SelectFactory,
1877
1900
  PluginManager,
1878
1901
  ...states,
1879
1902
  ...NgxsModule.ngxsTokenProviders(states, options)
@@ -1887,6 +1910,7 @@ class NgxsModule {
1887
1910
  return {
1888
1911
  ngModule: NgxsFeatureModule,
1889
1912
  providers: [
1913
+ // This is required on the feature level, see comments in `state-factory.ts`.
1890
1914
  StateFactory,
1891
1915
  PluginManager,
1892
1916
  ...states,
@@ -1909,24 +1933,15 @@ class NgxsModule {
1909
1933
  useValue: states
1910
1934
  },
1911
1935
  {
1912
- provide: NgxsModule.ROOT_OPTIONS,
1936
+ provide: ROOT_OPTIONS,
1913
1937
  useValue: options
1914
1938
  },
1915
- {
1916
- provide: NgxsConfig,
1917
- useFactory: NgxsModule.ngxsConfigFactory,
1918
- deps: [NgxsModule.ROOT_OPTIONS]
1919
- },
1920
1939
  {
1921
1940
  provide: APP_BOOTSTRAP_LISTENER,
1922
1941
  useFactory: NgxsModule.appBootstrapListenerFactory,
1923
1942
  multi: true,
1924
1943
  deps: [NgxsBootstrapper]
1925
1944
  },
1926
- {
1927
- provide: INITIAL_STATE_TOKEN,
1928
- useFactory: NgxsModule.getInitialState
1929
- },
1930
1945
  {
1931
1946
  provide: ɵNGXS_STATE_CONTEXT_FACTORY,
1932
1947
  useExisting: StateContextFactory
@@ -1937,17 +1952,10 @@ class NgxsModule {
1937
1952
  }
1938
1953
  ];
1939
1954
  }
1940
- static ngxsConfigFactory(options) {
1941
- return mergeDeep(new NgxsConfig(), options);
1942
- }
1943
1955
  static appBootstrapListenerFactory(bootstrapper) {
1944
1956
  return () => bootstrapper.bootstrap();
1945
1957
  }
1946
- static getInitialState() {
1947
- return InitialState.pop();
1948
- }
1949
1958
  }
1950
- NgxsModule.ROOT_OPTIONS = new InjectionToken('ROOT_OPTIONS');
1951
1959
  /** @nocollapse */ NgxsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1952
1960
  /** @nocollapse */ NgxsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule });
1953
1961
  /** @nocollapse */ NgxsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule });