@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
@@ -223,108 +223,84 @@
223
223
  return value;
224
224
  }
225
225
 
226
- var _a;
227
226
  /**
228
227
  * @fileoverview added by tsickle
229
228
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
230
229
  */
231
- /** @enum {string} */
232
- var VALIDATION_CODE = {
233
- STATE_NAME: 'STATE_NAME',
234
- STATE_UNIQUE: 'STATE_UNIQUE',
235
- STATE_NAME_PROPERTY: 'STATE_NAME_PROPERTY',
236
- STATE_DECORATOR: 'STATE_DECORATOR',
237
- INCORRECT_PRODUCTION: 'INCORRECT_PRODUCTION',
238
- INCORRECT_DEVELOPMENT: 'INCORRECT_DEVELOPMENT',
239
- SELECT_FACTORY_NOT_CONNECTED: 'SELECT_FACTORY_NOT_CONNECTED',
240
- ACTION_DECORATOR: 'ACTION_DECORATOR',
241
- SELECTOR_DECORATOR: 'SELECTOR_DECORATOR',
242
- ZONE_WARNING: 'ZONE_WARNING',
243
- PATCHING_ARRAY: 'PATCHING_ARRAY',
244
- PATCHING_PRIMITIVE: 'PATCHING_PRIMITIVE',
245
- UNDECORATED_STATE_IN_IVY: 'UNDECORATED_STATE_IN_IVY',
246
- };
247
- /** @type {?} */
248
- var CONFIG_MESSAGES = (_a = {},
249
- _a[VALIDATION_CODE.STATE_NAME] = (/**
250
- * @param {?} name
251
- * @return {?}
252
- */
253
- function (name) {
254
- return name + " is not a valid state name. It needs to be a valid object property name.";
255
- }),
256
- _a[VALIDATION_CODE.STATE_NAME_PROPERTY] = (/**
257
- * @return {?}
258
- */
259
- function () { return "States must register a 'name' property"; }),
260
- _a[VALIDATION_CODE.STATE_UNIQUE] = (/**
261
- * @param {?} current
262
- * @param {?} newName
263
- * @param {?} oldName
264
- * @return {?}
265
- */
266
- function (current, newName, oldName) {
267
- return "State name '" + current + "' from " + newName + " already exists in " + oldName;
268
- }),
269
- _a[VALIDATION_CODE.STATE_DECORATOR] = (/**
270
- * @return {?}
271
- */
272
- function () { return 'States must be decorated with @State() decorator'; }),
273
- _a[VALIDATION_CODE.INCORRECT_PRODUCTION] = (/**
274
- * @return {?}
275
- */
276
- function () {
277
- return 'Angular is running in production mode but NGXS is still running in the development mode!\n' +
278
- 'Please set developmentMode to false on the NgxsModule options when in production mode.\n' +
279
- 'NgxsModule.forRoot(states, { developmentMode: !environment.production })';
280
- }),
281
- _a[VALIDATION_CODE.INCORRECT_DEVELOPMENT] = (/**
282
- * @return {?}
283
- */
284
- function () {
285
- return 'RECOMMENDATION: Set developmentMode to true on the NgxsModule when Angular is running in development mode.\n' +
286
- 'NgxsModule.forRoot(states, { developmentMode: !environment.production })';
287
- }),
288
- _a[VALIDATION_CODE.SELECT_FACTORY_NOT_CONNECTED] = (/**
289
- * @return {?}
290
- */
291
- function () {
292
- return 'You have forgotten to import the NGXS module!';
293
- }),
294
- _a[VALIDATION_CODE.ACTION_DECORATOR] = (/**
295
- * @return {?}
296
- */
297
- function () {
298
- return '@Action() decorator cannot be used with static methods';
299
- }),
300
- _a[VALIDATION_CODE.SELECTOR_DECORATOR] = (/**
301
- * @return {?}
302
- */
303
- function () { return 'Selectors only work on methods'; }),
304
- _a[VALIDATION_CODE.ZONE_WARNING] = (/**
305
- * @return {?}
306
- */
307
- function () {
308
- return 'Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
309
- 'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
310
- 'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })';
311
- }),
312
- _a[VALIDATION_CODE.PATCHING_ARRAY] = (/**
313
- * @return {?}
314
- */
315
- function () { return 'Patching arrays is not supported.'; }),
316
- _a[VALIDATION_CODE.PATCHING_PRIMITIVE] = (/**
317
- * @return {?}
318
- */
319
- function () { return 'Patching primitives is not supported.'; }),
320
- _a[VALIDATION_CODE.UNDECORATED_STATE_IN_IVY] = (/**
321
- * @param {?} name
322
- * @return {?}
323
- */
324
- function (name) {
325
- return "'" + name + "' class should be decorated with @Injectable() right after the @State() decorator";
326
- }),
327
- _a);
230
+ /**
231
+ * @param {?} name
232
+ * @return {?}
233
+ */
234
+ function throwStateNameError(name) {
235
+ throw new Error(name + " is not a valid state name. It needs to be a valid object property name.");
236
+ }
237
+ /**
238
+ * @return {?}
239
+ */
240
+ function throwStateNamePropertyError() {
241
+ throw new Error("States must register a 'name' property.");
242
+ }
243
+ /**
244
+ * @param {?} current
245
+ * @param {?} newName
246
+ * @param {?} oldName
247
+ * @return {?}
248
+ */
249
+ function throwStateUniqueError(current, newName, oldName) {
250
+ throw new Error("State name '" + current + "' from " + newName + " already exists in " + oldName + ".");
251
+ }
252
+ /**
253
+ * @param {?} name
254
+ * @return {?}
255
+ */
256
+ function throwStateDecoratorError(name) {
257
+ throw new Error("States must be decorated with @State() decorator, but \"" + name + "\" isn't.");
258
+ }
259
+ /**
260
+ * @return {?}
261
+ */
262
+ function throwActionDecoratorError() {
263
+ throw new Error('@Action() decorator cannot be used with static methods.');
264
+ }
265
+ /**
266
+ * @return {?}
267
+ */
268
+ function throwSelectorDecoratorError() {
269
+ throw new Error('Selectors only work on methods.');
270
+ }
271
+ /**
272
+ * @return {?}
273
+ */
274
+ function getZoneWarningMessage() {
275
+ return ('Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
276
+ 'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
277
+ 'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })');
278
+ }
279
+ /**
280
+ * @param {?} name
281
+ * @return {?}
282
+ */
283
+ function getUndecoratedStateInIvyWarningMessage(name) {
284
+ return "'" + name + "' class should be decorated with @Injectable() right after the @State() decorator";
285
+ }
286
+ /**
287
+ * @return {?}
288
+ */
289
+ function throwSelectFactoryNotConnectedError() {
290
+ throw new Error('You have forgotten to import the NGXS module!');
291
+ }
292
+ /**
293
+ * @return {?}
294
+ */
295
+ function throwPatchingArrayError() {
296
+ throw new Error('Patching arrays is not supported.');
297
+ }
298
+ /**
299
+ * @return {?}
300
+ */
301
+ function throwPatchingPrimitiveError() {
302
+ throw new Error('Patching primitives is not supported.');
303
+ }
328
304
 
