@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,112 +1,88 @@
1
1
  import { __assign, __spread, __extends, __values } from 'tslib';
2
- import { NgZone, Injectable, Inject, PLATFORM_ID, InjectionToken, Optional, SkipSelf, ErrorHandler, Injector, isDevMode, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
3
- import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, isAngularInTestMode, NGXS_STATE_CONTEXT_FACTORY, NGXS_STATE_FACTORY, InitialState } from '@ngxs/store/internals';
2
+ import { NgZone, Injectable, Inject, PLATFORM_ID, defineInjectable, inject, InjectionToken, INJECTOR, ɵglobal, Optional, SkipSelf, ErrorHandler, Injector, ɵivyEnabled, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
3
+ import { isAngularInTestMode, memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, NGXS_STATE_CONTEXT_FACTORY, NGXS_STATE_FACTORY, InitialState, ensureInjectorNotifierIsCaptured, localInject, ensureLocalInjectorCaptured } from '@ngxs/store/internals';
4
4
  import { isPlatformServer } from '@angular/common';
5
- import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, ReplaySubject } from 'rxjs';
6
- import { filter, map, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, tap, distinctUntilChanged } from 'rxjs/operators';
5
+ import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from } from 'rxjs';
6
+ import { filter, map, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, tap, publishReplay, refCount, distinctUntilChanged } from 'rxjs/operators';
7
7
 
8
- var _a;
9
8
  /**
10
9
  * @fileoverview added by tsickle
11
10
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
12
11
  */
13
- /** @enum {string} */
14
- var VALIDATION_CODE = {
15
- STATE_NAME: 'STATE_NAME',
16
- STATE_UNIQUE: 'STATE_UNIQUE',
17
- STATE_NAME_PROPERTY: 'STATE_NAME_PROPERTY',
18
- STATE_DECORATOR: 'STATE_DECORATOR',
19
- INCORRECT_PRODUCTION: 'INCORRECT_PRODUCTION',
20
- INCORRECT_DEVELOPMENT: 'INCORRECT_DEVELOPMENT',
21
- SELECT_FACTORY_NOT_CONNECTED: 'SELECT_FACTORY_NOT_CONNECTED',
22
- ACTION_DECORATOR: 'ACTION_DECORATOR',
23
- SELECTOR_DECORATOR: 'SELECTOR_DECORATOR',
24
- ZONE_WARNING: 'ZONE_WARNING',
25
- PATCHING_ARRAY: 'PATCHING_ARRAY',
26
- PATCHING_PRIMITIVE: 'PATCHING_PRIMITIVE',
27
- UNDECORATED_STATE_IN_IVY: 'UNDECORATED_STATE_IN_IVY',
28
- };
29
- /** @type {?} */
30
- var CONFIG_MESSAGES = (_a = {},
31
- _a[VALIDATION_CODE.STATE_NAME] = (/**
32
- * @param {?} name
33
- * @return {?}
34
- */
35
- function (name) {
36
- return name + " is not a valid state name. It needs to be a valid object property name.";
37
- }),
38
- _a[VALIDATION_CODE.STATE_NAME_PROPERTY] = (/**
39
- * @return {?}
40
- */
41
- function () { return "States must register a 'name' property"; }),
42
- _a[VALIDATION_CODE.STATE_UNIQUE] = (/**
43
- * @param {?} current
44
- * @param {?} newName
45
- * @param {?} oldName
46
- * @return {?}
47
- */
48
- function (current, newName, oldName) {
49
- return "State name '" + current + "' from " + newName + " already exists in " + oldName;
50
- }),
51
- _a[VALIDATION_CODE.STATE_DECORATOR] = (/**
52
- * @return {?}
53
- */
54
- function () { return 'States must be decorated with @State() decorator'; }),
55
- _a[VALIDATION_CODE.INCORRECT_PRODUCTION] = (/**
56
- * @return {?}
57
- */
58
- function () {
59
- return 'Angular is running in production mode but NGXS is still running in the development mode!\n' +
60
- 'Please set developmentMode to false on the NgxsModule options when in production mode.\n' +
61
- 'NgxsModule.forRoot(states, { developmentMode: !environment.production })';
62
- }),
63
- _a[VALIDATION_CODE.INCORRECT_DEVELOPMENT] = (/**
64
- * @return {?}
65
- */
66
- function () {
67
- return 'RECOMMENDATION: Set developmentMode to true on the NgxsModule when Angular is running in development mode.\n' +
68
- 'NgxsModule.forRoot(states, { developmentMode: !environment.production })';
69
- }),
70
- _a[VALIDATION_CODE.SELECT_FACTORY_NOT_CONNECTED] = (/**
71
- * @return {?}
72
- */
73
- function () {
74
- return 'You have forgotten to import the NGXS module!';
75
- }),
76
- _a[VALIDATION_CODE.ACTION_DECORATOR] = (/**
77
- * @return {?}
78
- */
79
- function () {
80
- return '@Action() decorator cannot be used with static methods';
81
- }),
82
- _a[VALIDATION_CODE.SELECTOR_DECORATOR] = (/**
83
- * @return {?}
84
- */
85
- function () { return 'Selectors only work on methods'; }),
86
- _a[VALIDATION_CODE.ZONE_WARNING] = (/**
87
- * @return {?}
88
- */
89
- function () {
90
- return 'Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
91
- 'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
92
- 'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })';
93
- }),
94
- _a[VALIDATION_CODE.PATCHING_ARRAY] = (/**
95
- * @return {?}
96
- */
97
- function () { return 'Patching arrays is not supported.'; }),
98
- _a[VALIDATION_CODE.PATCHING_PRIMITIVE] = (/**
99
- * @return {?}
100
- */
101
- function () { return 'Patching primitives is not supported.'; }),
102
- _a[VALIDATION_CODE.UNDECORATED_STATE_IN_IVY] = (/**
103
- * @param {?} name
104
- * @return {?}
105
- */
106
- function (name) {
107
- return "'" + name + "' class should be decorated with @Injectable() right after the @State() decorator";
108
- }),
109
- _a);
12
+ /**
13
+ * @param {?} name
14
+ * @return {?}
15
+ */
16
+ function throwStateNameError(name) {
17
+ throw new Error(name + " is not a valid state name. It needs to be a valid object property name.");
18
+ }
19
+ /**
20
+ * @return {?}
21
+ */
22
+ function throwStateNamePropertyError() {
23
+ throw new Error("States must register a 'name' property.");
24
+ }
25
+ /**
26
+ * @param {?} current
27
+ * @param {?} newName
28
+ * @param {?} oldName
29
+ * @return {?}
30
+ */
31
+ function throwStateUniqueError(current, newName, oldName) {
32
+ throw new Error("State name '" + current + "' from " + newName + " already exists in " + oldName + ".");
33
+ }
34
+ /**
35
+ * @param {?} name
36
+ * @return {?}
37
+ */
38
+ function throwStateDecoratorError(name) {
39
+ throw new Error("States must be decorated with @State() decorator, but \"" + name + "\" isn't.");
40
+ }
41
+ /**
42
+ * @return {?}
43
+ */
44
+ function throwActionDecoratorError() {
45
+ throw new Error('@Action() decorator cannot be used with static methods.');
46
+ }
47
+ /**
48
+ * @return {?}
49
+ */
50
+ function throwSelectorDecoratorError() {
51
+ throw new Error('Selectors only work on methods.');
52
+ }
53
+ /**
54
+ * @return {?}
55
+ */
56
+ function getZoneWarningMessage() {
57
+ return ('Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
58
+ 'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
59
+ 'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })');
60
+ }
61
+ /**
62
+ * @param {?} name
63
+ * @return {?}
64
+ */
65
+ function getUndecoratedStateInIvyWarningMessage(name) {
66
+ return "'" + name + "' class should be decorated with @Injectable() right after the @State() decorator";
67
+ }
68
+ /**
69
+ * @return {?}
70
+ */
71
+ function throwSelectFactoryNotConnectedError() {
72
+ throw new Error('You have forgotten to import the NGXS module!');
73
+ }
74
+ /**
75
+ * @return {?}
76
+ */
77
+ function throwPatchingArrayError() {
78
+ throw new Error('Patching arrays is not supported.');
79
+ }
80
+ /**
81
+ * @return {?}
82
+ */
83
+ function throwPatchingPrimitiveError() {
84
+ throw new Error('Patching primitives is not supported.');
85
+ }
110
86
 
