@ngxs/store 3.7.3 → 3.7.4

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 (121) hide show
  1. package/bundles/ngxs-store-internals-testing.umd.js +114 -11
  2. package/bundles/ngxs-store-internals-testing.umd.js.map +1 -1
  3. package/bundles/ngxs-store-internals-testing.umd.min.js +1 -1
  4. package/bundles/ngxs-store-internals-testing.umd.min.js.map +1 -1
  5. package/bundles/ngxs-store-internals.umd.js +278 -91
  6. package/bundles/ngxs-store-internals.umd.js.map +1 -1
  7. package/bundles/ngxs-store-internals.umd.min.js +1 -1
  8. package/bundles/ngxs-store-internals.umd.min.js.map +1 -1
  9. package/bundles/ngxs-store.umd.js +457 -484
  10. package/bundles/ngxs-store.umd.js.map +1 -1
  11. package/bundles/ngxs-store.umd.min.js +1 -1
  12. package/bundles/ngxs-store.umd.min.js.map +1 -1
  13. package/esm2015/internals/angular.js +12 -32
  14. package/esm2015/internals/decorator-injector-adapter.js +204 -0
  15. package/esm2015/internals/index.js +2 -1
  16. package/esm2015/internals/ngxs-store-internals.js +2 -2
  17. package/esm2015/internals/testing/fresh-platform.js +46 -7
  18. package/esm2015/internals/testing/index.js +2 -1
  19. package/esm2015/internals/testing/ngxs-store-internals-testing.js +2 -2
  20. package/esm2015/internals/testing/skip-console-logging.js +62 -0
  21. package/esm2015/internals/testing/symbol.js +1 -1
  22. package/esm2015/ngxs-store.js +14 -18
  23. package/esm2015/src/configs/messages.config.js +74 -82
  24. package/esm2015/src/decorators/action.js +10 -6
  25. package/esm2015/src/decorators/select/select-factory.js +8 -5
  26. package/esm2015/src/decorators/select/select.js +39 -3
  27. package/esm2015/src/decorators/select/symbols.js +56 -12
  28. package/esm2015/src/decorators/selector/selector.js +10 -6
  29. package/esm2015/src/decorators/state.js +12 -4
  30. package/esm2015/src/execution/dispatch-outside-zone-ngxs-execution-strategy.js +25 -18
  31. package/esm2015/src/execution/noop-ngxs-execution-strategy.js +4 -2
  32. package/esm2015/src/execution/symbols.js +26 -3
  33. package/esm2015/src/internal/internals.js +8 -4
  34. package/esm2015/src/internal/state-factory.js +46 -26
  35. package/esm2015/src/internal/state-operations.js +47 -39
  36. package/esm2015/src/internal/state-operators.js +4 -4
  37. package/esm2015/src/internal/state-stream.js +10 -1
  38. package/esm2015/src/ivy/ivy-enabled-in-dev-mode.js +18 -30
  39. package/esm2015/src/module.js +7 -22
  40. package/esm2015/src/modules/ngxs-root.module.js +8 -8
  41. package/esm2015/src/store.js +20 -4
  42. package/esm2015/src/symbols.js +4 -5
  43. package/esm2015/src/utils/store-validators.js +24 -29
  44. package/esm5/internals/angular.js +12 -32
  45. package/esm5/internals/decorator-injector-adapter.js +204 -0
  46. package/esm5/internals/index.js +2 -1
  47. package/esm5/internals/ngxs-store-internals.js +2 -2
  48. package/esm5/internals/testing/fresh-platform.js +53 -13
  49. package/esm5/internals/testing/index.js +2 -1
  50. package/esm5/internals/testing/ngxs-store-internals-testing.js +2 -2
  51. package/esm5/internals/testing/skip-console-logging.js +62 -0
  52. package/esm5/internals/testing/symbol.js +1 -1
  53. package/esm5/ngxs-store.js +14 -18
  54. package/esm5/src/configs/messages.config.js +75 -100
  55. package/esm5/src/decorators/action.js +10 -6
  56. package/esm5/src/decorators/select/select-factory.js +8 -5
  57. package/esm5/src/decorators/select/select.js +40 -3
  58. package/esm5/src/decorators/select/symbols.js +56 -12
  59. package/esm5/src/decorators/selector/selector.js +10 -6
  60. package/esm5/src/decorators/state.js +12 -4
  61. package/esm5/src/execution/dispatch-outside-zone-ngxs-execution-strategy.js +25 -23
  62. package/esm5/src/execution/noop-ngxs-execution-strategy.js +4 -2
  63. package/esm5/src/execution/symbols.js +26 -3
  64. package/esm5/src/internal/internals.js +8 -4
  65. package/esm5/src/internal/state-factory.js +39 -27
  66. package/esm5/src/internal/state-operations.js +47 -43
  67. package/esm5/src/internal/state-operators.js +4 -4
  68. package/esm5/src/internal/state-stream.js +13 -1
  69. package/esm5/src/ivy/ivy-enabled-in-dev-mode.js +18 -30
  70. package/esm5/src/module.js +7 -22
  71. package/esm5/src/modules/ngxs-root.module.js +7 -7
  72. package/esm5/src/store.js +20 -4
  73. package/esm5/src/symbols.js +4 -5
  74. package/esm5/src/utils/store-validators.js +28 -36
  75. package/fesm2015/ngxs-store-internals-testing.js +108 -7
  76. package/fesm2015/ngxs-store-internals-testing.js.map +1 -1
  77. package/fesm2015/ngxs-store-internals.js +263 -79
  78. package/fesm2015/ngxs-store-internals.js.map +1 -1
  79. package/fesm2015/ngxs-store.js +429 -413
  80. package/fesm2015/ngxs-store.js.map +1 -1
  81. package/fesm5/ngxs-store-internals-testing.js +115 -13
  82. package/fesm5/ngxs-store-internals-testing.js.map +1 -1
  83. package/fesm5/ngxs-store-internals.js +277 -93
  84. package/fesm5/ngxs-store-internals.js.map +1 -1
  85. package/fesm5/ngxs-store.js +443 -465
  86. package/fesm5/ngxs-store.js.map +1 -1
  87. package/internals/angular.d.ts +1 -3
  88. package/internals/decorator-injector-adapter.d.ts +15 -0
  89. package/internals/index.d.ts +1 -0
  90. package/internals/ngxs-store-internals.metadata.json +1 -1
  91. package/internals/testing/fresh-platform.d.ts +1 -1
  92. package/internals/testing/index.d.ts +1 -0
  93. package/internals/testing/ngxs-store-internals-testing.metadata.json +1 -1
  94. package/internals/testing/skip-console-logging.d.ts +1 -0
  95. package/internals/testing/symbol.d.ts +1 -1
  96. package/ngxs-store.d.ts +14 -18
  97. package/ngxs-store.metadata.json +1 -1
  98. package/package.json +2 -2
  99. package/src/configs/messages.config.d.ts +11 -30
  100. package/src/decorators/select/select-factory.d.ts +2 -3
  101. package/src/decorators/select/symbols.d.ts +6 -2
  102. package/src/execution/dispatch-outside-zone-ngxs-execution-strategy.d.ts +0 -1
  103. package/src/execution/symbols.d.ts +5 -1
  104. package/src/internal/internals.d.ts +0 -1
  105. package/src/internal/state-factory.d.ts +2 -3
  106. package/src/internal/state-operations.d.ts +1 -3
  107. package/src/internal/state-stream.d.ts +3 -1
  108. package/src/ivy/ivy-enabled-in-dev-mode.d.ts +4 -12
  109. package/src/modules/ngxs-root.module.d.ts +2 -2
  110. package/src/store.d.ts +6 -0
  111. package/src/symbols.d.ts +4 -3
  112. package/src/utils/store-validators.d.ts +5 -6
  113. package/esm2015/src/host-environment/host-environment.js +0 -31
  114. package/esm2015/src/internal/config-validator.js +0 -67
  115. package/esm2015/src/ivy/ensure-state-class-is-injectable.js +0 -34
  116. package/esm5/src/host-environment/host-environment.js +0 -29
  117. package/esm5/src/internal/config-validator.js +0 -76
  118. package/esm5/src/ivy/ensure-state-class-is-injectable.js +0 -34
  119. package/src/host-environment/host-environment.d.ts +0 -6
  120. package/src/internal/config-validator.d.ts +0 -10
  121. package/src/ivy/ensure-state-class-is-injectable.d.ts +0 -6