329
305
  /**
330
306
  * @fileoverview added by tsickle
@@ -334,7 +310,11 @@
334
310
  function DispatchOutsideZoneNgxsExecutionStrategy(_ngZone, _platformId) {
335
311
  this._ngZone = _ngZone;
336
312
  this._platformId = _platformId;
337
- this.verifyZoneIsNotNooped(this._ngZone);
313
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
314
+ // creating a breaking change for projects that still use the View Engine.
315
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
316
+ verifyZoneIsNotNooped(_ngZone);
317
+ }
338
318
  }
339
319
  /**
340
320
  * @template T
@@ -401,33 +381,15 @@
401
381
  }
402
382
  return func();
403
383
  };
404
- /**
405
- * @private
406
- * @param {?} ngZone
407
- * @return {?}
408
- */
409
- DispatchOutsideZoneNgxsExecutionStrategy.prototype.verifyZoneIsNotNooped = /**
410
- * @private
411
- * @param {?} ngZone
412
- * @return {?}
413
- */
414
- function (ngZone) {
415
- // `NoopNgZone` is not exposed publicly as it doesn't expect
416
- // to be used outside of the core Angular code, thus we just have
417
- // to check if the zone doesn't extend or instanceof `NgZone`
418
- if (ngZone instanceof core.NgZone) {
419
- return;
420
- }
421
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.ZONE_WARNING]());
422
- };
423
384
  DispatchOutsideZoneNgxsExecutionStrategy.decorators = [
424
- { type: core.Injectable }
385
+ { type: core.Injectable, args: [{ providedIn: 'root' },] }
425
386
  ];
426
387
  /** @nocollapse */
427
388
  DispatchOutsideZoneNgxsExecutionStrategy.ctorParameters = function () { return [
428
389
  { type: core.NgZone },
429
390
  { type: String, decorators: [{ type: core.Inject, args: [core.PLATFORM_ID,] }] }
430
391
  ]; };
392
+ /** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ngInjectableDef = core.defineInjectable({ factory: function DispatchOutsideZoneNgxsExecutionStrategy_Factory() { return new DispatchOutsideZoneNgxsExecutionStrategy(core.inject(core.NgZone), core.inject(core.PLATFORM_ID)); }, token: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: "root" });
431
393
  return DispatchOutsideZoneNgxsExecutionStrategy;
432
394
  }());
433
395
  if (false) {
@@ -441,6 +403,21 @@
441
403
  * @private
442
404
  */
443
405
  DispatchOutsideZoneNgxsExecutionStrategy.prototype._platformId;
406
+ }
407
+ // Caretaker note: this should exist as a separate function and not a class method,
408
+ // since class methods are not tree-shakable.
409
+ /**
410
+ * @param {?} ngZone
411
+ * @return {?}
412
+ */
413
+ function verifyZoneIsNotNooped(ngZone) {
414
+ // `NoopNgZone` is not exposed publicly as it doesn't expect
415
+ // to be used outside of the core Angular code, thus we just have
416
+ // to check if the zone doesn't extend or instanceof `NgZone`.
417
+ if (ngZone instanceof core.NgZone) {
418
+ return;
419
+ }
420
+ console.warn(getZoneWarningMessage());
444
421
  }
445
422
 
446
423
  /**
@@ -454,10 +431,6 @@
454
431
  /** @type {?} */
455
432
  var NGXS_PLUGINS = new core.InjectionToken('NGXS_PLUGINS');
456
433
  /** @type {?} */
457
- var NG_TEST_MODE = new core.InjectionToken('NG_TEST_MODE');
458
- /** @type {?} */
459
- var NG_DEV_MODE = new core.InjectionToken('NG_DEV_MODE');
460
- /** @type {?} */
461
434
  var META_KEY = 'NGXS_META';
462
435
  /** @type {?} */
463
436
  var META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
@@ -500,6 +473,9 @@
500
473
  * Run in development mode. This will add additional debugging features:
501
474
  * - Object.freeze on the state and actions to guarantee immutability
502
475
  * (default: false)
476
+ *
477
+ * @deprecated This property is no longer necessary when the Ivy compiler is used.
478
+ * We'll determine the development mode through the `ngDevMode`. It's still essential with View Engine.
503
479
  * @type {?}
504
480
  */
505
481
  NgxsConfig.prototype.developmentMode;
@@ -668,11 +644,72 @@
668
644
  * @fileoverview added by tsickle
669
645
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
670
646
  */
647
+ var NoopNgxsExecutionStrategy = /** @class */ (function () {
648
+ function NoopNgxsExecutionStrategy() {
649
+ }
650
+ /**
651
+ * @template T
652
+ * @param {?} func
653
+ * @return {?}
654
+ */
655
+ NoopNgxsExecutionStrategy.prototype.enter = /**
656
+ * @template T
657
+ * @param {?} func
658
+ * @return {?}
659
+ */
660
+ function (func) {
661
+ return func();
662
+ };
663
+ /**
664
+ * @template T
665
+ * @param {?} func
666
+ * @return {?}
667
+ */
668
+ NoopNgxsExecutionStrategy.prototype.leave = /**
669
+ * @template T
670
+ * @param {?} func
671
+ * @return {?}
672
+ */
673
+ function (func) {
674
+ return func();
675
+ };
676
+ NoopNgxsExecutionStrategy.decorators = [
677
+ { type: core.Injectable, args: [{ providedIn: 'root' },] }
678
+ ];
679
+ /** @nocollapse */ NoopNgxsExecutionStrategy.ngInjectableDef = core.defineInjectable({ factory: function NoopNgxsExecutionStrategy_Factory() { return new NoopNgxsExecutionStrategy(); }, token: NoopNgxsExecutionStrategy, providedIn: "root" });
680
+ return NoopNgxsExecutionStrategy;
681
+ }());
682
+
683
+ /**
684
+ * @fileoverview added by tsickle
685
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
686
+ */
687
+ /**
688
+ * The strategy that might be provided by users through `options.executionStrategy`.
689
+ * @type {?}
690
+ */
691
+ var USER_PROVIDED_NGXS_EXECUTION_STRATEGY = new core.InjectionToken('USER_PROVIDED_NGXS_EXECUTION_STRATEGY');
671
692
  /*
672
693
  * Internal execution strategy injection token
673
694
  */
674
695
  /** @type {?} */
675
- var NGXS_EXECUTION_STRATEGY = new core.InjectionToken('NGXS_EXECUTION_STRATEGY');
696
+ var NGXS_EXECUTION_STRATEGY = new core.InjectionToken('NGXS_EXECUTION_STRATEGY', {
697
+ providedIn: 'root',
698
+ factory: (/**
699
+ * @return {?}
700
+ */
701
+ function () {
702
+ /** @type {?} */
703
+ var injector = core.inject(core.INJECTOR);
704
+ /** @type {?} */
705
+ var executionStrategy = injector.get(USER_PROVIDED_NGXS_EXECUTION_STRATEGY);
706
+ return executionStrategy
707
+ ? injector.get(executionStrategy)
708
+ : injector.get(typeof core.ɵglobal.Zone !== 'undefined'
709
+ ? DispatchOutsideZoneNgxsExecutionStrategy
710
+ : NoopNgxsExecutionStrategy);
711
+ })
712
+ });
676
713
  /**
677
714
  * @record
678
715
  */
@@ -1153,10 +1190,12 @@
1153
1190
  * @return {?}
1154
1191
  */