111
87
  /**
112
88
  * @fileoverview added by tsickle
@@ -116,7 +92,11 @@ var DispatchOutsideZoneNgxsExecutionStrategy = /** @class */ (function () {
116
92
  function DispatchOutsideZoneNgxsExecutionStrategy(_ngZone, _platformId) {
117
93
  this._ngZone = _ngZone;
118
94
  this._platformId = _platformId;
119
- this.verifyZoneIsNotNooped(this._ngZone);
95
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
96
+ // creating a breaking change for projects that still use the View Engine.
97
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
98
+ verifyZoneIsNotNooped(_ngZone);
99
+ }
120
100
  }
121
101
  /**
122
102
  * @template T
@@ -183,33 +163,15 @@ var DispatchOutsideZoneNgxsExecutionStrategy = /** @class */ (function () {
183
163
  }
184
164
  return func();
185
165
  };
186
- /**
187
- * @private
188
- * @param {?} ngZone
189
- * @return {?}
190
- */
191
- DispatchOutsideZoneNgxsExecutionStrategy.prototype.verifyZoneIsNotNooped = /**
192
- * @private
193
- * @param {?} ngZone
194
- * @return {?}
195
- */
196
- function (ngZone) {
197
- // `NoopNgZone` is not exposed publicly as it doesn't expect
198
- // to be used outside of the core Angular code, thus we just have
199
- // to check if the zone doesn't extend or instanceof `NgZone`
200
- if (ngZone instanceof NgZone) {
201
- return;
202
- }
203
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.ZONE_WARNING]());
204
- };
205
166
  DispatchOutsideZoneNgxsExecutionStrategy.decorators = [
206
- { type: Injectable }
167
+ { type: Injectable, args: [{ providedIn: 'root' },] }
207
168
  ];
208
169
  /** @nocollapse */
209
170
  DispatchOutsideZoneNgxsExecutionStrategy.ctorParameters = function () { return [
210
171
  { type: NgZone },
211
172
  { type: String, decorators: [{ type: Inject, args: [PLATFORM_ID,] }] }
212
173
  ]; };
174
+ /** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ngInjectableDef = defineInjectable({ factory: function DispatchOutsideZoneNgxsExecutionStrategy_Factory() { return new DispatchOutsideZoneNgxsExecutionStrategy(inject(NgZone), inject(PLATFORM_ID)); }, token: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: "root" });
213
175
  return DispatchOutsideZoneNgxsExecutionStrategy;
214
176
  }());
215
177
  if (false) {
@@ -223,6 +185,21 @@ if (false) {
223
185
  * @private
224
186
  */
225
187
  DispatchOutsideZoneNgxsExecutionStrategy.prototype._platformId;
188
+ }
189
+ // Caretaker note: this should exist as a separate function and not a class method,
190
+ // since class methods are not tree-shakable.
191
+ /**
192
+ * @param {?} ngZone
193
+ * @return {?}
194
+ */
195
+ function verifyZoneIsNotNooped(ngZone) {
196
+ // `NoopNgZone` is not exposed publicly as it doesn't expect
197
+ // to be used outside of the core Angular code, thus we just have
198
+ // to check if the zone doesn't extend or instanceof `NgZone`.
199
+ if (ngZone instanceof NgZone) {
200
+ return;
201
+ }
202
+ console.warn(getZoneWarningMessage());
226
203
  }
227
204
 
228
205
  /**
@@ -236,10 +213,6 @@ var FEATURE_STATE_TOKEN = new InjectionToken('FEATURE_STATE_TOKEN');
236
213
  /** @type {?} */
237
214
  var NGXS_PLUGINS = new InjectionToken('NGXS_PLUGINS');
238
215
  /** @type {?} */
239
- var NG_TEST_MODE = new InjectionToken('NG_TEST_MODE');
240
- /** @type {?} */
241
- var NG_DEV_MODE = new InjectionToken('NG_DEV_MODE');
242
- /** @type {?} */
243
216
  var META_KEY = 'NGXS_META';
244
217
  /** @type {?} */
245
218
  var META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