@@ -1,94 +1,87 @@
1
- import { NgZone, Injectable, Inject, PLATFORM_ID, InjectionToken, Optional, SkipSelf, ErrorHandler, Injector, isDevMode, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
2
- import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, isAngularInTestMode, NGXS_STATE_CONTEXT_FACTORY, NGXS_STATE_FACTORY, InitialState } from '@ngxs/store/internals';
1
+ import { NgZone, Injectable, Inject, PLATFORM_ID, defineInjectable, inject, InjectionToken, INJECTOR, ɵglobal, Optional, SkipSelf, ErrorHandler, Injector, ɵivyEnabled, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
2
+ import { isAngularInTestMode, memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, NGXS_STATE_CONTEXT_FACTORY, NGXS_STATE_FACTORY, InitialState, ensureInjectorNotifierIsCaptured, localInject, ensureLocalInjectorCaptured } from '@ngxs/store/internals';
3
3
  import { isPlatformServer } from '@angular/common';
4
- import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, ReplaySubject } from 'rxjs';
5
- import { filter, map, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, tap, distinctUntilChanged } from 'rxjs/operators';
4
+ import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from } from 'rxjs';
5
+ import { filter, map, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, tap, publishReplay, refCount, distinctUntilChanged } from 'rxjs/operators';
6
6
 
7
7
  /**
8
8
  * @fileoverview added by tsickle
9
9
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
10
10
  */
11
- /** @enum {string} */
12
- const VALIDATION_CODE = {
13
- STATE_NAME: 'STATE_NAME',
14
- STATE_UNIQUE: 'STATE_UNIQUE',
15
- STATE_NAME_PROPERTY: 'STATE_NAME_PROPERTY',
16
- STATE_DECORATOR: 'STATE_DECORATOR',
17
- INCORRECT_PRODUCTION: 'INCORRECT_PRODUCTION',
18
- INCORRECT_DEVELOPMENT: 'INCORRECT_DEVELOPMENT',
19
- SELECT_FACTORY_NOT_CONNECTED: 'SELECT_FACTORY_NOT_CONNECTED',
20
- ACTION_DECORATOR: 'ACTION_DECORATOR',
21
- SELECTOR_DECORATOR: 'SELECTOR_DECORATOR',
22
- ZONE_WARNING: 'ZONE_WARNING',
23
- PATCHING_ARRAY: 'PATCHING_ARRAY',
24
- PATCHING_PRIMITIVE: 'PATCHING_PRIMITIVE',
25
- UNDECORATED_STATE_IN_IVY: 'UNDECORATED_STATE_IN_IVY',
26
- };
27
- /** @type {?} */
28
- const CONFIG_MESSAGES = {
29
- [VALIDATION_CODE.STATE_NAME]: (/**
30
- * @param {?} name
31
- * @return {?}
32
- */
33
- (name) => `${name} is not a valid state name. It needs to be a valid object property name.`),
34
- [VALIDATION_CODE.STATE_NAME_PROPERTY]: (/**
35
- * @return {?}
36
- */
37
- () => `States must register a 'name' property`),
38
- [VALIDATION_CODE.STATE_UNIQUE]: (/**
39
- * @param {?} current
40
- * @param {?} newName
41
- * @param {?} oldName
42
- * @return {?}
43
- */
44
- (current, newName, oldName) => `State name '${current}' from ${newName} already exists in ${oldName}`),
45
- [VALIDATION_CODE.STATE_DECORATOR]: (/**
46
- * @return {?}
47
- */
48
- () => 'States must be decorated with @State() decorator'),
49
- [VALIDATION_CODE.INCORRECT_PRODUCTION]: (/**
50
- * @return {?}
51
- */
52
- () => 'Angular is running in production mode but NGXS is still running in the development mode!\n' +
53
- 'Please set developmentMode to false on the NgxsModule options when in production mode.\n' +
54
- 'NgxsModule.forRoot(states, { developmentMode: !environment.production })'),
55
- [VALIDATION_CODE.INCORRECT_DEVELOPMENT]: (/**
56
- * @return {?}
57
- */
58
- () => 'RECOMMENDATION: Set developmentMode to true on the NgxsModule when Angular is running in development mode.\n' +
59
- 'NgxsModule.forRoot(states, { developmentMode: !environment.production })'),
60
- [VALIDATION_CODE.SELECT_FACTORY_NOT_CONNECTED]: (/**
61
- * @return {?}
62
- */
63
- () => 'You have forgotten to import the NGXS module!'),
64
- [VALIDATION_CODE.ACTION_DECORATOR]: (/**
65
- * @return {?}
66
- */
67
- () => '@Action() decorator cannot be used with static methods'),
68
- [VALIDATION_CODE.SELECTOR_DECORATOR]: (/**
69
- * @return {?}
70
- */
71
- () => 'Selectors only work on methods'),
72
- [VALIDATION_CODE.ZONE_WARNING]: (/**
73
- * @return {?}
74
- */
75
- () => 'Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
11
+ /**
12
+ * @param {?} name
13
+ * @return {?}
14
+ */
15
+ function throwStateNameError(name) {
16
+ throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
17
+ }
18
+ /**
19
+ * @return {?}
20
+ */
21
+ function throwStateNamePropertyError() {
22
+ throw new Error(`States must register a 'name' property.`);
23
+ }
24
+ /**
25
+ * @param {?} current
26
+ * @param {?} newName
27
+ * @param {?} oldName
28
+ * @return {?}
29
+ */
30
+ function throwStateUniqueError(current, newName, oldName) {
31
+ throw new Error(`State name '${current}' from ${newName} already exists in ${oldName}.`);
32
+ }
33
+ /**
34
+ * @param {?} name
35
+ * @return {?}
36
+ */
37
+ function throwStateDecoratorError(name) {
38
+ throw new Error(`States must be decorated with @State() decorator, but "${name}" isn't.`);
39
+ }
40
+ /**
41
+ * @return {?}
42
+ */
43
+ function throwActionDecoratorError() {
44
+ throw new Error('@Action() decorator cannot be used with static methods.');
45
+ }
46
+ /**
47
+ * @return {?}
48
+ */
49
+ function throwSelectorDecoratorError() {
50
+ throw new Error('Selectors only work on methods.');
51
+ }
52
+ /**
53
+ * @return {?}
54
+ */
55
+ function getZoneWarningMessage() {
56
+ return ('Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
76
57
  'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
77
- 'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })'),
78
- [VALIDATION_CODE.PATCHING_ARRAY]: (/**
79
- * @return {?}
80
- */
81
- () => 'Patching arrays is not supported.'),
82
- [VALIDATION_CODE.PATCHING_PRIMITIVE]: (/**
83
- * @return {?}
84
- */
85
- () => 'Patching primitives is not supported.'),
86
- [VALIDATION_CODE.UNDECORATED_STATE_IN_IVY]: (/**
87
- * @param {?} name
88
- * @return {?}
89
- */
90
- (name) => `'${name}' class should be decorated with @Injectable() right after the @State() decorator`)
91
- };
58
+ 'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })');
59
+ }
60
+ /**
61
+ * @param {?} name
62
+ * @return {?}
63
+ */
64
+ function getUndecoratedStateInIvyWarningMessage(name) {
65
+ return `'${name}' class should be decorated with @Injectable() right after the @State() decorator`;
66
+ }
67
+ /**
68
+ * @return {?}
69
+ */
70
+ function throwSelectFactoryNotConnectedError() {
71
+ throw new Error('You have forgotten to import the NGXS module!');
72
+ }
73
+ /**
74
+ * @return {?}
75
+ */
76
+ function throwPatchingArrayError() {
77
+ throw new Error('Patching arrays is not supported.');
78
+ }
79
+ /**
80
+ * @return {?}
81
+ */
82
+ function throwPatchingPrimitiveError() {
83
+ throw new Error('Patching primitives is not supported.');
84
+ }
92
85
 