1155
1192
  function (g) { return g === stateClass; }));
1156
- if (!meta) {
1193
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
1194
+ // creating a breaking change for projects that still use the View Engine.
1195
+ if ((typeof ngDevMode === 'undefined' || ngDevMode) && !meta) {
1157
1196
  throw new Error("Child state not found: " + stateClass + ". \r\nYou may have forgotten to add states to module");
1158
1197
  }
1159
- return (/** @type {?} */ ((/** @type {?} */ (meta[META_KEY])).name));
1198
+ return (/** @type {?} */ ((/** @type {?} */ ((/** @type {?} */ (meta))[META_KEY])).name));
1160
1199
  });
1161
1200
  return stateClasses.reduce((/**
1162
1201
  * @param {?} result
@@ -1288,7 +1327,9 @@
1288
1327
  * @return {?}
1289
1328
  */
1290
1329
  function (dep) {
1291
- if (ancestors.indexOf(dep) >= 0) {
1330
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
1331
+ // creating a breaking change for projects that still use the View Engine.
1332
+ if ((typeof ngDevMode === 'undefined' || ngDevMode) && ancestors.indexOf(dep) >= 0) {
1292
1333
  throw new Error("Circular dependency '" + dep + "' is required by '" + name + "': " + ancestors.join(' -> '));
1293
1334
  }
1294
1335
  if (visited[dep]) {
@@ -1882,6 +1923,18 @@
1882
1923
  function StateStream() {
1883
1924
  return _super.call(this, {}) || this;
1884
1925
  }
1926
+ /**
1927
+ * @return {?}
1928
+ */
1929
+ StateStream.prototype.ngOnDestroy = /**
1930
+ * @return {?}
1931
+ */
1932
+ function () {
1933
+ // The `StateStream` should never emit values once the root view is removed, e.g. when the `NgModuleRef.destroy()` is called.
1934
+ // This will eliminate memory leaks in server-side rendered apps where the `StateStream` is created per each HTTP request, users
1935
+ // might forget to unsubscribe from `store.select` or `store.subscribe`, thus this will lead to huge memory leaks in SSR apps.
1936
+ this.complete();
1937
+ };
1885
1938
  StateStream.decorators = [
1886
1939
  { type: core.Injectable }
1887
1940
  ];
@@ -2243,103 +2296,6 @@
2243
2296
  return o;
2244
2297
  });
2245
2298
 
2246
- /**
2247
- * @fileoverview added by tsickle
2248
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2249
- */
2250
- var HostEnvironment = /** @class */ (function () {
2251
- function HostEnvironment(isDevMode, isTestMode) {
2252
- this.isDevMode = isDevMode;
2253
- this.isTestMode = isTestMode;
2254
- }
2255
- HostEnvironment.decorators = [
2256
- { type: core.Injectable }
2257
- ];
2258
- /** @nocollapse */
2259
- HostEnvironment.ctorParameters = function () { return [
2260
- { type: undefined, decorators: [{ type: core.Inject, args: [NG_DEV_MODE,] }] },
2261
- { type: undefined, decorators: [{ type: core.Inject, args: [NG_TEST_MODE,] }] }
2262
- ]; };
2263
- return HostEnvironment;
2264
- }());
2265
- if (false) {
2266
- /** @type {?} */
2267
- HostEnvironment.prototype.isDevMode;
2268
- /** @type {?} */
2269
- HostEnvironment.prototype.isTestMode;
2270
- }
2271
-
2272
- /**
2273
- * @fileoverview added by tsickle
2274
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2275
- */
2276
- var ConfigValidator = /** @class */ (function () {
2277
- function ConfigValidator(_host, _config) {
2278
- this._host = _host;
2279
- this._config = _config;
2280
- }
2281
- Object.defineProperty(ConfigValidator.prototype, "isIncorrectProduction", {
2282
- get: /**
2283
- * @private
2284
- * @return {?}
2285
- */
2286
- function () {
2287
- return !this._host.isDevMode() && this._config.developmentMode;
2288
- },
2289
- enumerable: true,
2290
- configurable: true
2291
- });
2292
- Object.defineProperty(ConfigValidator.prototype, "isIncorrectDevelopment", {
2293
- get: /**
2294
- * @private
2295
- * @return {?}
2296
- */
2297
- function () {
2298
- return this._host.isDevMode() && !this._config.developmentMode;
2299
- },
2300
- enumerable: true,
2301
- configurable: true
2302
- });
2303
- /**
2304
- * @return {?}
2305
- */
2306
- ConfigValidator.prototype.verifyDevMode = /**
2307
- * @return {?}
2308
- */
2309
- function () {
2310
- if (this._host.isTestMode()) {
2311
- return;
2312
- }
2313
- if (this.isIncorrectProduction) {
2314
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.INCORRECT_PRODUCTION]());
2315
- }
2316
- else if (this.isIncorrectDevelopment) {
2317
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.INCORRECT_DEVELOPMENT]());
2318
- }
2319
- };
2320
- ConfigValidator.decorators = [
2321
- { type: core.Injectable }
2322
- ];
2323
- /** @nocollapse */
2324
- ConfigValidator.ctorParameters = function () { return [
2325
- { type: HostEnvironment },
2326
- { type: NgxsConfig }
2327
- ]; };
2328
- return ConfigValidator;
2329
- }());
2330
- if (false) {
2331
- /**
2332
- * @type {?}
2333
- * @private
2334
- */
2335
- ConfigValidator.prototype._host;
2336
- /**
2337
- * @type {?}
2338
- * @private
2339
- */
2340
- ConfigValidator.prototype._config;
2341
- }
2342
-
2343
2299
  /**
2344
2300
  * @fileoverview added by tsickle
2345
2301
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -2349,11 +2305,10 @@
2349
2305
  * @ignore
2350
2306
  */