@@ -282,6 +255,9 @@ if (false) {
282
255
  * Run in development mode. This will add additional debugging features:
283
256
  * - Object.freeze on the state and actions to guarantee immutability
284
257
  * (default: false)
258
+ *
259
+ * @deprecated This property is no longer necessary when the Ivy compiler is used.
260
+ * We'll determine the development mode through the `ngDevMode`. It's still essential with View Engine.
285
261
  * @type {?}
286
262
  */
287
263
  NgxsConfig.prototype.developmentMode;
@@ -450,11 +426,72 @@ if (false) {
450
426
  * @fileoverview added by tsickle
451
427
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
452
428
  */
429
+ var NoopNgxsExecutionStrategy = /** @class */ (function () {
430
+ function NoopNgxsExecutionStrategy() {
431
+ }
432
+ /**
433
+ * @template T
434
+ * @param {?} func
435
+ * @return {?}
436
+ */
437
+ NoopNgxsExecutionStrategy.prototype.enter = /**
438
+ * @template T
439
+ * @param {?} func
440
+ * @return {?}
441
+ */
442
+ function (func) {
443
+ return func();
444
+ };
445
+ /**
446
+ * @template T
447
+ * @param {?} func
448
+ * @return {?}
449
+ */
450
+ NoopNgxsExecutionStrategy.prototype.leave = /**
451
+ * @template T
452
+ * @param {?} func
453
+ * @return {?}
454
+ */
455
+ function (func) {
456
+ return func();
457
+ };
458
+ NoopNgxsExecutionStrategy.decorators = [
459
+ { type: Injectable, args: [{ providedIn: 'root' },] }
460
+ ];
461
+ /** @nocollapse */ NoopNgxsExecutionStrategy.ngInjectableDef = defineInjectable({ factory: function NoopNgxsExecutionStrategy_Factory() { return new NoopNgxsExecutionStrategy(); }, token: NoopNgxsExecutionStrategy, providedIn: "root" });
462
+ return NoopNgxsExecutionStrategy;
463
+ }());
464
+
465
+ /**
466
+ * @fileoverview added by tsickle
467
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
468
+ */
469
+ /**
470
+ * The strategy that might be provided by users through `options.executionStrategy`.
471
+ * @type {?}
472
+ */
473
+ var USER_PROVIDED_NGXS_EXECUTION_STRATEGY = new InjectionToken('USER_PROVIDED_NGXS_EXECUTION_STRATEGY');
453
474
  /*
454
475
  * Internal execution strategy injection token
455
476
  */
456
477
  /** @type {?} */
457
- var NGXS_EXECUTION_STRATEGY = new InjectionToken('NGXS_EXECUTION_STRATEGY');
478
+ var NGXS_EXECUTION_STRATEGY = new InjectionToken('NGXS_EXECUTION_STRATEGY', {
479
+ providedIn: 'root',
480
+ factory: (/**
481
+ * @return {?}
482
+ */
483
+ function () {
484
+ /** @type {?} */
485
+ var injector = inject(INJECTOR);
486
+ /** @type {?} */
487
+ var executionStrategy = injector.get(USER_PROVIDED_NGXS_EXECUTION_STRATEGY);
488
+ return executionStrategy
489
+ ? injector.get(executionStrategy)
490
+ : injector.get(typeof ɵglobal.Zone !== 'undefined'
491
+ ? DispatchOutsideZoneNgxsExecutionStrategy
492
+ : NoopNgxsExecutionStrategy);
493
+ })
494
+ });
458
495
  /**
459
496
  * @record
460
497
  */
@@ -935,10 +972,12 @@ function buildGraph(stateClasses) {
935
972
  * @return {?}
936
973
  */
937
974
  function (g) { return g === stateClass; }));
938
- if (!meta) {
975
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
976
+ // creating a breaking change for projects that still use the View Engine.
977
+ if ((typeof ngDevMode === 'undefined' || ngDevMode) && !meta) {
939
978
  throw new Error("Child state not found: " + stateClass + ". \r\nYou may have forgotten to add states to module");
940
979
  }
941
- return (/** @type {?} */ ((/** @type {?} */ (meta[META_KEY])).name));
980
+ return (/** @type {?} */ ((/** @type {?} */ ((/** @type {?} */ (meta))[META_KEY])).name));
942
981
  });