93
86
  /**
94
87
  * @fileoverview added by tsickle
@@ -102,7 +95,11 @@ class DispatchOutsideZoneNgxsExecutionStrategy {
102
95
  constructor(_ngZone, _platformId) {
103
96
  this._ngZone = _ngZone;
104
97
  this._platformId = _platformId;
105
- this.verifyZoneIsNotNooped(this._ngZone);
98
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
99
+ // creating a breaking change for projects that still use the View Engine.
100
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
101
+ verifyZoneIsNotNooped(_ngZone);
102
+ }
106
103
  }
107
104
  /**
108
105
  * @template T
@@ -147,29 +144,16 @@ class DispatchOutsideZoneNgxsExecutionStrategy {
147
144
  }
148
145
  return func();
149
146
  }
150
- /**
151
- * @private
152
- * @param {?} ngZone
153
- * @return {?}
154
- */
155
- verifyZoneIsNotNooped(ngZone) {
156
- // `NoopNgZone` is not exposed publicly as it doesn't expect
157
- // to be used outside of the core Angular code, thus we just have
158
- // to check if the zone doesn't extend or instanceof `NgZone`
159
- if (ngZone instanceof NgZone) {
160
- return;
161
- }
162
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.ZONE_WARNING]());
163
- }
164
147
  }
165
148
  DispatchOutsideZoneNgxsExecutionStrategy.decorators = [
166
- { type: Injectable }
149
+ { type: Injectable, args: [{ providedIn: 'root' },] }
167
150
  ];
168
151
  /** @nocollapse */
169
152
  DispatchOutsideZoneNgxsExecutionStrategy.ctorParameters = () => [
170
153
  { type: NgZone },
171
154
  { type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
172
155
  ];
156
+ /** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ngInjectableDef = defineInjectable({ factory: function DispatchOutsideZoneNgxsExecutionStrategy_Factory() { return new DispatchOutsideZoneNgxsExecutionStrategy(inject(NgZone), inject(PLATFORM_ID)); }, token: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: "root" });
173
157
  if (false) {
174
158
  /**
175
159
  * @type {?}
@@ -181,6 +165,21 @@ if (false) {
181
165
  * @private
182
166
  */
183
167
  DispatchOutsideZoneNgxsExecutionStrategy.prototype._platformId;
168
+ }
169
+ // Caretaker note: this should exist as a separate function and not a class method,
170
+ // since class methods are not tree-shakable.
171
+ /**
172
+ * @param {?} ngZone
173
+ * @return {?}
174
+ */
175
+ function verifyZoneIsNotNooped(ngZone) {
176
+ // `NoopNgZone` is not exposed publicly as it doesn't expect
177
+ // to be used outside of the core Angular code, thus we just have
178
+ // to check if the zone doesn't extend or instanceof `NgZone`.
179
+ if (ngZone instanceof NgZone) {
180
+ return;
181
+ }
182
+ console.warn(getZoneWarningMessage());
184
183
  }
185
184
 
186
185
  /**
@@ -194,10 +193,6 @@ const FEATURE_STATE_TOKEN = new InjectionToken('FEATURE_STATE_TOKEN');
194
193
  /** @type {?} */
195
194
  const NGXS_PLUGINS = new InjectionToken('NGXS_PLUGINS');
196
195
  /** @type {?} */
197
- const NG_TEST_MODE = new InjectionToken('NG_TEST_MODE');
198
- /** @type {?} */
199
- const NG_DEV_MODE = new InjectionToken('NG_DEV_MODE');
200
- /** @type {?} */
201
196
  const META_KEY = 'NGXS_META';
202
197
  /** @type {?} */
203
198
  const META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
@@ -239,6 +234,9 @@ if (false) {
239
234
  * Run in development mode. This will add additional debugging features:
240
235
  * - Object.freeze on the state and actions to guarantee immutability
241
236
  * (default: false)
237
+ *
238
+ * @deprecated This property is no longer necessary when the Ivy compiler is used.
239
+ * We'll determine the development mode through the `ngDevMode`. It's still essential with View Engine.
242
240
  * @type {?}
243
241
  */
244
242
  NgxsConfig.prototype.developmentMode;
@@ -406,11 +404,59 @@ if (false) {
406
404
  * @fileoverview added by tsickle
407
405
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
408
406
  */
407
+ class NoopNgxsExecutionStrategy {
408
+ /**
409
+ * @template T
410
+ * @param {?} func
411
+ * @return {?}
412
+ */
413
+ enter(func) {
414
+ return func();
415
+ }
416
+ /**
417
+ * @template T
418
+ * @param {?} func
419
+ * @return {?}
420
+ */
421
+ leave(func) {
422
+ return func();
423
+ }
424
+ }
425
+ NoopNgxsExecutionStrategy.decorators = [
426
+ { type: Injectable, args: [{ providedIn: 'root' },] }
427
+ ];
428
+ /** @nocollapse */ NoopNgxsExecutionStrategy.ngInjectableDef = defineInjectable({ factory: function NoopNgxsExecutionStrategy_Factory() { return new NoopNgxsExecutionStrategy(); }, token: NoopNgxsExecutionStrategy, providedIn: "root" });
429
+
430
+ /**
431
+ * @fileoverview added by tsickle
432
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
433
+ */
434
+ /**
435
+ * The strategy that might be provided by users through `options.executionStrategy`.
436
+ * @type {?}
437
+ */
438
+ const USER_PROVIDED_NGXS_EXECUTION_STRATEGY = new InjectionToken('USER_PROVIDED_NGXS_EXECUTION_STRATEGY');
409
439
  /*
410
440
  * Internal execution strategy injection token
411
441
  */
412
442
  /** @type {?} */
413
- const NGXS_EXECUTION_STRATEGY = new InjectionToken('NGXS_EXECUTION_STRATEGY');
443
+ const NGXS_EXECUTION_STRATEGY = new InjectionToken('NGXS_EXECUTION_STRATEGY', {
444
+ providedIn: 'root',
445
+ factory: (/**
446
+ * @return {?}
447
+ */
448
+ () => {
449
+ /** @type {?} */
450
+ const injector = inject(INJECTOR);
451
+ /** @type {?} */
452
+ const executionStrategy = injector.get(USER_PROVIDED_NGXS_EXECUTION_STRATEGY);
453
+ return executionStrategy
454
+ ? injector.get(executionStrategy)
455
+ : injector.get(typeof ɵglobal.Zone !== 'undefined'
456
+ ? DispatchOutsideZoneNgxsExecutionStrategy
457
+ : NoopNgxsExecutionStrategy);
458
+ })
459
+ });
414
460
  /**
415
461
  * @record
416
462
  */
@@ -884,10 +930,12 @@ function buildGraph(stateClasses) {
884
930
  * @return {?}
885
931
  */
886
932
  g => g === stateClass));
887
- if (!meta) {
933
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
934
+ // creating a breaking change for projects that still use the View Engine.
935
+ if ((typeof ngDevMode === 'undefined' || ngDevMode) && !meta) {
888
936
  throw new Error(`Child state not found: ${stateClass}. \r\nYou may have forgotten to add states to module`);
889
937
  }
890
- return (/** @type {?} */ ((/** @type {?} */ (meta[META_KEY])).name));
938
+ return (/** @type {?} */ ((/** @type {?} */ ((/** @type {?} */ (meta))[META_KEY])).name));
891
939
  });