2351
2307
  var InternalStateOperations = /** @class */ (function () {
2352
- function InternalStateOperations(_stateStream, _dispatcher, _config, configValidator) {
2308
+ function InternalStateOperations(_stateStream, _dispatcher, _config) {
2353
2309
  this._stateStream = _stateStream;
2354
2310
  this._dispatcher = _dispatcher;
2355
2311
  this._config = _config;
2356
- configValidator.verifyDevMode();
2357
2312
  }
2358
2313
  /**
2359
2314
  * Returns the root state operators.
@@ -2385,44 +2340,22 @@
2385
2340
  */
2386
2341
  function (actionOrActions) { return _this._dispatcher.dispatch(actionOrActions); })
2387
2342
  };
2388
- if (this._config.developmentMode) {
2389
- return this.ensureStateAndActionsAreImmutable(rootStateOperations);
2343
+ // We have to have that duplication since this will allow us to tree-shake `ensureStateAndActionsAreImmutable`
2344
+ // and `deepFreeze` in Ivy production build.
2345
+ // The below `if` condition checks 2 things:
2346
+ // 1) if we're in View Engine (`ngDevMode` is `undefined`)
2347
+ // 2) if we're running tests, we should fallback to `config.developmentMode` to be backwards-compatible
2348
+ if (typeof ngDevMode === 'undefined' || (ngDevMode && internals.isAngularInTestMode())) {
2349
+ return this._config.developmentMode
2350
+ ? ensureStateAndActionsAreImmutable(rootStateOperations)
2351
+ : rootStateOperations;
2352
+ }
2353
+ else {
2354
+ // If we're in Ivy and not running tests, then tree-shake `ensureStateAndActionsAreImmutable` and `deepFreeze`.
2355
+ return ngDevMode
2356
+ ? ensureStateAndActionsAreImmutable(rootStateOperations)
2357
+ : rootStateOperations;
2390
2358
  }
2391
- return rootStateOperations;
2392
- };
2393
- /**
2394
- * @private
2395
- * @param {?} root
2396
- * @return {?}
2397
- */
2398
- InternalStateOperations.prototype.ensureStateAndActionsAreImmutable = /**
2399
- * @private
2400
- * @param {?} root
2401
- * @return {?}
2402
- */
2403
- function (root) {
2404
- return {
2405
- getState: (/**
2406
- * @return {?}
2407
- */
2408
- function () { return root.getState(); }),
2409
- setState: (/**
2410
- * @param {?} value
2411
- * @return {?}
2412
- */
2413
- function (value) {
2414
- /** @type {?} */
2415
- var frozenValue = deepFreeze(value);
2416
- return root.setState(frozenValue);
2417
- }),
2418
- dispatch: (/**
2419
- * @param {?} actions
2420
- * @return {?}
2421
- */
2422
- function (actions) {
2423
- return root.dispatch(actions);
2424
- })
2425
- };
2426
2359
  };
2427
2360
  /**
2428
2361
  * @param {?} results
@@ -2448,8 +2381,7 @@
2448
2381
  InternalStateOperations.ctorParameters = function () { return [
2449
2382
  { type: StateStream },
2450
2383
  { type: InternalDispatcher },
2451
- { type: NgxsConfig },
2452
- { type: ConfigValidator }
2384
+ { type: NgxsConfig }
2453
2385
  ]; };
2454
2386
  return InternalStateOperations;
2455
2387
  }());
@@ -2469,6 +2401,34 @@
2469
2401
  * @private
2470
2402
  */
2471
2403
  InternalStateOperations.prototype._config;
2404
+ }
2405
+ /**
2406
+ * @param {?} root
2407
+ * @return {?}
2408
+ */
2409
+ function ensureStateAndActionsAreImmutable(root) {
2410
+ return {
2411
+ getState: (/**
2412
+ * @return {?}
2413
+ */
2414
+ function () { return root.getState(); }),
2415
+ setState: (/**
2416
+ * @param {?} value
2417
+ * @return {?}
2418
+ */
2419
+ function (value) {
2420
+ /** @type {?} */
2421
+ var frozenValue = deepFreeze(value);
2422
+ return root.setState(frozenValue);
2423
+ }),
2424
+ dispatch: (/**
2425
+ * @param {?} actions
2426
+ * @return {?}
2427
+ */
2428
+ function (actions) {
2429
+ return root.dispatch(actions);
2430
+ })
2431
+ };
2472
2432
  }
2473
2433
 
2474
2434
  /**
@@ -2487,10 +2447,10 @@
2487
2447
  */
2488
2448
  function (existingState) {
2489
2449
  if (Array.isArray(val)) {
2490
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.PATCHING_ARRAY]());
2450
+ throwPatchingArrayError();
2491
2451
  }
2492
2452
  else if (typeof val !== 'object') {
2493
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.PATCHING_PRIMITIVE]());
2453
+ throwPatchingPrimitiveError();
2494
2454
  }
2495
2455
  /** @type {?} */
2496
2456
  var newState = __assign({}, ((/** @type {?} */ (existingState))));
@@ -2657,72 +2617,64 @@
2657
2617
  * @param {?} name
2658
2618
  * @return {?}
2659
2619
  */
2660
- StoreValidators.stateNameErrorMessage = /**
2661
- * @param {?} name
2662
- * @return {?}
2663
- */
2664
- function (name) {
2665
- return CONFIG_MESSAGES[VALIDATION_CODE.STATE_NAME](name);
2666
- };
2667
- /**
2668
- * @param {?} name
2669
- * @return {?}
2670
- */
2671
- StoreValidators.checkCorrectStateName = /**
2620
+ StoreValidators.checkThatStateIsNamedCorrectly = /**
2672
2621
  * @param {?} name
2673
2622
  * @return {?}
2674
2623
  */
2675
2624
  function (name) {
2676
2625
  if (!name) {
2677
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.STATE_NAME_PROPERTY]());
2626
+ throwStateNamePropertyError();
2678
2627
  }
2679
- if (!this.stateNameRegex.test(name)) {
2680
- throw new Error(this.stateNameErrorMessage(name));
2628
+ else if (!this.stateNameRegex.test(name)) {
2629
+ throwStateNameError(name);
2681
2630
  }
2682
2631
  };
2683
2632
  /**
2633
+ * @param {?} stateName
2684
2634
  * @param {?} state
2685
2635
  * @param {?} statesByName
2686
2636
  * @return {?}
2687
2637
  */
2688
- StoreValidators.checkStateNameIsUnique = /**
2638
+ StoreValidators.checkThatStateNameIsUnique = /**
2639
+ * @param {?} stateName
2689
2640
  * @param {?} state
2690
2641
  * @param {?} statesByName
2691
2642
  * @return {?}
2692
2643
  */
2693
- function (state, statesByName) {
2694
- /** @type {?} */
2695
- var meta = this.getValidStateMeta(state);
2696
- /** @type {?} */
2697
- var stateName = (/** @type {?} */ ((/** @type {?} */ (meta)).name));
2644
+ function (stateName, state, statesByName) {
2698
2645
  /** @type {?} */
2699
2646
  var existingState = statesByName[stateName];
2700
2647
  if (existingState && existingState !== state) {
2701
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.STATE_UNIQUE](stateName, state.name, existingState.name));
2648
+ throwStateUniqueError(stateName, state.name, existingState.name);
2702
2649
  }
2703
- return stateName;
2704
2650
  };
2705
2651
  /**
2706
- * @param {?} state
2652
+ * @param {?} stateClasses
2707
2653
  * @return {?}
2708
2654
  */
2709
- StoreValidators.getValidStateMeta = /**
2710
- * @param {?} state
2655
+ StoreValidators.checkThatStateClassesHaveBeenDecorated = /**
2656
+ * @param {?} stateClasses
2711
2657
  * @return {?}
2712
2658
  */
2713
- function (state) {
2714
- /** @type {?} */
2715
- var meta = getStoreMetadata(state);
2716
- if (!meta) {
2717
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.STATE_DECORATOR]());
2718
- }
2719
- return meta;
2659
+ function (stateClasses) {
2660
+ stateClasses.forEach((/**
2661
+ * @param {?} stateClass
2662
+ * @return {?}
2663
+ */
2664
+ function (stateClass) {
2665
+ if (!getStoreMetadata(stateClass)) {
2666
+ throwStateDecoratorError(stateClass.name);
2667
+ }
2668
+ }));
2720
2669
  };
2721
2670
  StoreValidators.stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
2722
2671
  return StoreValidators;
2723
2672
  }());
2724
2673
  if (false) {
2725
- /** @type {?} */
2674
+ /**
2675
+ * @type {?}
2676
+ * @private
2677
+ */
2726
2678
  StoreValidators.stateNameRegex;
2727
2679
  }
2728
2680
 
@@ -2864,19 +2816,6 @@
2864
2816
  }