943
982
  return stateClasses.reduce((/**
944
983
  * @param {?} result
@@ -1070,7 +1109,9 @@ function topologicalSort(graph) {
1070
1109
  * @return {?}
1071
1110
  */
1072
1111
  function (dep) {
1073
- if (ancestors.indexOf(dep) >= 0) {
1112
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
1113
+ // creating a breaking change for projects that still use the View Engine.
1114
+ if ((typeof ngDevMode === 'undefined' || ngDevMode) && ancestors.indexOf(dep) >= 0) {
1074
1115
  throw new Error("Circular dependency '" + dep + "' is required by '" + name + "': " + ancestors.join(' -> '));
1075
1116
  }
1076
1117
  if (visited[dep]) {
@@ -1664,6 +1705,18 @@ var StateStream = /** @class */ (function (_super) {
1664
1705
  function StateStream() {
1665
1706
  return _super.call(this, {}) || this;
1666
1707
  }
1708
+ /**
1709
+ * @return {?}
1710
+ */
1711
+ StateStream.prototype.ngOnDestroy = /**
1712
+ * @return {?}
1713
+ */
1714
+ function () {
1715
+ // The `StateStream` should never emit values once the root view is removed, e.g. when the `NgModuleRef.destroy()` is called.
1716
+ // This will eliminate memory leaks in server-side rendered apps where the `StateStream` is created per each HTTP request, users
1717
+ // might forget to unsubscribe from `store.select` or `store.subscribe`, thus this will lead to huge memory leaks in SSR apps.
1718
+ this.complete();
1719
+ };
1667
1720
  StateStream.decorators = [
1668
1721
  { type: Injectable }
1669
1722
  ];
@@ -2025,103 +2078,6 @@ function (o) {
2025
2078
  return o;
2026
2079
  });
2027
2080
 
2028
- /**
2029
- * @fileoverview added by tsickle
2030
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2031
- */
2032
- var HostEnvironment = /** @class */ (function () {
2033
- function HostEnvironment(isDevMode, isTestMode) {
2034
- this.isDevMode = isDevMode;
2035
- this.isTestMode = isTestMode;
2036
- }
2037
- HostEnvironment.decorators = [
2038
- { type: Injectable }
2039
- ];
2040
- /** @nocollapse */
2041
- HostEnvironment.ctorParameters = function () { return [
2042
- { type: undefined, decorators: [{ type: Inject, args: [NG_DEV_MODE,] }] },
2043
- { type: undefined, decorators: [{ type: Inject, args: [NG_TEST_MODE,] }] }
2044
- ]; };
2045
- return HostEnvironment;
2046
- }());
2047
- if (false) {
2048
- /** @type {?} */
2049
- HostEnvironment.prototype.isDevMode;
2050
- /** @type {?} */
2051
- HostEnvironment.prototype.isTestMode;
2052
- }
2053
-
2054
- /**
2055
- * @fileoverview added by tsickle
2056
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2057
- */
2058
- var ConfigValidator = /** @class */ (function () {
2059
- function ConfigValidator(_host, _config) {
2060
- this._host = _host;
2061
- this._config = _config;
2062
- }
2063
- Object.defineProperty(ConfigValidator.prototype, "isIncorrectProduction", {
2064
- get: /**
2065
- * @private
2066
- * @return {?}
2067
- */
2068
- function () {
2069
- return !this._host.isDevMode() && this._config.developmentMode;
2070
- },
2071
- enumerable: true,
2072
- configurable: true
2073
- });
2074
- Object.defineProperty(ConfigValidator.prototype, "isIncorrectDevelopment", {
2075
- get: /**
2076
- * @private
2077
- * @return {?}
2078
- */
2079
- function () {
2080
- return this._host.isDevMode() && !this._config.developmentMode;
2081
- },
2082
- enumerable: true,
2083
- configurable: true
2084
- });
2085
- /**
2086
- * @return {?}
2087
- */
2088
- ConfigValidator.prototype.verifyDevMode = /**
2089
- * @return {?}
2090
- */
2091
- function () {
2092
- if (this._host.isTestMode()) {
2093
- return;
2094
- }
2095
- if (this.isIncorrectProduction) {
2096
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.INCORRECT_PRODUCTION]());
2097
- }
2098
- else if (this.isIncorrectDevelopment) {
2099
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.INCORRECT_DEVELOPMENT]());
2100
- }
2101
- };
2102
- ConfigValidator.decorators = [
2103
- { type: Injectable }
2104
- ];
2105
- /** @nocollapse */
2106
- ConfigValidator.ctorParameters = function () { return [
2107
- { type: HostEnvironment },
2108
- { type: NgxsConfig }
2109
- ]; };
2110
- return ConfigValidator;
2111
- }());
2112
- if (false) {
2113
- /**
2114
- * @type {?}
2115
- * @private
2116
- */
2117
- ConfigValidator.prototype._host;
2118
- /**
2119
- * @type {?}
2120
- * @private
2121
- */
2122
- ConfigValidator.prototype._config;
2123
- }
2124
-
2125
2081
  /**
2126
2082
  * @fileoverview added by tsickle
2127
2083
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -2131,11 +2087,10 @@ if (false) {
2131
2087
  * @ignore
2132
2088
  */
2133
2089
  var InternalStateOperations = /** @class */ (function () {
2134
- function InternalStateOperations(_stateStream, _dispatcher, _config, configValidator) {
2090
+ function InternalStateOperations(_stateStream, _dispatcher, _config) {
2135
2091
  this._stateStream = _stateStream;
2136
2092
  this._dispatcher = _dispatcher;
2137
2093
  this._config = _config;
2138
- configValidator.verifyDevMode();
2139
2094
  }
2140
2095
  /**
2141
2096
  * Returns the root state operators.
@@ -2167,44 +2122,22 @@ var InternalStateOperations = /** @class */ (function () {
2167
2122
  */
2168
2123
  function (actionOrActions) { return _this._dispatcher.dispatch(actionOrActions); })
2169
2124
  };
2170
- if (this._config.developmentMode) {
2171
- return this.ensureStateAndActionsAreImmutable(rootStateOperations);
2125
+ // We have to have that duplication since this will allow us to tree-shake `ensureStateAndActionsAreImmutable`
2126
+ // and `deepFreeze` in Ivy production build.
2127
+ // The below `if` condition checks 2 things:
2128
+ // 1) if we're in View Engine (`ngDevMode` is `undefined`)
2129
+ // 2) if we're running tests, we should fallback to `config.developmentMode` to be backwards-compatible
2130
+ if (typeof ngDevMode === 'undefined' || (ngDevMode && isAngularInTestMode())) {
2131
+ return this._config.developmentMode
2132
+ ? ensureStateAndActionsAreImmutable(rootStateOperations)
2133
+ : rootStateOperations;
2134
+ }
2135
+ else {
2136
+ // If we're in Ivy and not running tests, then tree-shake `ensureStateAndActionsAreImmutable` and `deepFreeze`.
2137
+ return ngDevMode
2138
+ ? ensureStateAndActionsAreImmutable(rootStateOperations)
2139
+ : rootStateOperations;
2172
2140
  }
2173
- return rootStateOperations;
2174
- };
2175
- /**
2176
- * @private
2177
- * @param {?} root
2178
- * @return {?}
2179
- */
2180
- InternalStateOperations.prototype.ensureStateAndActionsAreImmutable = /**
2181
- * @private
2182
- * @param {?} root
2183
- * @return {?}
2184
- */
2185
- function (root) {
2186
- return {
2187
- getState: (/**
2188
- * @return {?}
2189
- */
2190
- function () { return root.getState(); }),
2191
- setState: (/**
2192
- * @param {?} value
2193
- * @return {?}
2194
- */
2195
- function (value) {
2196
- /** @type {?} */
2197
- var frozenValue = deepFreeze(value);
2198
- return root.setState(frozenValue);
2199
- }),
2200
- dispatch: (/**
2201
- * @param {?} actions
2202
- * @return {?}
2203
- */
2204
- function (actions) {
2205
- return root.dispatch(actions);
2206
- })
2207
- };
2208
2141
  };
2209
2142
  /**
2210
2143
  * @param {?} results
@@ -2230,8 +2163,7 @@ var InternalStateOperations = /** @class */ (function () {
2230
2163
  InternalStateOperations.ctorParameters = function () { return [
2231
2164
  { type: StateStream },
2232
2165
  { type: InternalDispatcher },
2233
- { type: NgxsConfig },
2234
- { type: ConfigValidator }
2166
+ { type: NgxsConfig }
2235
2167
  ]; };
2236
2168
  return InternalStateOperations;
2237
2169
  }());
@@ -2251,6 +2183,34 @@ if (false) {
2251
2183
  * @private
2252
2184
  */
2253
2185
  InternalStateOperations.prototype._config;
2186
+ }
2187
+ /**
2188
+ * @param {?} root
2189
+ * @return {?}
2190
+ */
2191
+ function ensureStateAndActionsAreImmutable(root) {
2192
+ return {
2193
+ getState: (/**
2194
+ * @return {?}
2195
+ */
2196
+ function () { return root.getState(); }),
2197
+ setState: (/**
2198
+ * @param {?} value
2199
+ * @return {?}
2200
+ */
2201
+ function (value) {
2202
+ /** @type {?} */
2203
+ var frozenValue = deepFreeze(value);
2204
+ return root.setState(frozenValue);
2205
+ }),
2206
+ dispatch: (/**
2207
+ * @param {?} actions
2208
+ * @return {?}
2209
+ */
2210
+ function (actions) {
2211
+ return root.dispatch(actions);
2212
+ })
2213
+ };
2254
2214
  }
2255
2215
 
2256
2216
  /**
@@ -2269,10 +2229,10 @@ function simplePatch(val) {
2269
2229
  */
2270
2230
  function (existingState) {
2271
2231
  if (Array.isArray(val)) {
2272
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.PATCHING_ARRAY]());
2232
+ throwPatchingArrayError();
2273
2233
  }
2274
2234
  else if (typeof val !== 'object') {
2275
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.PATCHING_PRIMITIVE]());
2235
+ throwPatchingPrimitiveError();
2276
2236
  }
2277
2237
  /** @type {?} */
2278
2238
  var newState = __assign({}, ((/** @type {?} */ (existingState))));
@@ -2439,72 +2399,64 @@ var StoreValidators = /** @class */ (function () {
2439
2399
  * @param {?} name
2440
2400
  * @return {?}
2441
2401
  */
2442
- StoreValidators.stateNameErrorMessage = /**
2443
- * @param {?} name
2444
- * @return {?}
2445
- */
2446
- function (name) {
2447
- return CONFIG_MESSAGES[VALIDATION_CODE.STATE_NAME](name);
2448
- };
2449
- /**
2450
- * @param {?} name
2451
- * @return {?}
2452
- */
2453
- StoreValidators.checkCorrectStateName = /**
2402
+ StoreValidators.checkThatStateIsNamedCorrectly = /**
2454
2403
  * @param {?} name
2455
2404
  * @return {?}
2456
2405
  */
2457
2406
  function (name) {
2458
2407
  if (!name) {
2459
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.STATE_NAME_PROPERTY]());
2408
+ throwStateNamePropertyError();
2460
2409
  }
2461
- if (!this.stateNameRegex.test(name)) {
2462
- throw new Error(this.stateNameErrorMessage(name));
2410
+ else if (!this.stateNameRegex.test(name)) {
2411
+ throwStateNameError(name);
2463
2412
  }
2464
2413
  };
2465
2414
  /**
2415
+ * @param {?} stateName
2466
2416
  * @param {?} state
2467
2417
  * @param {?} statesByName
2468
2418
  * @return {?}
2469
2419
  */
2470
- StoreValidators.checkStateNameIsUnique = /**
2420
+ StoreValidators.checkThatStateNameIsUnique = /**
2421
+ * @param {?} stateName
2471
2422
  * @param {?} state
2472
2423
  * @param {?} statesByName
2473
2424
  * @return {?}
2474
2425
  */
2475
- function (state, statesByName) {
2476
- /** @type {?} */
2477
- var meta = this.getValidStateMeta(state);
2478
- /** @type {?} */
2479
- var stateName = (/** @type {?} */ ((/** @type {?} */ (meta)).name));
2426
+ function (stateName, state, statesByName) {
2480
2427
  /** @type {?} */
2481
2428
  var existingState = statesByName[stateName];
2482
2429
  if (existingState && existingState !== state) {
2483
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.STATE_UNIQUE](stateName, state.name, existingState.name));
2430
+ throwStateUniqueError(stateName, state.name, existingState.name);
2484
2431
  }
2485
- return stateName;
2486
2432
  };
2487
2433
  /**
2488
- * @param {?} state
2434
+ * @param {?} stateClasses
2489
2435
  * @return {?}
2490
2436
  */
2491
- StoreValidators.getValidStateMeta = /**
2492
- * @param {?} state
2437
+ StoreValidators.checkThatStateClassesHaveBeenDecorated = /**
2438
+ * @param {?} stateClasses
2493
2439
  * @return {?}
2494
2440
  */
2495
- function (state) {
2496
- /** @type {?} */
2497
- var meta = getStoreMetadata(state);
2498
- if (!meta) {
2499
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.STATE_DECORATOR]());
2500
- }
2501
- return meta;
2441
+ function (stateClasses) {
2442
+ stateClasses.forEach((/**
2443
+ * @param {?} stateClass
2444
+ * @return {?}
2445
+ */
2446
+ function (stateClass) {
2447
+ if (!getStoreMetadata(stateClass)) {
2448
+ throwStateDecoratorError(stateClass.name);
2449
+ }
2450
+ }));
2502
2451
  };
2503
2452
  StoreValidators.stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
2504
2453
  return StoreValidators;
2505
2454
  }());