892
940
  return stateClasses.reduce((/**
893
941
  * @param {?} result
@@ -1017,7 +1065,9 @@ function topologicalSort(graph) {
1017
1065
  * @return {?}
1018
1066
  */
1019
1067
  (dep) => {
1020
- if (ancestors.indexOf(dep) >= 0) {
1068
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
1069
+ // creating a breaking change for projects that still use the View Engine.
1070
+ if ((typeof ngDevMode === 'undefined' || ngDevMode) && ancestors.indexOf(dep) >= 0) {
1021
1071
  throw new Error(`Circular dependency '${dep}' is required by '${name}': ${ancestors.join(' -> ')}`);
1022
1072
  }
1023
1073
  if (visited[dep]) {
@@ -1540,6 +1590,15 @@ class StateStream extends BehaviorSubject {
1540
1590
  constructor() {
1541
1591
  super({});
1542
1592
  }
1593
+ /**
1594
+ * @return {?}
1595
+ */
1596
+ ngOnDestroy() {
1597
+ // The `StateStream` should never emit values once the root view is removed, e.g. when the `NgModuleRef.destroy()` is called.
1598
+ // This will eliminate memory leaks in server-side rendered apps where the `StateStream` is created per each HTTP request, users
1599
+ // might forget to unsubscribe from `store.select` or `store.subscribe`, thus this will lead to huge memory leaks in SSR apps.
1600
+ this.complete();
1601
+ }
1543
1602
  }
1544
1603
  StateStream.decorators = [
1545
1604
  { type: Injectable }
@@ -1857,98 +1916,6 @@ const deepFreeze = (/**
1857
1916
  return o;
1858
1917
  });
1859
1918
 
1860
- /**
1861
- * @fileoverview added by tsickle
1862
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1863
- */
1864
- class HostEnvironment {
1865
- /**
1866
- * @param {?} isDevMode
1867
- * @param {?} isTestMode
1868
- */
1869
- constructor(isDevMode, isTestMode) {
1870
- this.isDevMode = isDevMode;
1871
- this.isTestMode = isTestMode;
1872
- }
1873
- }
1874
- HostEnvironment.decorators = [
1875
- { type: Injectable }
1876
- ];
1877
- /** @nocollapse */
1878
- HostEnvironment.ctorParameters = () => [
1879
- { type: undefined, decorators: [{ type: Inject, args: [NG_DEV_MODE,] }] },
1880
- { type: undefined, decorators: [{ type: Inject, args: [NG_TEST_MODE,] }] }
1881
- ];
1882
- if (false) {
1883
- /** @type {?} */
1884
- HostEnvironment.prototype.isDevMode;
1885
- /** @type {?} */
1886
- HostEnvironment.prototype.isTestMode;
1887
- }
1888
-
1889
- /**
1890
- * @fileoverview added by tsickle
1891
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1892
- */
1893
- class ConfigValidator {
1894
- /**
1895
- * @param {?} _host
1896
- * @param {?} _config
1897
- */
1898
- constructor(_host, _config) {
1899
- this._host = _host;
1900
- this._config = _config;
1901
- }
1902
- /**
1903
- * @private
1904
- * @return {?}
1905
- */
1906
- get isIncorrectProduction() {
1907
- return !this._host.isDevMode() && this._config.developmentMode;
1908
- }
1909
- /**
1910
- * @private
1911
- * @return {?}
1912
- */
1913
- get isIncorrectDevelopment() {
1914
- return this._host.isDevMode() && !this._config.developmentMode;
1915
- }
1916
- /**
1917
- * @return {?}
1918
- */
1919
- verifyDevMode() {
1920
- if (this._host.isTestMode()) {
1921
- return;
1922
- }
1923
- if (this.isIncorrectProduction) {
1924
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.INCORRECT_PRODUCTION]());
1925
- }
1926
- else if (this.isIncorrectDevelopment) {
1927
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.INCORRECT_DEVELOPMENT]());
1928
- }
1929
- }
1930
- }
1931
- ConfigValidator.decorators = [
1932
- { type: Injectable }
1933
- ];
1934
- /** @nocollapse */
1935
- ConfigValidator.ctorParameters = () => [
1936
- { type: HostEnvironment },
1937
- { type: NgxsConfig }
1938
- ];
1939
- if (false) {
1940
- /**
1941
- * @type {?}
1942
- * @private
1943
- */
1944
- ConfigValidator.prototype._host;
1945
- /**
1946
- * @type {?}
1947
- * @private
1948
- */
1949
- ConfigValidator.prototype._config;
1950
- }
1951
-
1952
1919
  /**
1953
1920
  * @fileoverview added by tsickle
1954
1921
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -1962,13 +1929,11 @@ class InternalStateOperations {
1962
1929
  * @param {?} _stateStream
1963
1930
  * @param {?} _dispatcher
1964
1931
  * @param {?} _config
1965
- * @param {?} configValidator
1966
1932
  */
1967
- constructor(_stateStream, _dispatcher, _config, configValidator) {
1933
+ constructor(_stateStream, _dispatcher, _config) {
1968
1934
  this._stateStream = _stateStream;
1969
1935
  this._dispatcher = _dispatcher;
1970
1936
  this._config = _config;
1971
- configValidator.verifyDevMode();
1972
1937
  }
1973
1938
  /**
1974
1939
  * Returns the root state operators.
@@ -1992,39 +1957,22 @@ class InternalStateOperations {
1992
1957
  */
1993
1958
  (actionOrActions) => this._dispatcher.dispatch(actionOrActions))
1994
1959
  };
1995
- if (this._config.developmentMode) {
1996
- return this.ensureStateAndActionsAreImmutable(rootStateOperations);
1960
+ // We have to have that duplication since this will allow us to tree-shake `ensureStateAndActionsAreImmutable`
1961
+ // and `deepFreeze` in Ivy production build.
1962
+ // The below `if` condition checks 2 things:
1963
+ // 1) if we're in View Engine (`ngDevMode` is `undefined`)
1964
+ // 2) if we're running tests, we should fallback to `config.developmentMode` to be backwards-compatible
1965
+ if (typeof ngDevMode === 'undefined' || (ngDevMode && isAngularInTestMode())) {
1966
+ return this._config.developmentMode
1967
+ ? ensureStateAndActionsAreImmutable(rootStateOperations)
1968
+ : rootStateOperations;
1969
+ }
1970
+ else {
1971
+ // If we're in Ivy and not running tests, then tree-shake `ensureStateAndActionsAreImmutable` and `deepFreeze`.
1972
+ return ngDevMode
1973
+ ? ensureStateAndActionsAreImmutable(rootStateOperations)
1974
+ : rootStateOperations;
1997
1975
  }
1998
- return rootStateOperations;
1999
- }
2000
- /**
2001
- * @private
2002
- * @param {?} root
2003
- * @return {?}
2004
- */
2005
- ensureStateAndActionsAreImmutable(root) {
2006
- return {
2007
- getState: (/**
2008
- * @return {?}
2009
- */
2010
- () => root.getState()),
2011
- setState: (/**
2012
- * @param {?} value
2013
- * @return {?}
2014
- */
2015
- value => {
2016
- /** @type {?} */
2017
- const frozenValue = deepFreeze(value);
2018
- return root.setState(frozenValue);
2019
- }),
2020
- dispatch: (/**
2021
- * @param {?} actions
2022
- * @return {?}
2023
- */
2024
- actions => {
2025
- return root.dispatch(actions);
2026
- })
2027
- };
2028
1976
  }
2029
1977
  /**
2030
1978
  * @param {?} results
@@ -2047,8 +1995,7 @@ InternalStateOperations.decorators = [
2047
1995
  InternalStateOperations.ctorParameters = () => [
2048
1996
  { type: StateStream },
2049
1997
  { type: InternalDispatcher },
2050
- { type: NgxsConfig },
2051
- { type: ConfigValidator }
1998
+ { type: NgxsConfig }
2052
1999
  ];
2053
2000
  if (false) {
2054
2001
  /**
@@ -2066,6 +2013,34 @@ if (false) {
2066
2013
  * @private
2067
2014
  */
2068
2015
  InternalStateOperations.prototype._config;
2016
+ }
2017
+ /**
2018
+ * @param {?} root
2019
+ * @return {?}
2020
+ */
2021
+ function ensureStateAndActionsAreImmutable(root) {
2022
+ return {
2023
+ getState: (/**
2024
+ * @return {?}
2025
+ */
2026
+ () => root.getState()),
2027
+ setState: (/**
2028
+ * @param {?} value
2029
+ * @return {?}
2030
+ */
2031
+ value => {
2032
+ /** @type {?} */
2033
+ const frozenValue = deepFreeze(value);
2034
+ return root.setState(frozenValue);
2035
+ }),
2036
+ dispatch: (/**
2037
+ * @param {?} actions
2038
+ * @return {?}
2039
+ */
2040
+ actions => {
2041
+ return root.dispatch(actions);
2042
+ })
2043
+ };
2069
2044
  }
2070
2045
 
2071
2046
  /**
@@ -2084,10 +2059,10 @@ function simplePatch(val) {
2084
2059
  */
2085
2060
  (existingState) => {
2086
2061
  if (Array.isArray(val)) {
2087
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.PATCHING_ARRAY]());
2062
+ throwPatchingArrayError();
2088
2063
  }