2865
2817
  return value;
2866
2818
  };
2867
- /**
2868
- * @private
2869
- * @param {?} stateClasses
2870
- * @return {?}
2871
- */
2872
- StateFactory.checkStatesAreValid = /**
2873
- * @private
2874
- * @param {?} stateClasses
2875
- * @return {?}
2876
- */
2877
- function (stateClasses) {
2878
- stateClasses.forEach(StoreValidators.getValidStateMeta);
2879
- };
2880
2819
  /**
2881
2820
  * @return {?}
2882
2821
  */
@@ -2905,7 +2844,11 @@
2905
2844
  */
2906
2845
  function (stateClasses) {
2907
2846
  var e_1, _a;
2908
- StateFactory.checkStatesAreValid(stateClasses);
2847
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
2848
+ // creating a breaking change for projects that still use the View Engine.
2849
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
2850
+ StoreValidators.checkThatStateClassesHaveBeenDecorated(stateClasses);
2851
+ }
2909
2852
  var newStates = this.addToStatesMap(stateClasses).newStates;
2910
2853
  if (!newStates.length)
2911
2854
  return [];
@@ -3000,18 +2943,22 @@
3000
2943
  var _this = this;
3001
2944
  if (this._actionsSubscription !== null)
3002
2945
  return;
2946
+ /** @type {?} */
2947
+ var dispatched$ = new rxjs.Subject();
3003
2948
  this._actionsSubscription = this._actions