2506
2455
  if (false) {
2507
- /** @type {?} */
2456
+ /**
2457
+ * @type {?}
2458
+ * @private
2459
+ */
2508
2460
  StoreValidators.stateNameRegex;
2509
2461
  }
2510
2462
 
@@ -2646,19 +2598,6 @@ var StateFactory = /** @class */ (function () {
2646
2598
  }
2647
2599
  return value;
2648
2600
  };
2649
- /**
2650
- * @private
2651
- * @param {?} stateClasses
2652
- * @return {?}
2653
- */
2654
- StateFactory.checkStatesAreValid = /**
2655
- * @private
2656
- * @param {?} stateClasses
2657
- * @return {?}
2658
- */
2659
- function (stateClasses) {
2660
- stateClasses.forEach(StoreValidators.getValidStateMeta);
2661
- };
2662
2601
  /**
2663
2602
  * @return {?}
2664
2603
  */
@@ -2687,7 +2626,11 @@ var StateFactory = /** @class */ (function () {
2687
2626
  */
2688
2627
  function (stateClasses) {
2689
2628
  var e_1, _a;
2690
- StateFactory.checkStatesAreValid(stateClasses);
2629
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
2630
+ // creating a breaking change for projects that still use the View Engine.
2631
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2632
+ StoreValidators.checkThatStateClassesHaveBeenDecorated(stateClasses);
2633
+ }
2691
2634
  var newStates = this.addToStatesMap(stateClasses).newStates;
2692
2635
  if (!newStates.length)
2693
2636
  return [];
@@ -2782,18 +2725,22 @@ var StateFactory = /** @class */ (function () {
2782
2725
  var _this = this;
2783
2726
  if (this._actionsSubscription !== null)
2784
2727
  return;
2728
+ /** @type {?} */
2729
+ var dispatched$ = new Subject();
2785
2730
  this._actionsSubscription = this._actions
2786
2731
  .pipe(filter((/**
2787
2732
  * @param {?} ctx
2788
2733
  * @return {?}
2789
2734
  */
2790
2735
  function (ctx) { return ctx.status === "DISPATCHED" /* Dispatched */; })), mergeMap((/**
2791
- * @param {?} __0
2736
+ * @param {?} ctx
2792
2737
  * @return {?}
2793
2738
  */
2794
- function (_a) {
2795
- var action = _a.action;
2796
- return _this.invokeActions(_this._actions, (/** @type {?} */ (action))).pipe(map((/**
2739
+ function (ctx) {
2740
+ dispatched$.next(ctx);
2741
+ /** @type {?} */
2742
+ var action = ctx.action;
2743
+ return _this.invokeActions(dispatched$, (/** @type {?} */ (action))).pipe(map((/**
2797
2744
  * @return {?}
2798
2745
  */
2799
2746
  function () { return (/** @type {?} */ ({ action: action, status: "SUCCESSFUL" /* Successful */ })); })), defaultIfEmpty((/** @type {?} */ ({ action: action, status: "CANCELED" /* Canceled */ }))), catchError((/**
@@ -2815,17 +2762,17 @@ var StateFactory = /** @class */ (function () {
2815
2762
  */
2816
2763
  /**
2817
2764
  * Invoke actions on the states.
2818
- * @param {?} actions$
2765
+ * @param {?} dispatched$
2819
2766
  * @param {?} action
2820
2767
  * @return {?}
2821
2768
  */
2822
2769
  StateFactory.prototype.invokeActions = /**
2823
2770
  * Invoke actions on the states.
2824
- * @param {?} actions$
2771
+ * @param {?} dispatched$
2825
2772
  * @param {?} action
2826
2773
  * @return {?}
2827
2774
  */
2828
- function (actions$, action) {
2775
+ function (dispatched$, action) {
2829
2776
  var e_2, _a, e_3, _b;
2830
2777
  /** @type {?} */
2831
2778
  var type = (/** @type {?} */ (getActionTypeFromInstance(action)));
@@ -2857,10 +2804,22 @@ var StateFactory = /** @class */ (function () {
2857
2804
  // `handler(ctx) { return EMPTY; }`
2858
2805
  // then the action will be canceled.
2859
2806
  // See https://github.com/ngxs/store/issues/1568
2860
- result = result.pipe(defaultIfEmpty({}));
2807
+ result = result.pipe(mergeMap((/**
2808
+ * @param {?} value
2809
+ * @return {?}
2810
+ */
2811
+ function (value) {
2812
+ if (value instanceof Promise) {
2813
+ return from(value);
2814
+ }
2815
+ if (value instanceof Observable) {
2816
+ return value;
2817
+ }
2818
+ return of(value);
2819
+ })), defaultIfEmpty({}));
2861
2820
  if (actionMeta.options.cancelUncompleted) {
2862
2821
  // todo: ofActionDispatched should be used with action class
2863
- result = result.pipe(takeUntil(actions$.pipe(ofActionDispatched((/** @type {?} */ (action))))));
2822
+ result = result.pipe(takeUntil(dispatched$.pipe(ofActionDispatched((/** @type {?} */ (action))))));
2864
2823
  }
2865
2824
  }
2866
2825
  else {
@@ -2915,7 +2874,12 @@ var StateFactory = /** @class */ (function () {
2915
2874
  for (var stateClasses_1 = __values(stateClasses), stateClasses_1_1 = stateClasses_1.next(); !stateClasses_1_1.done; stateClasses_1_1 = stateClasses_1.next()) {
2916
2875
  var stateClass = stateClasses_1_1.value;
2917
2876
  /** @type {?} */
2918
- var stateName = StoreValidators.checkStateNameIsUnique(stateClass, statesMap);
2877
+ var stateName = (/** @type {?} */ (getStoreMetadata(stateClass).name));
2878
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
2879
+ // creating a breaking change for projects that still use the View Engine.
2880
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2881
+ StoreValidators.checkThatStateNameIsUnique(stateName, stateClass, statesMap);
2882
+ }
2919
2883
  /** @type {?} */
2920
2884
  var unmountedState = !statesMap[stateName];
2921
2885
  if (unmountedState) {
@@ -3464,6 +3428,12 @@ var Store = /** @class */ (function () {
3464
3428
  this._config = _config;
3465
3429
  this._internalExecutionStrategy = _internalExecutionStrategy;
3466
3430
  this._stateFactory = _stateFactory;
3431
+ /**
3432
+ * This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
3433
+ * because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
3434
+ * All selects would use this stream, and it would call leave only once for any state change across all active selectors.
3435
+ */
3436
+ this._selectableStateStream = this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy), publishReplay(1), refCount());
3467
3437
  this.initStateStream(initialStateValue);
3468
3438
  }
3469
3439
  /**
@@ -3494,7 +3464,7 @@ var Store = /** @class */ (function () {
3494
3464
  var _this = this;
3495
3465
  /** @type {?} */
3496
3466
  var selectorFn = this.getStoreBoundSelectorFn(selector);
3497
- return this._stateStream.pipe(map(selectorFn), catchError((/**
3467
+ return this._selectableStateStream.pipe(map(selectorFn), catchError((/**
3498
3468
  * @param {?} err
3499
3469
  * @return {?}
3500
3470
  */
@@ -3546,7 +3516,9 @@ var Store = /** @class */ (function () {
3546
3516
  * @return {?}
3547
3517
  */
3548
3518
  function (fn) {
3549
- return this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy)).subscribe(fn);
3519
+ return this._selectableStateStream
3520
+ .pipe(leaveNgxs(this._internalExecutionStrategy))
3521
+ .subscribe(fn);
3550
3522
  };
3551
3523
  /**
3552
3524
  * Return the raw value of the state.
@@ -3637,6 +3609,14 @@ var Store = /** @class */ (function () {
3637
3609
  return Store;
3638
3610
  }());
3639
3611
  if (false) {
3612
+ /**
3613
+ * This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
3614
+ * because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
3615
+ * All selects would use this stream, and it would call leave only once for any state change across all active selectors.
3616
+ * @type {?}
3617
+ * @private
3618
+ */
3619
+ Store.prototype._selectableStateStream;
3640
3620
  /**
3641
3621
  * @type {?}
3642
3622
  * @private
@@ -3669,9 +3649,8 @@ if (false) {
3669
3649
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3670
3650
  */
3671
3651
  /**
3672
- * Allows the select decorator to get access to the DI store.
3673
- * \@internal only use in \@Select decorator
3674
- * @ignore
3652
+ * Allows the select decorator to get access to the DI store, this is used internally
3653
+ * in `\@Select` decorator.
3675
3654
  */
3676
3655
  var SelectFactory = /** @class */ (function () {
3677
3656
  function SelectFactory(store, config) {
@@ -3691,13 +3670,14 @@ var SelectFactory = /** @class */ (function () {
3691
3670
  SelectFactory.store = null;
3692
3671
  SelectFactory.config = null;
3693
3672
  SelectFactory.decorators = [
3694
- { type: Injectable }
3673
+ { type: Injectable, args: [{ providedIn: 'root' },] }
3695
3674
  ];
3696
3675
  /** @nocollapse */
3697
3676
  SelectFactory.ctorParameters = function () { return [
3698
3677
  { type: Store },
3699
3678
  { type: NgxsConfig }
3700
3679
  ]; };
3680
+ /** @nocollapse */ SelectFactory.ngInjectableDef = defineInjectable({ factory: function SelectFactory_Factory() { return new SelectFactory(inject(Store), inject(NgxsConfig)); }, token: SelectFactory, providedIn: "root" });
3701
3681
  return SelectFactory;
3702
3682
  }());
3703
3683
  if (false) {
@@ -3761,44 +3741,6 @@ if (false) {
3761
3741
  UpdateState.prototype.addedStates;
3762
3742
  }
3763
3743
 
3764
- /**
3765
- * @fileoverview added by tsickle
3766
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3767
- */
3768
- /** @type {?} */
3769
- var ivyEnabledInDevMode$ = new ReplaySubject(1);
3770
- /**
3771
- * Ivy exposes helper functions to the global `window.ng` object.
3772
- * Those functions are `getComponent, getContext,
3773
- * getListeners, getViewComponent, getHostElement, getInjector,
3774
- * getRootComponents, getDirectives, getDebugNode`
3775
- * Previously, old view engine exposed `window.ng.coreTokens` and
3776
- * `window.ng.probe` if an application was in development/production.
3777
- * Ivy doesn't expose these functions in production. Developers will be able
3778
- * to see warnings in both JIT/AOT modes, but only if an application
3779
- * is in development.
3780
- * @return {?}
3781
- */
3782
- function setIvyEnabledInDevMode() {
3783
- try {
3784
- // `try-catch` will also handle server-side rendering, as
3785
- // `window is not defined` will not be thrown.
3786
- /** @type {?} */
3787
- var ng = ((/** @type {?} */ (window))).ng;
3788
- /** @type {?} */
3789
- var _viewEngineEnabled = !!ng.probe && !!ng.coreTokens;
3790
- /** @type {?} */
3791
- var _ivyEnabledInDevMode = !_viewEngineEnabled && isDevMode();
3792
- ivyEnabledInDevMode$.next(_ivyEnabledInDevMode);
3793
- }
3794
- catch (_a) {
3795
- ivyEnabledInDevMode$.next(false);
3796
- }
3797
- finally {
3798
- ivyEnabledInDevMode$.complete();
3799
- }
3800
- }
3801
-
3802
3744
  /**
3803
3745
  * @fileoverview added by tsickle
3804
3746
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -3808,10 +3750,11 @@ function setIvyEnabledInDevMode() {
3808
3750
  * @ignore
3809
3751
  */
3810
3752
  var NgxsRootModule = /** @class */ (function () {
3811
- function NgxsRootModule(factory, internalStateOperations, _store, _select, states, lifecycleStateManager) {
3753
+ function NgxsRootModule(factory, internalStateOperations, _store, injector, states, lifecycleStateManager) {
3812
3754
  if (states === void 0) { states = []; }
3813
- // Validate states on having the `@Injectable()` decorator in Ivy
3814
- setIvyEnabledInDevMode();
3755
+ // If the user is running View Engine then we create the `SelectFactory` instance,
3756
+ // otherwise it'll be tree-shaken away in Ivy.
3757
+ !ɵivyEnabled && injector.get(SelectFactory);
3815
3758
  // Add stores to the state graph and return their defaults
3816
3759
  /** @type {?} */
3817
3760
  var results = factory.addAndReturnDefaults(states);
@@ -3829,7 +3772,7 @@ var NgxsRootModule = /** @class */ (function () {
3829
3772
  { type: StateFactory },
3830
3773
  { type: InternalStateOperations },
3831
3774
  { type: Store },
3832
- { type: SelectFactory },
3775
+ { type: Injector },
3833
3776
  { type: Array, decorators: [{ type: Optional }, { type: Inject, args: [ROOT_STATE_TOKEN,] }] },
3834
3777
  { type: LifecycleStateManager }
3835
3778
  ]; };
@@ -3929,8 +3872,6 @@ var NgxsModule = /** @class */ (function () {
3929
3872
  Actions,
3930
3873
  InternalActions,
3931
3874
  NgxsBootstrapper,
3932
- ConfigValidator,
3933
- HostEnvironment,
3934
3875
  LifecycleStateManager,
3935
3876
  InternalDispatcher,
3936
3877
  InternalDispatchedActionResults,
@@ -3938,7 +3879,6 @@ var NgxsModule = /** @class */ (function () {
3938
3879
  InternalNgxsExecutionStrategy,
3939
3880
  Store,
3940
3881
  StateStream,
3941
- SelectFactory,
3942
3882
  PluginManager
3943
3883
  ], states, NgxsModule.ngxsTokenProviders(states, options))
3944
3884
  };
@@ -3987,16 +3927,8 @@ var NgxsModule = /** @class */ (function () {
3987
3927
  function (states, options) {
3988
3928
  return [
3989
3929
  {
3990
- provide: NG_TEST_MODE,
3991
- useValue: isAngularInTestMode
3992
- },
3993
- {
3994
- provide: NG_DEV_MODE,
3995
- useValue: isDevMode
3996
- },
3997
- {
3998
- provide: NGXS_EXECUTION_STRATEGY,
3999
- useClass: options.executionStrategy || DispatchOutsideZoneNgxsExecutionStrategy
3930
+ provide: USER_PROVIDED_NGXS_EXECUTION_STRATEGY,
3931
+ useValue: options.executionStrategy
4000
3932
  },
4001
3933
  {
4002
3934
  provide: ROOT_STATE_TOKEN,
@@ -4103,10 +4035,14 @@ function Action(actions, options) {
4103
4035
  */
4104
4036
  function (target, name) {
4105
4037
  var e_1, _a;
4106
- /** @type {?} */
4107
- var isStaticMethod = target.hasOwnProperty('prototype');
4108
- if (isStaticMethod) {
4109
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.ACTION_DECORATOR]());
4038
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
4039
+ // creating a breaking change for projects that still use the View Engine.
4040
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
4041
+ /** @type {?} */
4042
+ var isStaticMethod = target.hasOwnProperty('prototype');
4043
+ if (isStaticMethod) {
4044
+ throwActionDecoratorError();
4045
+ }
4110
4046
  }
4111
4047
  /** @type {?} */
4112
4048
  var meta = ensureStoreMetadata(target.constructor);
@@ -4154,20 +4090,14 @@ function ensureStateClassIsInjectable(target) {
4154
4090
  // AOT mode because this property is added before runtime. If an application is running in
4155
4091
  // JIT mode then this property can be added by the `@Injectable()` decorator. The `@Injectable()`
4156
4092
  // decorator has to go after the `@State()` decorator, thus we prevent users from unwanted DI errors.
4157
- ivyEnabledInDevMode$.subscribe((/**
4158
- * @param {?} _ivyEnabledInDevMode
4159
- * @return {?}
4160
- */
4161
- function (_ivyEnabledInDevMode) {
4162
- if (_ivyEnabledInDevMode) {
4163
- /** @type {?} */
4164
- /** @nocollapse */ var ngInjectableDef = target.ɵprov;
4165
- if (!ngInjectableDef) {
4166
- // Don't warn if Ivy is disabled or `ɵprov` exists on the class
4167
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.UNDECORATED_STATE_IN_IVY](target.name));
4168
- }
4093
+ if (ɵivyEnabled) {
4094
+ /** @type {?} */
4095
+ /** @nocollapse */ var ngInjectableDef = target.ɵprov;
4096
+ if (!ngInjectableDef) {
4097
+ // Don't warn if Ivy is disabled or `ɵprov` exists on the class
4098
+ console.warn(getUndecoratedStateInIvyWarningMessage(target.name));
4169
4099
  }
4170
- }));
4100
+ }
4171
4101
  }
4172
4102
 
4173
4103
  /**
@@ -4212,7 +4142,11 @@ function State(options) {
4212
4142
  var children = optionsWithInheritance.children, defaults = optionsWithInheritance.defaults, name = optionsWithInheritance.name;
4213
4143
  /** @type {?} */
4214
4144
  var stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
4215
- StoreValidators.checkCorrectStateName(stateName);
4145
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
4146
+ // creating a breaking change for projects that still use the View Engine.
4147
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
4148
+ StoreValidators.checkThatStateIsNamedCorrectly(stateName);
4149
+ }
4216
4150
  if (inheritedStateClass.hasOwnProperty(META_KEY)) {
4217
4151
  /** @type {?} */
4218
4152
  var inheritedMeta = inheritedStateClass[META_KEY] || {};
@@ -4227,7 +4161,11 @@ function State(options) {
4227
4161
  * @return {?}
4228
4162
  */
4229
4163
  function (target) {
4230
- ensureStateClassIsInjectable(target);
4164
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
4165
+ // creating a breaking change for projects that still use the View Engine.
4166
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
4167
+ ensureStateClassIsInjectable(target);
4168
+ }
4231
4169
  /** @type {?} */
4232
4170
  var stateClass = target;
4233
4171
  /** @type {?} */
@@ -4250,30 +4188,37 @@ var DOLLAR_CHAR_CODE = 36;
4250
4188
  /**
4251
4189
  * @template T
4252
4190
  * @param {?} selector
4191
+ * @param {?} store
4253
4192
  * @return {?}
4254
4193
  */
4255
- function createSelectObservable(selector) {
4256
- if (!SelectFactory.store) {
4257
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.SELECT_FACTORY_NOT_CONNECTED]());
4258
- }
4259
- return SelectFactory.store.select(selector);
4194
+ function createSelectObservable(selector, store) {
4195
+ // We're doing this stuff to tree-shake the `SelectFactory` when the user
4196
+ // is running Ivy since NGXS will select the state from the provided `store` argument.
4197
+ return ɵivyEnabled
4198
+ ? createSelectObservableIvy(selector, store)
4199
+ : createSelectObservableViewEngine(selector);
4260
4200
  }
4261
4201
  /**
4202
+ * @param {?} config
4262
4203
  * @param {?} name
4263
4204
  * @param {?=} rawSelector
4264
4205
  * @param {?=} paths
4265
4206
  * @return {?}
4266
4207
  */
4267
- function createSelectorFn(name, rawSelector, paths) {
4208
+ function createSelectorFn(config, name, rawSelector, paths) {
4268
4209
  if (paths === void 0) { paths = []; }
4269
- rawSelector = !rawSelector ? removeDollarAtTheEnd(name) : rawSelector;
4270
- if (typeof rawSelector === 'string') {
4210
+ rawSelector = rawSelector || removeDollarAtTheEnd(name);
4211
+ if (typeof rawSelector !== 'string') {
4212
+ return rawSelector;
4213
+ }
4214
+ else {
4271
4215
  /** @type {?} */
4272
4216
  var propsArray = paths.length
4273
4217
  ? __spread([rawSelector], paths) : rawSelector.split('.');
4274
- return propGetter(propsArray, (/** @type {?} */ (SelectFactory.config)));
4218
+ return ɵivyEnabled
4219
+ ? createSelectorFnIvy(propsArray, config)
4220
+ : createSelectorFnViewEngine(propsArray);
4275
4221
  }
4276
- return rawSelector;
4277
4222
  }
4278
4223
  /**
4279
4224
  * \@example If `foo$` => make it just `foo`
@@ -4286,6 +4231,42 @@ function removeDollarAtTheEnd(name) {
4286
4231
  /** @type {?} */
4287
4232
  var dollarAtTheEnd = name.charCodeAt(lastCharIndex) === DOLLAR_CHAR_CODE;
4288
4233
  return dollarAtTheEnd ? name.slice(0, lastCharIndex) : name;
4234
+ }
4235
+ /**
4236
+ * @template T
4237
+ * @param {?} selector
4238
+ * @param {?} store
4239
+ * @return {?}
4240
+ */
4241
+ function createSelectObservableIvy(selector, store) {
4242
+ return ngDevMode && !store ? throwSelectFactoryNotConnectedError() : (/** @type {?} */ (store)).select(selector);
4243
+ }
4244
+ /**
4245
+ * @template T
4246
+ * @param {?} selector
4247
+ * @return {?}
4248
+ */
4249
+ function createSelectObservableViewEngine(selector) {
4250
+ return SelectFactory.store
4251
+ ? SelectFactory.store.select(selector)
4252
+ : throwSelectFactoryNotConnectedError();
4253
+ }
4254
+ /**
4255
+ * @param {?} propsArray
4256
+ * @param {?} config
4257
+ * @return {?}
4258
+ */
4259
+ function createSelectorFnIvy(propsArray, config) {
4260
+ return ngDevMode && !config
4261
+ ? throwSelectFactoryNotConnectedError()
4262
+ : propGetter(propsArray, (/** @type {?} */ (config)));
4263
+ }
4264
+ /**
4265
+ * @param {?} propsArray
4266
+ * @return {?}
4267
+ */
4268
+ function createSelectorFnViewEngine(propsArray) {
4269
+ return propGetter(propsArray, (/** @type {?} */ (SelectFactory.config)));
4289
4270
  }
4290
4271
 
4291
4272
  /**
@@ -4316,7 +4297,12 @@ function Select(rawSelector) {
4316
4297
  /** @type {?} */
4317
4298
  var selectorId = "__" + name + "__selector";
4318
4299
  /** @type {?} */
4319
- var selector = createSelectorFn(name, rawSelector, paths);
4300
+ var selector = null;
4301
+ /** @type {?} */
4302
+ var injectorNotifier$ = null;
4303
+ if (ɵivyEnabled) {
4304
+ injectorNotifier$ = ensureInjectorNotifierIsCaptured(target);
4305
+ }
4320
4306
  Object.defineProperties(target, (_a = {},
4321
4307
  _a[selectorId] = {
4322
4308
  writable: true,
@@ -4330,10 +4316,37 @@ function Select(rawSelector) {
4330
4316
  * @return {?}
4331
4317
  */
4332
4318
  function () {
4333
- return this[selectorId] || (this[selectorId] = createSelectObservable(selector));
4319
+ var _this = this;
4320
+ if (this[selectorId]) {
4321
+ return this[selectorId];
4322
+ }
4323
+ // The `localInject` will be tree-shaken away in apps that
4324
+ // still use the View Engine.
4325
+ if (ɵivyEnabled) {
4326
+ this[selectorId] = (/** @type {?} */ (injectorNotifier$)).pipe(mergeMap((/**
4327
+ * @return {?}
4328
+ */
4329
+ function () {
4330
+ /** @type {?} */
4331
+ var store = localInject(_this, Store);
4332
+ /** @type {?} */
4333
+ var config = localInject(_this, NgxsConfig);
4334
+ selector = selector || createSelectorFn(config, name, rawSelector, paths);
4335
+ return createSelectObservable(selector, store);
4336
+ })));
4337
+ }
4338
+ else {
4339
+ selector = selector || createSelectorFn(null, name, rawSelector, paths);
4340
+ this[selectorId] = createSelectObservable(selector, null);
4341
+ }
4342
+ return this[selectorId];
4334
4343
  }
4335
4344
  },
4336
4345
  _a));
4346
+ // Keep this `if` guard here so the below stuff will be tree-shaken away in apps that still use the View Engine.
4347
+ if (ɵivyEnabled) {
4348
+ ensureLocalInjectorCaptured(target);
4349
+ }
4337
4350
  });
4338
4351
  }
4339
4352
 
@@ -4452,10 +4465,14 @@ function Selector(selectors) {
4452
4465
  * @return {?}
4453
4466
  */
4454
4467
  function (target, key, descriptor) {
4455
- /** @type {?} */
4456
- var isNotMethod = !(descriptor && descriptor.value !== null);
4457
- if (isNotMethod) {
4458
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.SELECTOR_DECORATOR]());
4468
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
4469
+ // creating a breaking change for projects that still use the View Engine.
4470
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
4471
+ /** @type {?} */
4472
+ var isNotMethod = !(descriptor && descriptor.value !== null);
4473
+ if (isNotMethod) {
4474
+ throwSelectorDecoratorError();
4475
+ }
4459
4476
  }
4460
4477
  /** @type {?} */
4461
4478
  var originalFn = descriptor.value;
@@ -4486,45 +4503,6 @@ function Selector(selectors) {
4486
4503
  });
4487
4504
  }
4488
4505
 
4489
- /**
4490
- * @fileoverview added by tsickle
4491
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
4492
- */
4493
- var NoopNgxsExecutionStrategy = /** @class */ (function () {
4494
- function NoopNgxsExecutionStrategy() {
4495
- }
4496
- /**
4497
- * @template T
4498
- * @param {?} func
4499
- * @return {?}
4500
- */
4501
- NoopNgxsExecutionStrategy.prototype.enter = /**
4502
- * @template T
4503
- * @param {?} func
4504
- * @return {?}
4505
- */
4506
- function (func) {
4507
- return func();
4508
- };
4509
- /**
4510
- * @template T
4511
- * @param {?} func
4512
- * @return {?}
4513
- */
4514
- NoopNgxsExecutionStrategy.prototype.leave = /**
4515
- * @template T
4516
- * @param {?} func
4517
- * @return {?}
4518
- */
4519
- function (func) {
4520
- return func();
4521
- };
4522
- NoopNgxsExecutionStrategy.decorators = [
4523
- { type: Injectable }
4524
- ];
4525
- return NoopNgxsExecutionStrategy;
4526
- }());
4527
-
4528
4506
  /**
4529
4507
  * @fileoverview added by tsickle
4530
4508
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -4597,5 +4575,5 @@ if (false) {
4597
4575
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
4598
4576
  */
4599
4577
 
4600
- 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 };
4578
+ 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 };
4601
4579
  //# sourceMappingURL=ngxs-store.js.map