2089
2064
  else if (typeof val !== 'object') {
2090
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.PATCHING_PRIMITIVE]());
2065
+ throwPatchingPrimitiveError();
2091
2066
  }
2092
2067
  /** @type {?} */
2093
2068
  const newState = Object.assign({}, ((/** @type {?} */ (existingState))));
@@ -2245,54 +2220,49 @@ class StoreValidators {
2245
2220
  * @param {?} name
2246
2221
  * @return {?}
2247
2222
  */
2248
- static stateNameErrorMessage(name) {
2249
- return CONFIG_MESSAGES[VALIDATION_CODE.STATE_NAME](name);
2250
- }
2251
- /**
2252
- * @param {?} name
2253
- * @return {?}
2254
- */
2255
- static checkCorrectStateName(name) {
2223
+ static checkThatStateIsNamedCorrectly(name) {
2256
2224
  if (!name) {
2257
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.STATE_NAME_PROPERTY]());
2225
+ throwStateNamePropertyError();
2258
2226
  }
2259
- if (!this.stateNameRegex.test(name)) {
2260
- throw new Error(this.stateNameErrorMessage(name));
2227
+ else if (!this.stateNameRegex.test(name)) {
2228
+ throwStateNameError(name);
2261
2229
  }
2262
2230
  }
2263
2231
  /**
2232
+ * @param {?} stateName
2264
2233
  * @param {?} state
2265
2234
  * @param {?} statesByName
2266
2235
  * @return {?}
2267
2236
  */
2268
- static checkStateNameIsUnique(state, statesByName) {
2269
- /** @type {?} */
2270
- const meta = this.getValidStateMeta(state);
2271
- /** @type {?} */
2272
- const stateName = (/** @type {?} */ ((/** @type {?} */ (meta)).name));
2237
+ static checkThatStateNameIsUnique(stateName, state, statesByName) {
2273
2238
  /** @type {?} */
2274
2239
  const existingState = statesByName[stateName];
2275
2240
  if (existingState && existingState !== state) {
2276
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.STATE_UNIQUE](stateName, state.name, existingState.name));
2241
+ throwStateUniqueError(stateName, state.name, existingState.name);
2277
2242
  }
2278
- return stateName;
2279
2243
  }
2280
2244
  /**
2281
- * @param {?} state
2245
+ * @param {?} stateClasses
2282
2246
  * @return {?}
2283
2247
  */
2284
- static getValidStateMeta(state) {
2285
- /** @type {?} */
2286
- const meta = getStoreMetadata(state);
2287
- if (!meta) {
2288
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.STATE_DECORATOR]());
2289
- }
2290
- return meta;
2248
+ static checkThatStateClassesHaveBeenDecorated(stateClasses) {
2249
+ stateClasses.forEach((/**
2250
+ * @param {?} stateClass
2251
+ * @return {?}
2252
+ */
2253
+ (stateClass) => {
2254
+ if (!getStoreMetadata(stateClass)) {
2255
+ throwStateDecoratorError(stateClass.name);
2256
+ }
2257
+ }));
2291
2258
  }
2292
2259
  }
2293
2260
  StoreValidators.stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
2294
2261
  if (false) {
2295
- /** @type {?} */
2262
+ /**
2263
+ * @type {?}
2264
+ * @private
2265
+ */
2296
2266
  StoreValidators.stateNameRegex;
2297
2267
  }
2298
2268
 
@@ -2421,14 +2391,6 @@ class StateFactory {
2421
2391
  }
2422
2392
  return value;
2423
2393
  }
2424
- /**
2425
- * @private
2426
- * @param {?} stateClasses
2427
- * @return {?}
2428
- */
2429
- static checkStatesAreValid(stateClasses) {
2430
- stateClasses.forEach(StoreValidators.getValidStateMeta);
2431
- }
2432
2394
  /**
2433
2395
  * @return {?}
2434
2396
  */