3004
2949
  .pipe(operators.filter((/**
3005
2950
  * @param {?} ctx
3006
2951
  * @return {?}
3007
2952
  */
3008
2953
  function (ctx) { return ctx.status === "DISPATCHED" /* Dispatched */; })), operators.mergeMap((/**
3009
- * @param {?} __0
2954
+ * @param {?} ctx
3010
2955
  * @return {?}
3011
2956
  */
3012
- function (_a) {
3013
- var action = _a.action;
3014
- return _this.invokeActions(_this._actions, (/** @type {?} */ (action))).pipe(operators.map((/**
2957
+ function (ctx) {
2958
+ dispatched$.next(ctx);
2959
+ /** @type {?} */
2960
+ var action = ctx.action;
2961
+ return _this.invokeActions(dispatched$, (/** @type {?} */ (action))).pipe(operators.map((/**
3015
2962
  * @return {?}
3016
2963
  */
3017
2964
  function () { return (/** @type {?} */ ({ action: action, status: "SUCCESSFUL" /* Successful */ })); })), operators.defaultIfEmpty((/** @type {?} */ ({ action: action, status: "CANCELED" /* Canceled */ }))), operators.catchError((/**
@@ -3033,17 +2980,17 @@
3033
2980
  */
3034
2981
  /**
3035
2982
  * Invoke actions on the states.
3036
- * @param {?} actions$
2983
+ * @param {?} dispatched$
3037
2984
  * @param {?} action
3038
2985
  * @return {?}
3039
2986
  */
3040
2987
  StateFactory.prototype.invokeActions = /**
3041
2988
  * Invoke actions on the states.
3042
- * @param {?} actions$
2989
+ * @param {?} dispatched$
3043
2990
  * @param {?} action
3044
2991
  * @return {?}
3045
2992
  */
3046
- function (actions$, action) {
2993
+ function (dispatched$, action) {
3047
2994
  var e_2, _a, e_3, _b;
3048
2995
  /** @type {?} */
3049
2996
  var type = (/** @type {?} */ (getActionTypeFromInstance(action)));
@@ -3075,10 +3022,22 @@
3075
3022
  // `handler(ctx) { return EMPTY; }`
3076
3023
  // then the action will be canceled.
3077
3024
  // See https://github.com/ngxs/store/issues/1568
3078
- result = result.pipe(operators.defaultIfEmpty({}));
3025
+ result = result.pipe(operators.mergeMap((/**
3026
+ * @param {?} value
3027
+ * @return {?}
3028
+ */
3029
+ function (value) {
3030
+ if (value instanceof Promise) {
3031
+ return rxjs.from(value);
3032
+ }
3033
+ if (value instanceof rxjs.Observable) {
3034
+ return value;
3035
+ }
3036
+ return rxjs.of(value);
3037
+ })), operators.defaultIfEmpty({}));
3079
3038
  if (actionMeta.options.cancelUncompleted) {
3080
3039
  // todo: ofActionDispatched should be used with action class
3081
- result = result.pipe(operators.takeUntil(actions$.pipe(ofActionDispatched((/** @type {?} */ (action))))));
3040
+ result = result.pipe(operators.takeUntil(dispatched$.pipe(ofActionDispatched((/** @type {?} */ (action))))));
3082
3041
  }
3083
3042
  }
3084
3043
  else {
@@ -3133,7 +3092,12 @@
3133
3092
  for (var stateClasses_1 = __values(stateClasses), stateClasses_1_1 = stateClasses_1.next(); !stateClasses_1_1.done; stateClasses_1_1 = stateClasses_1.next()) {
3134
3093
  var stateClass = stateClasses_1_1.value;
3135
3094
  /** @type {?} */
3136
- var stateName = StoreValidators.checkStateNameIsUnique(stateClass, statesMap);
3095
+ var stateName = (/** @type {?} */ (getStoreMetadata(stateClass).name));
3096
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
3097
+ // creating a breaking change for projects that still use the View Engine.
3098
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
3099
+ StoreValidators.checkThatStateNameIsUnique(stateName, stateClass, statesMap);
3100
+ }
3137
3101
  /** @type {?} */
3138
3102
  var unmountedState = !statesMap[stateName];
3139
3103
  if (unmountedState) {
@@ -3682,6 +3646,12 @@
3682
3646
  this._config = _config;
3683
3647
  this._internalExecutionStrategy = _internalExecutionStrategy;
3684
3648
  this._stateFactory = _stateFactory;
3649
+ /**
3650
+ * This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
3651
+ * because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
3652
+ * All selects would use this stream, and it would call leave only once for any state change across all active selectors.
3653
+ */
3654
+ this._selectableStateStream = this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy), operators.publishReplay(1), operators.refCount());
3685
3655
  this.initStateStream(initialStateValue);
3686
3656
  }
3687
3657
  /**
@@ -3712,7 +3682,7 @@
3712
3682
  var _this = this;
3713
3683
  /** @type {?} */
3714
3684
  var selectorFn = this.getStoreBoundSelectorFn(selector);
3715
- return this._stateStream.pipe(operators.map(selectorFn), operators.catchError((/**
3685
+ return this._selectableStateStream.pipe(operators.map(selectorFn), operators.catchError((/**
3716
3686
  * @param {?} err
3717
3687
  * @return {?}
3718
3688
  */
@@ -3764,7 +3734,9 @@
3764
3734
  * @return {?}
3765
3735
  */
3766
3736
  function (fn) {
3767
- return this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy)).subscribe(fn);
3737
+ return this._selectableStateStream
3738
+ .pipe(leaveNgxs(this._internalExecutionStrategy))
3739
+ .subscribe(fn);
3768
3740
  };
3769
3741
  /**
3770
3742
  * Return the raw value of the state.
@@ -3855,6 +3827,14 @@
3855
3827
  return Store;
3856
3828
  }());
3857
3829
  if (false) {
3830
+ /**
3831
+ * This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
3832
+ * because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
3833
+ * All selects would use this stream, and it would call leave only once for any state change across all active selectors.
3834
+ * @type {?}
3835
+ * @private
3836
+ */
3837
+ Store.prototype._selectableStateStream;
3858
3838
  /**
3859
3839
  * @type {?}
3860
3840
  * @private
@@ -3887,9 +3867,8 @@
3887
3867
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3888
3868
  */
3889
3869
  /**
3890
- * Allows the select decorator to get access to the DI store.
3891
- * \@internal only use in \@Select decorator
3892
- * @ignore
3870
+ * Allows the select decorator to get access to the DI store, this is used internally
3871
+ * in `\@Select` decorator.
3893
3872
  */
3894
3873
  var SelectFactory = /** @class */ (function () {
3895
3874
  function SelectFactory(store, config) {
@@ -3909,13 +3888,14 @@
3909
3888
  SelectFactory.store = null;
3910
3889
  SelectFactory.config = null;
3911
3890
  SelectFactory.decorators = [
3912
- { type: core.Injectable }
3891
+ { type: core.Injectable, args: [{ providedIn: 'root' },] }
3913
3892
  ];
3914
3893
  /** @nocollapse */
3915
3894
  SelectFactory.ctorParameters = function () { return [
3916
3895
  { type: Store },
3917
3896
  { type: NgxsConfig }
3918
3897
  ]; };
3898
+ /** @nocollapse */ SelectFactory.ngInjectableDef = core.defineInjectable({ factory: function SelectFactory_Factory() { return new SelectFactory(core.inject(Store), core.inject(NgxsConfig)); }, token: SelectFactory, providedIn: "root" });
3919
3899
  return SelectFactory;
3920
3900
  }());
3921
3901
  if (false) {
@@ -3979,44 +3959,6 @@
3979
3959
  UpdateState.prototype.addedStates;
3980
3960
  }
3981
3961
 
3982
- /**
3983
- * @fileoverview added by tsickle
3984
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3985
- */
3986
- /** @type {?} */
3987
- var ivyEnabledInDevMode$ = new rxjs.ReplaySubject(1);
3988
- /**
3989
- * Ivy exposes helper functions to the global `window.ng` object.
3990
- * Those functions are `getComponent, getContext,
3991
- * getListeners, getViewComponent, getHostElement, getInjector,
3992
- * getRootComponents, getDirectives, getDebugNode`
3993
- * Previously, old view engine exposed `window.ng.coreTokens` and
3994
- * `window.ng.probe` if an application was in development/production.
3995
- * Ivy doesn't expose these functions in production. Developers will be able
3996
- * to see warnings in both JIT/AOT modes, but only if an application
3997
- * is in development.
3998
- * @return {?}
3999
- */
4000
- function setIvyEnabledInDevMode() {
4001
- try {
4002
- // `try-catch` will also handle server-side rendering, as
4003
- // `window is not defined` will not be thrown.
4004
- /** @type {?} */
4005
- var ng = ((/** @type {?} */ (window))).ng;
4006
- /** @type {?} */
4007
- var _viewEngineEnabled = !!ng.probe && !!ng.coreTokens;
4008
- /** @type {?} */
4009
- var _ivyEnabledInDevMode = !_viewEngineEnabled && core.isDevMode();
4010
- ivyEnabledInDevMode$.next(_ivyEnabledInDevMode);
4011
- }
4012
- catch (_a) {
4013
- ivyEnabledInDevMode$.next(false);
4014
- }
4015
- finally {
4016
- ivyEnabledInDevMode$.complete();
4017
- }
4018
- }
4019
-
4020
3962
  /**
4021
3963
  * @fileoverview added by tsickle
4022
3964
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -4026,10 +3968,11 @@
4026
3968
  * @ignore
4027
3969
  */
4028
3970
  var NgxsRootModule = /** @class */ (function () {
4029
- function NgxsRootModule(factory, internalStateOperations, _store, _select, states, lifecycleStateManager) {
3971
+ function NgxsRootModule(factory, internalStateOperations, _store, injector, states, lifecycleStateManager) {
4030
3972
  if (states === void 0) { states = []; }
4031
- // Validate states on having the `@Injectable()` decorator in Ivy
4032
- setIvyEnabledInDevMode();
3973
+ // If the user is running View Engine then we create the `SelectFactory` instance,
3974
+ // otherwise it'll be tree-shaken away in Ivy.
3975
+ !core.ɵivyEnabled && injector.get(SelectFactory);
4033
3976
  // Add stores to the state graph and return their defaults
4034
3977
  /** @type {?} */
4035
3978
  var results = factory.addAndReturnDefaults(states);
@@ -4047,7 +3990,7 @@
4047
3990
  { type: StateFactory },
4048
3991
  { type: InternalStateOperations },
4049
3992
  { type: Store },
4050
- { type: SelectFactory },
3993
+ { type: core.Injector },
4051
3994
  { type: Array, decorators: [{ type: core.Optional }, { type: core.Inject, args: [ROOT_STATE_TOKEN,] }] },
4052
3995
  { type: LifecycleStateManager }
4053
3996
  ]; };
@@ -4147,8 +4090,6 @@
4147
4090
  Actions,
4148
4091
  InternalActions,
4149
4092
  internals.NgxsBootstrapper,
4150
- ConfigValidator,
4151
- HostEnvironment,
4152
4093
  LifecycleStateManager,
4153
4094
  InternalDispatcher,
4154
4095
  InternalDispatchedActionResults,
@@ -4156,7 +4097,6 @@
4156
4097
  InternalNgxsExecutionStrategy,
4157
4098
  Store,
4158
4099
  StateStream,
4159
- SelectFactory,
4160
4100
  PluginManager
4161
4101
  ], states, NgxsModule.ngxsTokenProviders(states, options))
4162
4102
  };
@@ -4205,16 +4145,8 @@
4205
4145
  function (states, options) {
4206
4146
  return [
4207
4147
  {
4208
- provide: NG_TEST_MODE,
4209
- useValue: internals.isAngularInTestMode
4210
- },
4211
- {
4212
- provide: NG_DEV_MODE,
4213
- useValue: core.isDevMode
4214
- },
4215
- {
4216
- provide: NGXS_EXECUTION_STRATEGY,
4217
- useClass: options.executionStrategy || DispatchOutsideZoneNgxsExecutionStrategy
4148
+ provide: USER_PROVIDED_NGXS_EXECUTION_STRATEGY,
4149
+ useValue: options.executionStrategy
4218
4150
  },
4219
4151
  {
4220
4152
  provide: ROOT_STATE_TOKEN,
@@ -4321,10 +4253,14 @@
4321
4253
  */
4322
4254
  function (target, name) {
4323
4255
  var e_1, _a;
4324
- /** @type {?} */
4325
- var isStaticMethod = target.hasOwnProperty('prototype');
4326
- if (isStaticMethod) {
4327
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.ACTION_DECORATOR]());
4256
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
4257
+ // creating a breaking change for projects that still use the View Engine.
4258
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
4259
+ /** @type {?} */
4260
+ var isStaticMethod = target.hasOwnProperty('prototype');
4261
+ if (isStaticMethod) {
4262
+ throwActionDecoratorError();
4263
+ }
4328
4264
  }
4329
4265
  /** @type {?} */
4330
4266
  var meta = ensureStoreMetadata(target.constructor);
@@ -4372,20 +4308,14 @@
4372
4308
  // AOT mode because this property is added before runtime. If an application is running in
4373
4309
  // JIT mode then this property can be added by the `@Injectable()` decorator. The `@Injectable()`
4374
4310
  // decorator has to go after the `@State()` decorator, thus we prevent users from unwanted DI errors.
4375
- ivyEnabledInDevMode$.subscribe((/**
4376
- * @param {?} _ivyEnabledInDevMode
4377
- * @return {?}
4378
- */
4379
- function (_ivyEnabledInDevMode) {
4380
- if (_ivyEnabledInDevMode) {
4381
- /** @type {?} */
4382
- /** @nocollapse */ var ngInjectableDef = target.ɵprov;
4383
- if (!ngInjectableDef) {
4384
- // Don't warn if Ivy is disabled or `ɵprov` exists on the class
4385
- console.warn(CONFIG_MESSAGES[VALIDATION_CODE.UNDECORATED_STATE_IN_IVY](target.name));
4386
- }
4311
+ if (core.ɵivyEnabled) {
4312
+ /** @type {?} */
4313
+ /** @nocollapse */ var ngInjectableDef = target.ɵprov;
4314
+ if (!ngInjectableDef) {
4315
+ // Don't warn if Ivy is disabled or `ɵprov` exists on the class
4316
+ console.warn(getUndecoratedStateInIvyWarningMessage(target.name));
4387
4317
  }
4388
- }));
4318
+ }
4389
4319
  }
4390
4320
 
4391
4321
  /**
@@ -4430,7 +4360,11 @@
4430
4360
  var children = optionsWithInheritance.children, defaults = optionsWithInheritance.defaults, name = optionsWithInheritance.name;
4431
4361
  /** @type {?} */
4432
4362
  var stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
4433
- StoreValidators.checkCorrectStateName(stateName);
4363
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
4364
+ // creating a breaking change for projects that still use the View Engine.
4365
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
4366
+ StoreValidators.checkThatStateIsNamedCorrectly(stateName);
4367
+ }
4434
4368
  if (inheritedStateClass.hasOwnProperty(META_KEY)) {
4435
4369
  /** @type {?} */
4436
4370
  var inheritedMeta = inheritedStateClass[META_KEY] || {};
@@ -4445,7 +4379,11 @@
4445
4379
  * @return {?}
4446
4380
  */
4447
4381
  function (target) {
4448
- ensureStateClassIsInjectable(target);
4382
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
4383
+ // creating a breaking change for projects that still use the View Engine.
4384
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
4385
+ ensureStateClassIsInjectable(target);
4386
+ }
4449
4387
  /** @type {?} */
4450
4388
  var stateClass = target;
4451
4389
  /** @type {?} */
@@ -4468,30 +4406,37 @@
4468
4406
  /**
4469
4407
  * @template T
4470
4408
  * @param {?} selector
4409
+ * @param {?} store
4471
4410
  * @return {?}
4472
4411
  */
4473
- function createSelectObservable(selector) {
4474
- if (!SelectFactory.store) {
4475
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.SELECT_FACTORY_NOT_CONNECTED]());
4476
- }
4477
- return SelectFactory.store.select(selector);
4412
+ function createSelectObservable(selector, store) {
4413
+ // We're doing this stuff to tree-shake the `SelectFactory` when the user
4414
+ // is running Ivy since NGXS will select the state from the provided `store` argument.
4415
+ return core.ɵivyEnabled
4416
+ ? createSelectObservableIvy(selector, store)
4417
+ : createSelectObservableViewEngine(selector);
4478
4418
  }
4479
4419
  /**
4420
+ * @param {?} config
4480
4421
  * @param {?} name
4481
4422
  * @param {?=} rawSelector
4482
4423
  * @param {?=} paths
4483
4424
  * @return {?}
4484
4425
  */
4485
- function createSelectorFn(name, rawSelector, paths) {
4426
+ function createSelectorFn(config, name, rawSelector, paths) {
4486
4427
  if (paths === void 0) { paths = []; }
4487
- rawSelector = !rawSelector ? removeDollarAtTheEnd(name) : rawSelector;
4488
- if (typeof rawSelector === 'string') {
4428
+ rawSelector = rawSelector || removeDollarAtTheEnd(name);
4429
+ if (typeof rawSelector !== 'string') {
4430
+ return rawSelector;
4431
+ }
4432
+ else {
4489
4433
  /** @type {?} */
4490
4434
  var propsArray = paths.length
4491
4435
  ? __spread([rawSelector], paths) : rawSelector.split('.');
4492
- return propGetter(propsArray, (/** @type {?} */ (SelectFactory.config)));
4436
+ return core.ɵivyEnabled
4437
+ ? createSelectorFnIvy(propsArray, config)
4438
+ : createSelectorFnViewEngine(propsArray);
4493
4439
  }
4494
- return rawSelector;
4495
4440
  }
4496
4441
  /**
4497
4442
  * \@example If `foo$` => make it just `foo`
@@ -4504,6 +4449,42 @@
4504
4449
  /** @type {?} */
4505
4450
  var dollarAtTheEnd = name.charCodeAt(lastCharIndex) === DOLLAR_CHAR_CODE;
4506
4451
  return dollarAtTheEnd ? name.slice(0, lastCharIndex) : name;
4452
+ }
4453
+ /**
4454
+ * @template T
4455
+ * @param {?} selector
4456
+ * @param {?} store
4457
+ * @return {?}
4458
+ */
4459
+ function createSelectObservableIvy(selector, store) {
4460
+ return ngDevMode && !store ? throwSelectFactoryNotConnectedError() : (/** @type {?} */ (store)).select(selector);
4461
+ }
4462
+ /**
4463
+ * @template T
4464
+ * @param {?} selector
4465
+ * @return {?}
4466
+ */
4467
+ function createSelectObservableViewEngine(selector) {
4468
+ return SelectFactory.store
4469
+ ? SelectFactory.store.select(selector)
4470
+ : throwSelectFactoryNotConnectedError();
4471
+ }
4472
+ /**
4473
+ * @param {?} propsArray
4474
+ * @param {?} config
4475
+ * @return {?}
4476
+ */
4477
+ function createSelectorFnIvy(propsArray, config) {
4478
+ return ngDevMode && !config
4479
+ ? throwSelectFactoryNotConnectedError()
4480
+ : propGetter(propsArray, (/** @type {?} */ (config)));
4481
+ }
4482
+ /**
4483
+ * @param {?} propsArray
4484
+ * @return {?}
4485
+ */
4486
+ function createSelectorFnViewEngine(propsArray) {
4487
+ return propGetter(propsArray, (/** @type {?} */ (SelectFactory.config)));
4507
4488
  }
4508
4489
 
4509
4490
  /**
@@ -4534,7 +4515,12 @@
4534
4515
  /** @type {?} */
4535
4516
  var selectorId = "__" + name + "__selector";
4536
4517
  /** @type {?} */
4537
- var selector = createSelectorFn(name, rawSelector, paths);
4518
+ var selector = null;
4519
+ /** @type {?} */
4520
+ var injectorNotifier$ = null;
4521
+ if (core.ɵivyEnabled) {
4522
+ injectorNotifier$ = internals.ensureInjectorNotifierIsCaptured(target);
4523
+ }
4538
4524
  Object.defineProperties(target, (_a = {},
4539
4525
  _a[selectorId] = {
4540
4526
  writable: true,
@@ -4548,10 +4534,37 @@
4548
4534
  * @return {?}
4549
4535
  */
4550
4536
  function () {
4551
- return this[selectorId] || (this[selectorId] = createSelectObservable(selector));
4537
+ var _this = this;
4538
+ if (this[selectorId]) {
4539
+ return this[selectorId];
4540
+ }
4541
+ // The `localInject` will be tree-shaken away in apps that
4542
+ // still use the View Engine.
4543
+ if (core.ɵivyEnabled) {
4544
+ this[selectorId] = (/** @type {?} */ (injectorNotifier$)).pipe(operators.mergeMap((/**
4545
+ * @return {?}
4546
+ */
4547
+ function () {
4548
+ /** @type {?} */
4549
+ var store = internals.localInject(_this, Store);
4550
+ /** @type {?} */
4551
+ var config = internals.localInject(_this, NgxsConfig);
4552
+ selector = selector || createSelectorFn(config, name, rawSelector, paths);
4553
+ return createSelectObservable(selector, store);
4554
+ })));
4555
+ }
4556
+ else {
4557
+ selector = selector || createSelectorFn(null, name, rawSelector, paths);
4558
+ this[selectorId] = createSelectObservable(selector, null);
4559
+ }
4560
+ return this[selectorId];
4552
4561
  }
4553
4562
  },
4554
4563
  _a));
4564
+ // Keep this `if` guard here so the below stuff will be tree-shaken away in apps that still use the View Engine.
4565
+ if (core.ɵivyEnabled) {
4566
+ internals.ensureLocalInjectorCaptured(target);
4567
+ }
4555
4568
  });
4556
4569
  }
4557
4570
 
@@ -4670,10 +4683,14 @@
4670
4683
  * @return {?}
4671
4684
  */
4672
4685
  function (target, key, descriptor) {
4673
- /** @type {?} */
4674
- var isNotMethod = !(descriptor && descriptor.value !== null);
4675
- if (isNotMethod) {
4676
- throw new Error(CONFIG_MESSAGES[VALIDATION_CODE.SELECTOR_DECORATOR]());
4686
+ // Caretaker note: we have still left the `typeof` condition in order to avoid
4687
+ // creating a breaking change for projects that still use the View Engine.
4688
+ if (typeof ngDevMode === 'undefined' || ngDevMode) {
4689
+ /** @type {?} */
4690
+ var isNotMethod = !(descriptor && descriptor.value !== null);
4691
+ if (isNotMethod) {
4692
+ throwSelectorDecoratorError();
4693
+ }
4677
4694
  }
4678
4695
  /** @type {?} */
4679
4696
  var originalFn = descriptor.value;
@@ -4704,45 +4721,6 @@
4704
4721
  });
4705
4722
  }
4706
4723
 
4707
- /**
4708
- * @fileoverview added by tsickle
4709
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
4710
- */
4711
- var NoopNgxsExecutionStrategy = /** @class */ (function () {
4712
- function NoopNgxsExecutionStrategy() {
4713
- }
4714
- /**
4715
- * @template T
4716
- * @param {?} func
4717
- * @return {?}
4718
- */
4719
- NoopNgxsExecutionStrategy.prototype.enter = /**
4720
- * @template T
4721
- * @param {?} func
4722
- * @return {?}
4723
- */
4724
- function (func) {
4725
- return func();
4726
- };
4727
- /**
4728
- * @template T
4729
- * @param {?} func
4730
- * @return {?}
4731
- */
4732
- NoopNgxsExecutionStrategy.prototype.leave = /**
4733
- * @template T
4734
- * @param {?} func
4735
- * @return {?}
4736
- */
4737
- function (func) {
4738
- return func();
4739
- };
4740
- NoopNgxsExecutionStrategy.decorators = [
4741
- { type: core.Injectable }
4742
- ];
4743
- return NoopNgxsExecutionStrategy;
4744
- }());
4745
-
4746
4724
  /**
4747
4725
  * @fileoverview added by tsickle
4748
4726
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -4827,32 +4805,27 @@
4827
4805
  exports.setValue = setValue;
4828
4806
  exports.ɵa = OrderedSubject;
4829
4807
  exports.ɵb = InternalActions;
4830
- exports.ɵba = SelectFactory;
4831
- exports.ɵbb = LifecycleStateManager;
4832
- exports.ɵbc = NgxsFeatureModule;
4833
- exports.ɵbd = DispatchOutsideZoneNgxsExecutionStrategy;
4834
4808
  exports.ɵc = ROOT_STATE_TOKEN;
4835
4809
  exports.ɵd = FEATURE_STATE_TOKEN;
4836
- exports.ɵe = NG_TEST_MODE;
4837
- exports.ɵf = NG_DEV_MODE;
4838
- exports.ɵg = SELECTOR_META_KEY;
4839
- exports.ɵh = NgxsConfig;
4840
- exports.ɵi = mergeDeep;
4841
- exports.ɵj = NGXS_EXECUTION_STRATEGY;
4842
- exports.ɵk = NgxsRootModule;
4843
- exports.ɵl = StateFactory;
4844
- exports.ɵm = InternalDispatchedActionResults;
4845
- exports.ɵn = InternalDispatcher;
4846
- exports.ɵo = StateContextFactory;
4847
- exports.ɵp = InternalStateOperations;
4848
- exports.ɵq = PluginManager;
4849
- exports.ɵr = InternalNgxsExecutionStrategy;
4850
- exports.ɵs = ConfigValidator;
4851
- exports.ɵt = HostEnvironment;
4852
- exports.ɵw = ensureStoreMetadata;
4853
- exports.ɵx = getStoreMetadata;
4854
- exports.ɵy = ensureSelectorMetadata;
4855
- exports.ɵz = getSelectorMetadata;
4810
+ exports.ɵe = SELECTOR_META_KEY;
4811
+ exports.ɵf = NgxsConfig;
4812
+ exports.ɵg = mergeDeep;
4813
+ exports.ɵh = USER_PROVIDED_NGXS_EXECUTION_STRATEGY;
4814
+ exports.ɵi = NGXS_EXECUTION_STRATEGY;
4815
+ exports.ɵj = NgxsRootModule;
4816
+ exports.ɵk = StateFactory;
4817
+ exports.ɵl = InternalDispatchedActionResults;
4818
+ exports.ɵm = InternalDispatcher;
4819
+ exports.ɵn = StateContextFactory;
4820
+ exports.ɵo = InternalStateOperations;
4821
+ exports.ɵp = PluginManager;
4822
+ exports.ɵq = InternalNgxsExecutionStrategy;
4823
+ exports.ɵs = ensureStoreMetadata;
4824
+ exports.ɵt = getStoreMetadata;
4825
+ exports.ɵu = ensureSelectorMetadata;
4826
+ exports.ɵv = getSelectorMetadata;
4827
+ exports.ɵw = LifecycleStateManager;
4828
+ exports.ɵx = NgxsFeatureModule;
4856
4829
 
4857
4830
  Object.defineProperty(exports, '__esModule', { value: true });
4858
4831