@@ -2445,7 +2407,11 @@ class StateFactory {
2445
2407
  * @return {?}
2446
2408
  */
2447
2409
  add(stateClasses) {
2448
- StateFactory.checkStatesAreValid(stateClasses);
2410
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
2411
+ // creating a breaking change for projects that still use the View Engine.
2412
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2413
+ StoreValidators.checkThatStateClassesHaveBeenDecorated(stateClasses);
2414
+ }
2449
2415
  const { newStates } = this.addToStatesMap(stateClasses);
2450
2416
  if (!newStates.length)
2451
2417
  return [];
@@ -2512,23 +2478,30 @@ class StateFactory {
2512
2478
  connectActionHandlers() {
2513
2479
  if (this._actionsSubscription !== null)
2514
2480
  return;
2481
+ /** @type {?} */
2482
+ const dispatched$ = new Subject();
2515
2483
  this._actionsSubscription = this._actions
2516
2484
  .pipe(filter((/**
2517
2485
  * @param {?} ctx
2518
2486
  * @return {?}
2519
2487
  */
2520
2488
  (ctx) => ctx.status === "DISPATCHED" /* Dispatched */)), mergeMap((/**
2521
- * @param {?} __0
2522
- * @return {?}
2523
- */
2524
- ({ action }) => this.invokeActions(this._actions, (/** @type {?} */ (action))).pipe(map((/**
2525
- * @return {?}
2526
- */
2527
- () => (/** @type {?} */ ({ action, status: "SUCCESSFUL" /* Successful */ })))), defaultIfEmpty((/** @type {?} */ ({ action, status: "CANCELED" /* Canceled */ }))), catchError((/**
2528
- * @param {?} error
2489
+ * @param {?} ctx
2529
2490
  * @return {?}
2530
2491
  */
2531
- error => of((/** @type {?} */ ({ action, status: "ERRORED" /* Errored */, error })))))))))
2492
+ ctx => {
2493
+ dispatched$.next(ctx);
2494
+ /** @type {?} */
2495
+ const action = ctx.action;
2496
+ return this.invokeActions(dispatched$, (/** @type {?} */ (action))).pipe(map((/**
2497
+ * @return {?}
2498
+ */
2499
+ () => (/** @type {?} */ ({ action, status: "SUCCESSFUL" /* Successful */ })))), defaultIfEmpty((/** @type {?} */ ({ action, status: "CANCELED" /* Canceled */ }))), catchError((/**
2500
+ * @param {?} error
2501
+ * @return {?}
2502
+ */
2503
+ error => of((/** @type {?} */ ({ action, status: "ERRORED" /* Errored */, error }))))));
2504
+ })))
2532
2505
  .subscribe((/**
2533
2506
  * @param {?} ctx
2534
2507
  * @return {?}
@@ -2537,11 +2510,11 @@ class StateFactory {
2537
2510
  }
2538
2511
  /**
2539
2512
  * Invoke actions on the states.
2540
- * @param {?} actions$
2513
+ * @param {?} dispatched$
2541
2514
  * @param {?} action
2542
2515
  * @return {?}
2543
2516
  */
2544
- invokeActions(actions$, action) {
2517
+ invokeActions(dispatched$, action) {
2545
2518
  /** @type {?} */
2546
2519
  const type = (/** @type {?} */ (getActionTypeFromInstance(action)));
2547
2520
  /** @type {?} */
@@ -2568,10 +2541,22 @@ class StateFactory {
2568
2541
  // `handler(ctx) { return EMPTY; }`
2569
2542
  // then the action will be canceled.
2570
2543
  // See https://github.com/ngxs/store/issues/1568
2571
- result = result.pipe(defaultIfEmpty({}));
2544
+ result = result.pipe(mergeMap((/**
2545
+ * @param {?} value
2546
+ * @return {?}
2547
+ */
2548
+ (value) => {
2549
+ if (value instanceof Promise) {
2550
+ return from(value);
2551
+ }
2552
+ if (value instanceof Observable) {
2553
+ return value;
2554
+ }
2555
+ return of(value);
2556
+ })), defaultIfEmpty({}));
2572
2557
  if (actionMeta.options.cancelUncompleted) {
2573
2558
  // todo: ofActionDispatched should be used with action class
2574
- result = result.pipe(takeUntil(actions$.pipe(ofActionDispatched((/** @type {?} */ (action))))));
2559
+ result = result.pipe(takeUntil(dispatched$.pipe(ofActionDispatched((/** @type {?} */ (action))))));
2575
2560
  }
2576
2561
  }
2577
2562
  else {
@@ -2602,7 +2587,12 @@ class StateFactory {
2602
2587
  const statesMap = this.statesByName;
2603
2588
  for (const stateClass of stateClasses) {
2604
2589
  /** @type {?} */
2605
- const stateName = StoreValidators.checkStateNameIsUnique(stateClass, statesMap);
2590
+ const stateName = (/** @type {?} */ (getStoreMetadata(stateClass).name));
2591
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
2592
+ // creating a breaking change for projects that still use the View Engine.
2593
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2594
+ StoreValidators.checkThatStateNameIsUnique(stateName, stateClass, statesMap);
2595
+ }
2606
2596
  /** @type {?} */
2607
2597
  const unmountedState = !statesMap[stateName];
2608
2598
  if (unmountedState) {
@@ -3074,6 +3064,12 @@ class Store {
3074
3064
  this._config = _config;
3075
3065
  this._internalExecutionStrategy = _internalExecutionStrategy;
3076
3066
  this._stateFactory = _stateFactory;
3067
+ /**
3068
+ * This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
3069
+ * because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
3070
+ * All selects would use this stream, and it would call leave only once for any state change across all active selectors.
3071
+ */
3072
+ this._selectableStateStream = this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy), publishReplay(1), refCount());
3077
3073
  this.initStateStream(initialStateValue);
3078
3074
  }
3079
3075
  /**
@@ -3091,7 +3087,7 @@ class Store {
3091
3087
  select(selector) {
3092
3088
  /** @type {?} */
3093
3089
  const selectorFn = this.getStoreBoundSelectorFn(selector);
3094
- return this._stateStream.pipe(map(selectorFn), catchError((/**
3090
+ return this._selectableStateStream.pipe(map(selectorFn), catchError((/**
3095
3091
  * @param {?} err
3096
3092
  * @return {?}
3097
3093
  */
@@ -3127,7 +3123,9 @@ class Store {
3127
3123
  * @return {?}
3128
3124
  */
3129
3125
  subscribe(fn) {
3130
- return this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy)).subscribe(fn);
3126
+ return this._selectableStateStream
3127
+ .pipe(leaveNgxs(this._internalExecutionStrategy))
3128
+ .subscribe(fn);
3131
3129
  }
3132
3130
  /**
3133
3131
  * Return the raw value of the state.
@@ -3190,6 +3188,14 @@ Store.ctorParameters = () => [
3190
3188
  { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [INITIAL_STATE_TOKEN,] }] }
3191
3189
  ];
3192
3190
  if (false) {
3191
+ /**
3192
+ * This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
3193
+ * because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
3194
+ * All selects would use this stream, and it would call leave only once for any state change across all active selectors.
3195
+ * @type {?}
3196
+ * @private
3197
+ */
3198
+ Store.prototype._selectableStateStream;
3193
3199
  /**
3194
3200
  * @type {?}
3195
3201
  * @private
@@ -3222,9 +3228,8 @@ if (false) {
3222
3228
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3223
3229
  */
3224
3230
  /**
3225
- * Allows the select decorator to get access to the DI store.
3226
- * \@internal only use in \@Select decorator
3227
- * @ignore
3231
+ * Allows the select decorator to get access to the DI store, this is used internally
3232
+ * in `\@Select` decorator.
3228
3233
  */
3229
3234
  class SelectFactory {
3230
3235
  /**
@@ -3246,13 +3251,14 @@ class SelectFactory {
3246
3251
  SelectFactory.store = null;
3247
3252
  SelectFactory.config = null;
3248
3253
  SelectFactory.decorators = [
3249
- { type: Injectable }
3254
+ { type: Injectable, args: [{ providedIn: 'root' },] }
3250
3255
  ];
3251
3256
  /** @nocollapse */
3252
3257
  SelectFactory.ctorParameters = () => [
3253
3258
  { type: Store },
3254
3259
  { type: NgxsConfig }
3255
3260
  ];
3261
+ /** @nocollapse */ SelectFactory.ngInjectableDef = defineInjectable({ factory: function SelectFactory_Factory() { return new SelectFactory(inject(Store), inject(NgxsConfig)); }, token: SelectFactory, providedIn: "root" });
3256
3262
  if (false) {
3257
3263
  /** @type {?} */
3258
3264
  SelectFactory.store;
@@ -3299,44 +3305,6 @@ if (false) {
3299
3305
  UpdateState.prototype.addedStates;
3300
3306
  }
3301
3307
 
3302
- /**
3303
- * @fileoverview added by tsickle
3304
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3305
- */
3306
- /** @type {?} */
3307
- const ivyEnabledInDevMode$ = new ReplaySubject(1);
3308
- /**
3309
- * Ivy exposes helper functions to the global `window.ng` object.
3310
- * Those functions are `getComponent, getContext,
3311
- * getListeners, getViewComponent, getHostElement, getInjector,
3312
- * getRootComponents, getDirectives, getDebugNode`
3313
- * Previously, old view engine exposed `window.ng.coreTokens` and
3314
- * `window.ng.probe` if an application was in development/production.
3315
- * Ivy doesn't expose these functions in production. Developers will be able
3316
- * to see warnings in both JIT/AOT modes, but only if an application
3317
- * is in development.
3318
- * @return {?}
3319
- */
3320
- function setIvyEnabledInDevMode() {
3321
- try {
3322
- // `try-catch` will also handle server-side rendering, as
3323
- // `window is not defined` will not be thrown.
3324
- /** @type {?} */
3325
- const ng = ((/** @type {?} */ (window))).ng;
3326
- /** @type {?} */
3327
- const _viewEngineEnabled = !!ng.probe && !!ng.coreTokens;
3328
- /** @type {?} */
3329
- const _ivyEnabledInDevMode = !_viewEngineEnabled && isDevMode();
3330
- ivyEnabledInDevMode$.next(_ivyEnabledInDevMode);
3331
- }
3332
- catch (_a) {
3333
- ivyEnabledInDevMode$.next(false);
3334
- }
3335
- finally {
3336
- ivyEnabledInDevMode$.complete();
3337
- }
3338
- }
3339
-
3340
3308
  /**
3341
3309
  * @fileoverview added by tsickle
3342
3310
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -3350,13 +3318,14 @@ class NgxsRootModule {
3350
3318
  * @param {?} factory
3351
3319
  * @param {?} internalStateOperations
3352
3320
  * @param {?} _store
3353
- * @param {?} _select
3321
+ * @param {?} injector
3354
3322
  * @param {?=} states
3355
3323
  * @param {?=} lifecycleStateManager
3356
3324
  */
3357
- constructor(factory, internalStateOperations, _store, _select, states = [], lifecycleStateManager) {
3358
- // Validate states on having the `@Injectable()` decorator in Ivy
3359
- setIvyEnabledInDevMode();
3325
+ constructor(factory, internalStateOperations, _store, injector, states = [], lifecycleStateManager) {
3326
+ // If the user is running View Engine then we create the `SelectFactory` instance,
3327
+ // otherwise it'll be tree-shaken away in Ivy.
3328
+ !ɵivyEnabled && injector.get(SelectFactory);
3360
3329
  // Add stores to the state graph and return their defaults
3361
3330
  /** @type {?} */
3362
3331
  const results = factory.addAndReturnDefaults(states);
@@ -3375,7 +3344,7 @@ NgxsRootModule.ctorParameters = () => [
3375
3344
  { type: StateFactory },
3376
3345
  { type: InternalStateOperations },
3377
3346
  { type: Store },
3378
- { type: SelectFactory },
3347
+ { type: Injector },
3379
3348
  { type: Array, decorators: [{ type: Optional }, { type: Inject, args: [ROOT_STATE_TOKEN,] }] },
3380
3349
  { type: LifecycleStateManager }
3381
3350
  ];
@@ -3459,8 +3428,6 @@ class NgxsModule {
3459
3428
  Actions,
3460
3429
  InternalActions,
3461
3430
  NgxsBootstrapper,
3462
- ConfigValidator,
3463
- HostEnvironment,
3464
3431
  LifecycleStateManager,
3465
3432
  InternalDispatcher,
3466
3433
  InternalDispatchedActionResults,
@@ -3468,7 +3435,6 @@ class NgxsModule {
3468
3435
  InternalNgxsExecutionStrategy,
3469
3436
  Store,
3470
3437
  StateStream,
3471
- SelectFactory,
3472
3438
  PluginManager,
3473
3439
  ...states,
3474
3440
  ...NgxsModule.ngxsTokenProviders(states, options)
@@ -3504,16 +3470,8 @@ class NgxsModule {
3504
3470
  static ngxsTokenProviders(states, options) {
3505
3471
  return [
3506
3472
  {
3507
- provide: NG_TEST_MODE,
3508
- useValue: isAngularInTestMode
3509
- },
3510
- {
3511
- provide: NG_DEV_MODE,
3512
- useValue: isDevMode
3513
- },
3514
- {
3515
- provide: NGXS_EXECUTION_STRATEGY,
3516
- useClass: options.executionStrategy || DispatchOutsideZoneNgxsExecutionStrategy
3473
+ provide: USER_PROVIDED_NGXS_EXECUTION_STRATEGY,
3474
+ useValue: options.executionStrategy
3517
3475
  },
3518
3476
  {
3519
3477
  provide: ROOT_STATE_TOKEN,
@@ -3604,10 +3562,14 @@ function Action(actions, options) {
3604
3562
  * @return {?}
3605
3563
  */
3606
3564
  (target, name) => {
3607
- /** @type {?} */
3608
- const isStaticMethod = target.hasOwnProperty('prototype');
3609
- if (isStaticMethod) {
3610
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.ACTION_DECORATOR]());
3565
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
3566
+ // creating a breaking change for projects that still use the View Engine.
3567
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
3568
+ /** @type {?} */
3569
+ const isStaticMethod = target.hasOwnProperty('prototype');
3570
+ if (isStaticMethod) {
3571
+ throwActionDecoratorError();
3572
+ }
3611
3573
  }
3612
3574
  /** @type {?} */
3613
3575
  const meta = ensureStoreMetadata(target.constructor);
@@ -3645,20 +3607,14 @@ function ensureStateClassIsInjectable(target) {
3645
3607
  // AOT mode because this property is added before runtime. If an application is running in
3646
3608
  // JIT mode then this property can be added by the `@Injectable()` decorator. The `@Injectable()`
3647
3609
  // decorator has to go after the `@State()` decorator, thus we prevent users from unwanted DI errors.
3648
- ivyEnabledInDevMode$.subscribe((/**
3649
- * @param {?} _ivyEnabledInDevMode
3650
- * @return {?}
3651
- */
3652
- _ivyEnabledInDevMode => {
3653
- if (_ivyEnabledInDevMode) {
3654
- /** @type {?} */
3655
- /** @nocollapse */ const ngInjectableDef = target.ɵprov;
3656
- if (!ngInjectableDef) {
3657
- // Don't warn if Ivy is disabled or `ɵprov` exists on the class
3658
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.UNDECORATED_STATE_IN_IVY](target.name));
3659
- }
3610
+ if (ɵivyEnabled) {
3611
+ /** @type {?} */
3612
+ /** @nocollapse */ const ngInjectableDef = target.ɵprov;
3613
+ if (!ngInjectableDef) {
3614
+ // Don't warn if Ivy is disabled or `ɵprov` exists on the class
3615
+ console.warn(getUndecoratedStateInIvyWarningMessage(target.name));
3660
3616
  }
3661
- }));
3617
+ }
3662
3618
  }
3663
3619
 
3664
3620
  /**
@@ -3703,7 +3659,11 @@ function State(options) {
3703
3659
  const { children, defaults, name } = optionsWithInheritance;
3704
3660
  /** @type {?} */
3705
3661
  const stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
3706
- StoreValidators.checkCorrectStateName(stateName);
3662
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
3663
+ // creating a breaking change for projects that still use the View Engine.
3664
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
3665
+ StoreValidators.checkThatStateIsNamedCorrectly(stateName);
3666
+ }
3707
3667
  if (inheritedStateClass.hasOwnProperty(META_KEY)) {
3708
3668
  /** @type {?} */
3709
3669
  const inheritedMeta = inheritedStateClass[META_KEY] || {};
@@ -3718,7 +3678,11 @@ function State(options) {
3718
3678
  * @return {?}
3719
3679
  */
3720
3680
  (target) => {
3721
- ensureStateClassIsInjectable(target);
3681
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
3682
+ // creating a breaking change for projects that still use the View Engine.
3683
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
3684
+ ensureStateClassIsInjectable(target);
3685
+ }
3722
3686
  /** @type {?} */
3723
3687
  const stateClass = target;
3724
3688
  /** @type {?} */
@@ -3741,30 +3705,37 @@ const DOLLAR_CHAR_CODE = 36;
3741
3705
  /**
3742
3706
  * @template T
3743
3707
  * @param {?} selector
3708
+ * @param {?} store
3744
3709
  * @return {?}
3745
3710
  */
3746
- function createSelectObservable(selector) {
3747
- if (!SelectFactory.store) {
3748
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.SELECT_FACTORY_NOT_CONNECTED]());
3749
- }
3750
- return SelectFactory.store.select(selector);
3711
+ function createSelectObservable(selector, store) {
3712
+ // We're doing this stuff to tree-shake the `SelectFactory` when the user
3713
+ // is running Ivy since NGXS will select the state from the provided `store` argument.
3714
+ return ɵivyEnabled
3715
+ ? createSelectObservableIvy(selector, store)
3716
+ : createSelectObservableViewEngine(selector);
3751
3717
  }
3752
3718
  /**
3719
+ * @param {?} config
3753
3720
  * @param {?} name
3754
3721
  * @param {?=} rawSelector
3755
3722
  * @param {?=} paths
3756
3723
  * @return {?}
3757
3724
  */
3758
- function createSelectorFn(name, rawSelector, paths = []) {
3759
- rawSelector = !rawSelector ? removeDollarAtTheEnd(name) : rawSelector;
3760
- if (typeof rawSelector === 'string') {
3725
+ function createSelectorFn(config, name, rawSelector, paths = []) {
3726
+ rawSelector = rawSelector || removeDollarAtTheEnd(name);
3727
+ if (typeof rawSelector !== 'string') {
3728
+ return rawSelector;
3729
+ }
3730
+ else {
3761
3731
  /** @type {?} */
3762
3732
  const propsArray = paths.length
3763
3733
  ? [rawSelector, ...paths]
3764
3734
  : rawSelector.split('.');
3765
- return propGetter(propsArray, (/** @type {?} */ (SelectFactory.config)));
3735
+ return ɵivyEnabled
3736
+ ? createSelectorFnIvy(propsArray, config)
3737
+ : createSelectorFnViewEngine(propsArray);
3766
3738
  }
3767
- return rawSelector;
3768
3739
  }
3769
3740
  /**
3770
3741
  * \@example If `foo$` => make it just `foo`
@@ -3777,6 +3748,42 @@ function removeDollarAtTheEnd(name) {
3777
3748
  /** @type {?} */
3778
3749
  const dollarAtTheEnd = name.charCodeAt(lastCharIndex) === DOLLAR_CHAR_CODE;
3779
3750
  return dollarAtTheEnd ? name.slice(0, lastCharIndex) : name;
3751
+ }
3752
+ /**
3753
+ * @template T
3754
+ * @param {?} selector
3755
+ * @param {?} store
3756
+ * @return {?}
3757
+ */
3758
+ function createSelectObservableIvy(selector, store) {
3759
+ return ngDevMode && !store ? throwSelectFactoryNotConnectedError() : (/** @type {?} */ (store)).select(selector);
3760
+ }
3761
+ /**
3762
+ * @template T
3763
+ * @param {?} selector
3764
+ * @return {?}
3765
+ */
3766
+ function createSelectObservableViewEngine(selector) {
3767
+ return SelectFactory.store
3768
+ ? SelectFactory.store.select(selector)
3769
+ : throwSelectFactoryNotConnectedError();
3770
+ }
3771
+ /**
3772
+ * @param {?} propsArray
3773
+ * @param {?} config
3774
+ * @return {?}
3775
+ */
3776
+ function createSelectorFnIvy(propsArray, config) {
3777
+ return ngDevMode && !config
3778
+ ? throwSelectFactoryNotConnectedError()
3779
+ : propGetter(propsArray, (/** @type {?} */ (config)));
3780
+ }
3781
+ /**
3782
+ * @param {?} propsArray
3783
+ * @return {?}
3784
+ */
3785
+ function createSelectorFnViewEngine(propsArray) {
3786
+ return propGetter(propsArray, (/** @type {?} */ (SelectFactory.config)));
3780
3787
  }
3781
3788
 
3782
3789
  /**
@@ -3802,7 +3809,12 @@ function Select(rawSelector, ...paths) {
3802
3809
  /** @type {?} */
3803
3810
  const selectorId = `__${name}__selector`;
3804
3811
  /** @type {?} */
3805
- const selector = createSelectorFn(name, rawSelector, paths);
3812
+ let selector = null;
3813
+ /** @type {?} */
3814
+ let injectorNotifier$ = null;
3815
+ if (ɵivyEnabled) {
3816
+ injectorNotifier$ = ensureInjectorNotifierIsCaptured(target);
3817
+ }
3806
3818
  Object.defineProperties(target, {
3807
3819
  [selectorId]: {
3808
3820
  writable: true,
@@ -3816,10 +3828,36 @@ function Select(rawSelector, ...paths) {
3816
3828
  * @return {?}
3817
3829
  */
3818
3830
  get() {
3819
- return this[selectorId] || (this[selectorId] = createSelectObservable(selector));
3831
+ if (this[selectorId]) {
3832
+ return this[selectorId];
3833
+ }
3834
+ // The `localInject` will be tree-shaken away in apps that
3835
+ // still use the View Engine.
3836
+ if (ɵivyEnabled) {
3837
+ this[selectorId] = (/** @type {?} */ (injectorNotifier$)).pipe(mergeMap((/**
3838
+ * @return {?}
3839
+ */
3840
+ () => {
3841
+ /** @type {?} */
3842
+ const store = localInject(this, Store);
3843
+ /** @type {?} */
3844
+ const config = localInject(this, NgxsConfig);
3845
+ selector = selector || createSelectorFn(config, name, rawSelector, paths);
3846
+ return createSelectObservable(selector, store);
3847
+ })));
3848
+ }
3849
+ else {
3850
+ selector = selector || createSelectorFn(null, name, rawSelector, paths);
3851
+ this[selectorId] = createSelectObservable(selector, null);
3852
+ }
3853
+ return this[selectorId];
3820
3854
  }
3821
3855
  }
3822
3856
  });
3857
+ // Keep this `if` guard here so the below stuff will be tree-shaken away in apps that still use the View Engine.
3858
+ if (ɵivyEnabled) {
3859
+ ensureLocalInjectorCaptured(target);
3860
+ }
3823
3861
  });
3824
3862
  }
3825
3863
 
@@ -3938,10 +3976,14 @@ function Selector(selectors) {
3938
3976
  * @return {?}
3939
3977
  */
3940
3978
  (target, key, descriptor) => {
3941
- /** @type {?} */
3942
- const isNotMethod = !(descriptor && descriptor.value !== null);
3943
- if (isNotMethod) {
3944
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.SELECTOR_DECORATOR]());
3979
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
3980
+ // creating a breaking change for projects that still use the View Engine.
3981
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
3982
+ /** @type {?} */
3983
+ const isNotMethod = !(descriptor && descriptor.value !== null);
3984
+ if (isNotMethod) {
3985
+ throwSelectorDecoratorError();
3986
+ }
3945
3987
  }
3946
3988
  /** @type {?} */
3947
3989
  const originalFn = descriptor.value;
@@ -3972,32 +4014,6 @@ function Selector(selectors) {
3972
4014
  });
3973
4015
  }
3974
4016
 
3975
- /**
3976
- * @fileoverview added by tsickle
3977
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3978
- */
3979
- class NoopNgxsExecutionStrategy {
3980
- /**
3981
- * @template T
3982
- * @param {?} func
3983
- * @return {?}
3984
- */
3985
- enter(func) {
3986
- return func();
3987
- }
3988
- /**
3989
- * @template T
3990
- * @param {?} func
3991
- * @return {?}
3992
- */
3993
- leave(func) {
3994
- return func();
3995
- }
3996
- }
3997
- NoopNgxsExecutionStrategy.decorators = [
3998
- { type: Injectable }
3999
- ];
4000
-
4001
4017
  /**
4002
4018
  * @fileoverview added by tsickle
4003
4019
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -4062,5 +4078,5 @@ if (false) {
4062
4078
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
4063
4079
  */
4064
4080
 
4065
- export { Action, Actions, InitState, NGXS_PLUGINS, NgxsModule, NgxsSimpleChange, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, StateStream, StateToken, Store, UpdateState, actionMatcher, createSelector, ensureSelectorMetadata$1 as ensureSelectorMetadata, ensureStoreMetadata$1 as ensureStoreMetadata, getActionTypeFromInstance, getSelectorMetadata$1 as getSelectorMetadata, getStoreMetadata$1 as getStoreMetadata, getValue, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, setValue, OrderedSubject as ɵa, InternalActions as ɵb, SelectFactory as ɵba, LifecycleStateManager as ɵbb, NgxsFeatureModule as ɵbc, DispatchOutsideZoneNgxsExecutionStrategy as ɵbd, ROOT_STATE_TOKEN as ɵc, FEATURE_STATE_TOKEN as ɵd, NG_TEST_MODE as ɵe, NG_DEV_MODE as ɵf, SELECTOR_META_KEY as ɵg, NgxsConfig as ɵh, mergeDeep as ɵi, NGXS_EXECUTION_STRATEGY as ɵj, NgxsRootModule as ɵk, StateFactory as ɵl, InternalDispatchedActionResults as ɵm, InternalDispatcher as ɵn, StateContextFactory as ɵo, InternalStateOperations as ɵp, PluginManager as ɵq, InternalNgxsExecutionStrategy as ɵr, ConfigValidator as ɵs, HostEnvironment as ɵt, ensureStoreMetadata as ɵw, getStoreMetadata as ɵx, ensureSelectorMetadata as ɵy, getSelectorMetadata as ɵz };
4081
+ export { Action, Actions, InitState, NGXS_PLUGINS, NgxsModule, NgxsSimpleChange, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, StateStream, StateToken, Store, UpdateState, actionMatcher, createSelector, ensureSelectorMetadata$1 as ensureSelectorMetadata, ensureStoreMetadata$1 as ensureStoreMetadata, getActionTypeFromInstance, getSelectorMetadata$1 as getSelectorMetadata, getStoreMetadata$1 as getStoreMetadata, getValue, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, setValue, OrderedSubject as ɵa, InternalActions as ɵb, ROOT_STATE_TOKEN as ɵc, FEATURE_STATE_TOKEN as ɵd, SELECTOR_META_KEY as ɵe, NgxsConfig as ɵf, mergeDeep as ɵg, USER_PROVIDED_NGXS_EXECUTION_STRATEGY as ɵh, NGXS_EXECUTION_STRATEGY as ɵi, NgxsRootModule as ɵj, StateFactory as ɵk, InternalDispatchedActionResults as ɵl, InternalDispatcher as ɵm, StateContextFactory as ɵn, InternalStateOperations as ɵo, PluginManager as ɵp, InternalNgxsExecutionStrategy as ɵq, ensureStoreMetadata as ɵs, getStoreMetadata as ɵt, ensureSelectorMetadata as ɵu, getSelectorMetadata as ɵv, LifecycleStateManager as ɵw, NgxsFeatureModule as ɵx };
4066
4082
  //# sourceMappingURL=ngxs-store.js.map