@ngxs/store 3.8.0 → 3.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/bundles/ngxs-store-internals.umd.js +11 -7
  2. package/bundles/ngxs-store-internals.umd.js.map +1 -1
  3. package/bundles/ngxs-store.umd.js +222 -214
  4. package/bundles/ngxs-store.umd.js.map +1 -1
  5. package/esm2015/internals/initial-state.js +9 -6
  6. package/esm2015/internals/ngxs-bootstrapper.js +4 -3
  7. package/esm2015/src/actions-stream.js +7 -5
  8. package/esm2015/src/decorators/select/select-factory.js +4 -3
  9. package/esm2015/src/execution/internal-ngxs-execution-strategy.js +4 -3
  10. package/esm2015/src/internal/custom-rxjs-subjects.js +16 -5
  11. package/esm2015/src/internal/dispatcher.js +7 -5
  12. package/esm2015/src/internal/lifecycle-state-manager.js +4 -3
  13. package/esm2015/src/internal/state-context-factory.js +4 -3
  14. package/esm2015/src/internal/state-factory.js +24 -23
  15. package/esm2015/src/internal/state-operations.js +4 -4
  16. package/esm2015/src/internal/state-stream.js +4 -3
  17. package/esm2015/src/ivy/ivy-enabled-in-dev-mode.js +13 -6
  18. package/esm2015/src/module.js +6 -42
  19. package/esm2015/src/store.js +4 -3
  20. package/esm2015/src/symbols.js +10 -3
  21. package/fesm2015/ngxs-store-internals.js +11 -7
  22. package/fesm2015/ngxs-store-internals.js.map +1 -1
  23. package/fesm2015/ngxs-store.js +208 -200
  24. package/fesm2015/ngxs-store.js.map +1 -1
  25. package/internals/initial-state.d.ts +2 -2
  26. package/package.json +2 -2
  27. package/src/internal/custom-rxjs-subjects.d.ts +7 -2
  28. package/src/internal/state-factory.d.ts +10 -11
  29. package/src/internal/state-operations.d.ts +0 -1
  30. package/src/module.d.ts +0 -3
  31. package/src/symbols.d.ts +1 -0
@@ -352,6 +352,103 @@
352
352
  return typeof state === "function" ? receiver === state : state.has(receiver);
353
353
  }
354
354
 
355
+ /**
356
+ * Returns the type from an action instance/class.
357
+ * @ignore
358
+ */
359
+ function getActionTypeFromInstance(action) {
360
+ if (action.constructor && action.constructor.type) {
361
+ return action.constructor.type;
362
+ }
363
+ else {
364
+ return action.type;
365
+ }
366
+ }
367
+ /**
368
+ * Matches a action
369
+ * @ignore
370
+ */
371
+ function actionMatcher(action1) {
372
+ var type1 = getActionTypeFromInstance(action1);
373
+ return function (action2) {
374
+ return type1 === getActionTypeFromInstance(action2);
375
+ };
376
+ }
377
+ /**
378
+ * Set a deeply nested value. Example:
379
+ *
380
+ * setValue({ foo: { bar: { eat: false } } },
381
+ * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
382
+ *
383
+ * While it traverses it also creates new objects from top down.
384
+ *
385
+ * @ignore
386
+ */
387
+ var setValue = function (obj, prop, val) {
388
+ obj = Object.assign({}, obj);
389
+ var split = prop.split('.');
390
+ var lastIndex = split.length - 1;
391
+ split.reduce(function (acc, part, index) {
392
+ if (index === lastIndex) {
393
+ acc[part] = val;
394
+ }
395
+ else {
396
+ acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
397
+ }
398
+ return acc && acc[part];
399
+ }, obj);
400
+ return obj;
401
+ };
402
+ /**
403
+ * Get a deeply nested value. Example:
404
+ *
405
+ * getValue({ foo: bar: [] }, 'foo.bar') //=> []
406
+ *
407
+ * @ignore
408
+ */
409
+ var getValue = function (obj, prop) { return prop.split('.').reduce(function (acc, part) { return acc && acc[part]; }, obj); };
410
+ /**
411
+ * Simple object check.
412
+ *
413
+ * isObject({a:1}) //=> true
414
+ * isObject(1) //=> false
415
+ *
416
+ * @ignore
417
+ */
418
+ var isObject$1 = function (item) {
419
+ return item && typeof item === 'object' && !Array.isArray(item);
420
+ };
421
+ /**
422
+ * Deep merge two objects.
423
+ *
424
+ * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
425
+ *
426
+ * @param base base object onto which `sources` will be applied
427
+ */
428
+ var mergeDeep = function (base) {
429
+ var _a, _b;
430
+ var sources = [];
431
+ for (var _i = 1; _i < arguments.length; _i++) {
432
+ sources[_i - 1] = arguments[_i];
433
+ }
434
+ if (!sources.length)
435
+ return base;
436
+ var source = sources.shift();
437
+ if (isObject$1(base) && isObject$1(source)) {
438
+ for (var key in source) {
439
+ if (isObject$1(source[key])) {
440
+ if (!base[key])
441
+ Object.assign(base, (_a = {}, _a[key] = {}, _a));
442
+ mergeDeep(base[key], source[key]);
443
+ }
444
+ else {
445
+ Object.assign(base, (_b = {}, _b[key] = source[key], _b));
446
+ }
447
+ }
448
+ }
449
+ return mergeDeep.apply(void 0, __spreadArray([base], __read(sources)));
450
+ };
451
+
355
452
  function throwStateNameError(name) {
356
453
  throw new Error(name + " is not a valid state name. It needs to be a valid object property name.");
357
454
  }
@@ -444,6 +541,7 @@
444
541
  console.warn(getZoneWarningMessage());
445
542
  }
446
543
 
544
+ var ROOT_OPTIONS = new i0.InjectionToken('ROOT_OPTIONS');
447
545
  var ROOT_STATE_TOKEN = new i0.InjectionToken('ROOT_STATE_TOKEN');
448
546
  var FEATURE_STATE_TOKEN = new i0.InjectionToken('FEATURE_STATE_TOKEN');
449
547
  var NGXS_PLUGINS = new i0.InjectionToken('NGXS_PLUGINS');
@@ -477,9 +575,14 @@
477
575
  return NgxsConfig;
478
576
  }());
479
577
  /** @nocollapse */ NgxsConfig.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsConfig, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
480
- /** @nocollapse */ NgxsConfig.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsConfig });
578
+ /** @nocollapse */ NgxsConfig.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsConfig, providedIn: 'root', useFactory: function (options) { return mergeDeep(new NgxsConfig(), options); }, deps: [{ token: ROOT_OPTIONS }] });
481
579
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsConfig, decorators: [{
482
- type: i0.Injectable
580
+ type: i0.Injectable,
581
+ args: [{
582
+ providedIn: 'root',
583
+ useFactory: function (options) { return mergeDeep(new NgxsConfig(), options); },
584
+ deps: [ROOT_OPTIONS]
585
+ }]
483
586
  }], ctorParameters: function () { return []; } });
484
587
  /**
485
588
  * Represents a basic change from a previous to a new value for a single state instance.
@@ -777,107 +880,10 @@
777
880
  *
778
881
  * @ignore
779
882
  */
780
- function isObject$1(obj) {
883
+ function isObject(obj) {
781
884
  return (typeof obj === 'object' && obj !== null) || typeof obj === 'function';
782
885
  }
783
886
 
784
- /**
785
- * Returns the type from an action instance/class.
786
- * @ignore
787
- */
788
- function getActionTypeFromInstance(action) {
789
- if (action.constructor && action.constructor.type) {
790
- return action.constructor.type;
791
- }
792
- else {
793
- return action.type;
794
- }
795
- }
796
- /**
797
- * Matches a action
798
- * @ignore
799
- */
800
- function actionMatcher(action1) {
801
- var type1 = getActionTypeFromInstance(action1);
802
- return function (action2) {
803
- return type1 === getActionTypeFromInstance(action2);
804
- };
805
- }
806
- /**
807
- * Set a deeply nested value. Example:
808
- *
809
- * setValue({ foo: { bar: { eat: false } } },
810
- * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
811
- *
812
- * While it traverses it also creates new objects from top down.
813
- *
814
- * @ignore
815
- */
816
- var setValue = function (obj, prop, val) {
817
- obj = Object.assign({}, obj);
818
- var split = prop.split('.');
819
- var lastIndex = split.length - 1;
820
- split.reduce(function (acc, part, index) {
821
- if (index === lastIndex) {
822
- acc[part] = val;
823
- }
824
- else {
825
- acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
826
- }
827
- return acc && acc[part];
828
- }, obj);
829
- return obj;
830
- };
831
- /**
832
- * Get a deeply nested value. Example:
833
- *
834
- * getValue({ foo: bar: [] }, 'foo.bar') //=> []
835
- *
836
- * @ignore
837
- */
838
- var getValue = function (obj, prop) { return prop.split('.').reduce(function (acc, part) { return acc && acc[part]; }, obj); };
839
- /**
840
- * Simple object check.
841
- *
842
- * isObject({a:1}) //=> true
843
- * isObject(1) //=> false
844
- *
845
- * @ignore
846
- */
847
- var isObject = function (item) {
848
- return item && typeof item === 'object' && !Array.isArray(item);
849
- };
850
- /**
851
- * Deep merge two objects.
852
- *
853
- * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
854
- *
855
- * @param base base object onto which `sources` will be applied
856
- */
857
- var mergeDeep = function (base) {
858
- var _a, _b;
859
- var sources = [];
860
- for (var _i = 1; _i < arguments.length; _i++) {
861
- sources[_i - 1] = arguments[_i];
862
- }
863
- if (!sources.length)
864
- return base;
865
- var source = sources.shift();
866
- if (isObject(base) && isObject(source)) {
867
- for (var key in source) {
868
- if (isObject(source[key])) {
869
- if (!base[key])
870
- Object.assign(base, (_a = {}, _a[key] = {}, _a));
871
- mergeDeep(base[key], source[key]);
872
- }
873
- else {
874
- Object.assign(base, (_b = {}, _b[key] = source[key], _b));
875
- }
876
- }
877
- }
878
- return mergeDeep.apply(void 0, __spreadArray([base], __read(sources)));
879
- };
880
-
881
887
  /**
882
888
  * RxJS operator for selecting out specific actions.
883
889
  *
@@ -1038,15 +1044,22 @@
1038
1044
  * if another decorator was used, e.g. pipes).
1039
1045
  */
1040
1046
  function ensureStateClassIsInjectable(stateClass) {
1047
+ if (jit_hasInjectableAnnotation(stateClass) || aot_hasNgInjectableDef(stateClass)) {
1048
+ return;
1049
+ }
1050
+ console.warn(getUndecoratedStateInIvyWarningMessage(stateClass.name));
1051
+ }
1052
+ function aot_hasNgInjectableDef(stateClass) {
1041
1053
  // `ɵprov` is a static property added by the NGCC compiler. It always exists in
1042
1054
  // AOT mode because this property is added before runtime. If an application is running in
1043
1055
  // JIT mode then this property can be added by the `@Injectable()` decorator. The `@Injectable()`
1044
1056
  // decorator has to go after the `@State()` decorator, thus we prevent users from unwanted DI errors.
1045
- var ngInjectableDef = stateClass.ɵprov;
1046
- if (!ngInjectableDef) {
1047
- // Don't warn if Ivy is disabled or `ɵprov` exists on the class
1048
- console.warn(getUndecoratedStateInIvyWarningMessage(stateClass.name));
1049
- }
1057
+ return !!stateClass.ɵprov;
1058
+ }
1059
+ function jit_hasInjectableAnnotation(stateClass) {
1060
+ // `ɵprov` doesn't exist in JIT mode (for instance when running unit tests with Jest).
1061
+ var annotations = stateClass.__annotations__ || [];
1062
+ return annotations.some(function (annotation) { return (annotation === null || annotation === void 0 ? void 0 : annotation.ngMetadataName) === 'Injectable'; });
1050
1063
  }
1051
1064
 
1052
1065
  /**
@@ -1229,9 +1242,12 @@
1229
1242
  __extends(OrderedSubject, _super);
1230
1243
  function OrderedSubject() {
1231
1244
  var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
1232
- _this.next = orderedQueueOperation(function (value) { return _super.prototype.next.call(_this, value); });
1245
+ _this._orderedNext = orderedQueueOperation(function (value) { return _super.prototype.next.call(_this, value); });
1233
1246
  return _this;
1234
1247
  }
1248
+ OrderedSubject.prototype.next = function (value) {
1249
+ this._orderedNext(value);
1250
+ };
1235
1251
  return OrderedSubject;
1236
1252
  }(rxjs.Subject));
1237
1253
  /**
@@ -1251,11 +1267,19 @@
1251
1267
  */
1252
1268
  var OrderedBehaviorSubject = /** @class */ (function (_super) {
1253
1269
  __extends(OrderedBehaviorSubject, _super);
1254
- function OrderedBehaviorSubject() {
1255
- var _this = _super.apply(this, __spreadArray([], __read(arguments))) || this;
1256
- _this.next = orderedQueueOperation(function (value) { return _super.prototype.next.call(_this, value); });
1270
+ function OrderedBehaviorSubject(value) {
1271
+ var _this = _super.call(this, value) || this;
1272
+ _this._orderedNext = orderedQueueOperation(function (value) { return _super.prototype.next.call(_this, value); });
1273
+ _this._currentValue = value;
1257
1274
  return _this;
1258
1275
  }
1276
+ OrderedBehaviorSubject.prototype.getValue = function () {
1277
+ return this._currentValue;
1278
+ };
1279
+ OrderedBehaviorSubject.prototype.next = function (value) {
1280
+ this._currentValue = value;
1281
+ this._orderedNext(value);
1282
+ };
1259
1283
  return OrderedBehaviorSubject;
1260
1284
  }(rxjs.BehaviorSubject));
1261
1285
 
@@ -1272,9 +1296,10 @@
1272
1296
  return InternalNgxsExecutionStrategy;
1273
1297
  }());
1274
1298
  /** @nocollapse */ InternalNgxsExecutionStrategy.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalNgxsExecutionStrategy, deps: [{ token: NGXS_EXECUTION_STRATEGY }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1275
- /** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalNgxsExecutionStrategy });
1299
+ /** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalNgxsExecutionStrategy, providedIn: 'root' });
1276
1300
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalNgxsExecutionStrategy, decorators: [{
1277
- type: i0.Injectable
1301
+ type: i0.Injectable,
1302
+ args: [{ providedIn: 'root' }]
1278
1303
  }], ctorParameters: function () {
1279
1304
  return [{ type: undefined, decorators: [{
1280
1305
  type: i0.Inject,
@@ -1296,9 +1321,10 @@
1296
1321
  return InternalActions;
1297
1322
  }(OrderedSubject));
1298
1323
  /** @nocollapse */ InternalActions.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalActions, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
1299
- /** @nocollapse */ InternalActions.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalActions });
1324
+ /** @nocollapse */ InternalActions.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalActions, providedIn: 'root' });
1300
1325
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalActions, decorators: [{
1301
- type: i0.Injectable
1326
+ type: i0.Injectable,
1327
+ args: [{ providedIn: 'root' }]
1302
1328
  }] });
1303
1329
  /**
1304
1330
  * Action stream that is emitted anytime an action is dispatched.
@@ -1328,9 +1354,10 @@
1328
1354
  return Actions;
1329
1355
  }(rxjs.Observable));
1330
1356
  /** @nocollapse */ Actions.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Actions, deps: [{ token: InternalActions }, { token: InternalNgxsExecutionStrategy }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1331
- /** @nocollapse */ Actions.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Actions });
1357
+ /** @nocollapse */ Actions.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Actions, providedIn: 'root' });
1332
1358
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Actions, decorators: [{
1333
- type: i0.Injectable
1359
+ type: i0.Injectable,
1360
+ args: [{ providedIn: 'root' }]
1334
1361
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalNgxsExecutionStrategy }]; } });
1335
1362
 
1336
1363
  /**
@@ -1490,9 +1517,10 @@
1490
1517
  return StateStream;
1491
1518
  }(OrderedBehaviorSubject));
1492
1519
  /** @nocollapse */ StateStream.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateStream, deps: [], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1493
- /** @nocollapse */ StateStream.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateStream });
1520
+ /** @nocollapse */ StateStream.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateStream, providedIn: 'root' });
1494
1521
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateStream, decorators: [{
1495
- type: i0.Injectable
1522
+ type: i0.Injectable,
1523
+ args: [{ providedIn: 'root' }]
1496
1524
  }], ctorParameters: function () { return []; } });
1497
1525
 
1498
1526
  /**
@@ -1509,9 +1537,10 @@
1509
1537
  return InternalDispatchedActionResults;
1510
1538
  }(rxjs.Subject));
1511
1539
  /** @nocollapse */ InternalDispatchedActionResults.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatchedActionResults, deps: null, target: i0__namespace.ɵɵFactoryTarget.Injectable });
1512
- /** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatchedActionResults });
1540
+ /** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatchedActionResults, providedIn: 'root' });
1513
1541
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatchedActionResults, decorators: [{
1514
- type: i0.Injectable
1542
+ type: i0.Injectable,
1543
+ args: [{ providedIn: 'root' }]
1515
1544
  }] });
1516
1545
  var InternalDispatcher = /** @class */ (function () {
1517
1546
  function InternalDispatcher(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
@@ -1585,9 +1614,10 @@
1585
1614
  return InternalDispatcher;
1586
1615
  }());
1587
1616
  /** @nocollapse */ InternalDispatcher.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatcher, deps: [{ token: InternalActions }, { token: InternalDispatchedActionResults }, { token: PluginManager }, { token: StateStream }, { token: InternalNgxsExecutionStrategy }, { token: InternalErrorReporter }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1588
- /** @nocollapse */ InternalDispatcher.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatcher });
1617
+ /** @nocollapse */ InternalDispatcher.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatcher, providedIn: 'root' });
1589
1618
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatcher, decorators: [{
1590
- type: i0.Injectable
1619
+ type: i0.Injectable,
1620
+ args: [{ providedIn: 'root' }]
1591
1621
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalDispatchedActionResults }, { type: PluginManager }, { type: StateStream }, { type: InternalNgxsExecutionStrategy }, { type: InternalErrorReporter }]; } });
1592
1622
 
1593
1623
  function simplePatch(value) {
@@ -1630,7 +1660,6 @@
1630
1660
  };
1631
1661
 
1632
1662
  /**
1633
- * State Context factory class
1634
1663
  * @ignore
1635
1664
  */
1636
1665
  var InternalStateOperations = /** @class */ (function () {
@@ -1668,9 +1697,10 @@
1668
1697
  return InternalStateOperations;
1669
1698
  }());
1670
1699
  /** @nocollapse */ InternalStateOperations.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalStateOperations, deps: [{ token: StateStream }, { token: InternalDispatcher }, { token: NgxsConfig }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1671
- /** @nocollapse */ InternalStateOperations.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalStateOperations });
1700
+ /** @nocollapse */ InternalStateOperations.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalStateOperations, providedIn: 'root' });
1672
1701
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalStateOperations, decorators: [{
1673
- type: i0.Injectable
1702
+ type: i0.Injectable,
1703
+ args: [{ providedIn: 'root' }]
1674
1704
  }], ctorParameters: function () { return [{ type: StateStream }, { type: InternalDispatcher }, { type: NgxsConfig }]; } });
1675
1705
  function ensureStateAndActionsAreImmutable(root) {
1676
1706
  return {
@@ -1744,13 +1774,24 @@
1744
1774
  return StateContextFactory;
1745
1775
  }());
1746
1776
  /** @nocollapse */ StateContextFactory.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateContextFactory, deps: [{ token: InternalStateOperations }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
1747
- /** @nocollapse */ StateContextFactory.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateContextFactory });
1777
+ /** @nocollapse */ StateContextFactory.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateContextFactory, providedIn: 'root' });
1748
1778
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateContextFactory, decorators: [{
1749
- type: i0.Injectable
1779
+ type: i0.Injectable,
1780
+ args: [{ providedIn: 'root' }]
1750
1781
  }], ctorParameters: function () { return [{ type: InternalStateOperations }]; } });
1751
1782
 
1783
+ var NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
1752
1784
  /**
1753
- * State factory class
1785
+ * The `StateFactory` class adds root and feature states to the graph.
1786
+ * This extracts state names from state classes, checks if they already
1787
+ * exist in the global graph, throws errors if their names are invalid, etc.
1788
+ * See its constructor, state factories inject state factories that are
1789
+ * parent-level providers. This is required to get feature states from the
1790
+ * injector on the same level.
1791
+ *
1792
+ * The `NgxsModule.forFeature(...)` returns `providers: [StateFactory, ...states]`.
1793
+ * The `StateFactory` is initialized on the feature level and goes through `...states`
1794
+ * to get them from the injector through `injector.get(state)`.
1754
1795
  * @ignore
1755
1796
  */
1756
1797
  var StateFactory = /** @class */ (function () {
@@ -1828,7 +1869,7 @@
1828
1869
  if (Array.isArray(defaults)) {
1829
1870
  value = defaults.slice();
1830
1871
  }
1831
- else if (isObject$1(defaults)) {
1872
+ else if (isObject(defaults)) {
1832
1873
  value = Object.assign({}, defaults);
1833
1874
  }
1834
1875
  else if (defaults === undefined) {
@@ -1840,18 +1881,15 @@
1840
1881
  return value;
1841
1882
  };
1842
1883
  StateFactory.prototype.ngOnDestroy = function () {
1843
- // This is being non-null asserted since `_actionsSubscrition` is
1844
- // initialized within the constructor.
1845
- this._actionsSubscription.unsubscribe();
1884
+ var _a;
1885
+ (_a = this._actionsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1846
1886
  };
1847
1887
  /**
1848
1888
  * Add a new state to the global defs.
1849
1889
  */
1850
1890
  StateFactory.prototype.add = function (stateClasses) {
1851
- var e_1, _a;
1852
- // Caretaker note: we have still left the `typeof` condition in order to avoid
1853
- // creating a breaking change for projects that still use the View Engine.
1854
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
1891
+ var e_1, _b;
1892
+ if (NG_DEV_MODE) {
1855
1893
  StoreValidators.checkThatStateClassesHaveBeenDecorated(stateClasses);
1856
1894
  }
1857
1895
  var newStates = this.addToStatesMap(stateClasses).newStates;
@@ -1896,7 +1934,7 @@
1896
1934
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
1897
1935
  finally {
1898
1936
  try {
1899
- if (sortedStates_1_1 && !sortedStates_1_1.done && (_a = sortedStates_1.return)) _a.call(sortedStates_1);
1937
+ if (sortedStates_1_1 && !sortedStates_1_1.done && (_b = sortedStates_1.return)) _b.call(sortedStates_1);
1900
1938
  }
1901
1939
  finally { if (e_1) throw e_1.error; }
1902
1940
  }
@@ -1911,13 +1949,14 @@
1911
1949
  var defaults = mappedStores.reduce(function (result, mappedStore) { return setValue(result, mappedStore.path, mappedStore.defaults); }, {});
1912
1950
  return { defaults: defaults, states: mappedStores };
1913
1951
  };
1914
- /**
1915
- * Bind the actions to the handlers
1916
- */
1917
1952
  StateFactory.prototype.connectActionHandlers = function () {
1918
1953
  var _this = this;
1919
- if (this._actionsSubscription !== null)
1954
+ // Note: We have to connect actions only once when the `StateFactory`
1955
+ // is being created for the first time. This checks if we're in
1956
+ // a child state factory and the parent state factory already exists.
1957
+ if (this._parentFactory || this._actionsSubscription !== null) {
1920
1958
  return;
1959
+ }
1921
1960
  var dispatched$ = new rxjs.Subject();
1922
1961
  this._actionsSubscription = this._actions
1923
1962
  .pipe(operators.filter(function (ctx) { return ctx.status === "DISPATCHED"; } /* Dispatched */), operators.mergeMap(function (ctx) {
@@ -1931,15 +1970,15 @@
1931
1970
  * Invoke actions on the states.
1932
1971
  */
1933
1972
  StateFactory.prototype.invokeActions = function (dispatched$, action) {
1934
- var e_2, _a, e_3, _b;
1973
+ var e_2, _b, e_3, _c;
1935
1974
  var type = getActionTypeFromInstance(action);
1936
1975
  var results = [];
1937
1976
  // Determines whether the dispatched action has been handled, this is assigned
1938
1977
  // to `true` within the below `for` loop if any `actionMetas` has been found.
1939
1978
  var actionHasBeenHandled = false;
1940
1979
  try {
1941
- for (var _c = __values(this.states), _d = _c.next(); !_d.done; _d = _c.next()) {
1942
- var metadata = _d.value;
1980
+ for (var _d = __values(this.states), _e = _d.next(); !_e.done; _e = _d.next()) {
1981
+ var metadata = _e.value;
1943
1982
  var actionMetas = metadata.actions[type];
1944
1983
  if (actionMetas) {
1945
1984
  try {
@@ -1988,7 +2027,7 @@
1988
2027
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
1989
2028
  finally {
1990
2029
  try {
1991
- if (actionMetas_1_1 && !actionMetas_1_1.done && (_b = actionMetas_1.return)) _b.call(actionMetas_1);
2030
+ if (actionMetas_1_1 && !actionMetas_1_1.done && (_c = actionMetas_1.return)) _c.call(actionMetas_1);
1992
2031
  }
1993
2032
  finally { if (e_3) throw e_3.error; }
1994
2033
  }
@@ -1998,13 +2037,13 @@
1998
2037
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
1999
2038
  finally {
2000
2039
  try {
2001
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
2040
+ if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
2002
2041
  }
2003
2042
  finally { if (e_2) throw e_2.error; }
2004
2043
  }
2005
2044
  // The `NgxsUnhandledActionsLogger` is a tree-shakable class which functions
2006
2045
  // only during development.
2007
- if ((typeof ngDevMode === 'undefined' || ngDevMode) && !actionHasBeenHandled) {
2046
+ if (NG_DEV_MODE && !actionHasBeenHandled) {
2008
2047
  var unhandledActionsLogger = this._injector.get(NgxsUnhandledActionsLogger, null);
2009
2048
  // The `NgxsUnhandledActionsLogger` will not be resolved by the injector if the
2010
2049
  // `NgxsDevelopmentModule` is not provided. It's enough to check whether the `injector.get`
@@ -2019,16 +2058,14 @@
2019
2058
  return rxjs.forkJoin(results);
2020
2059
  };
2021
2060
  StateFactory.prototype.addToStatesMap = function (stateClasses) {
2022
- var e_4, _a;
2061
+ var e_4, _b;
2023
2062
  var newStates = [];
2024
2063
  var statesMap = this.statesByName;
2025
2064
  try {
2026
2065
  for (var stateClasses_1 = __values(stateClasses), stateClasses_1_1 = stateClasses_1.next(); !stateClasses_1_1.done; stateClasses_1_1 = stateClasses_1.next()) {
2027
2066
  var stateClass = stateClasses_1_1.value;
2028
2067
  var stateName = getStoreMetadata$1(stateClass).name;
2029
- // Caretaker note: we have still left the `typeof` condition in order to avoid
2030
- // creating a breaking change for projects that still use the View Engine.
2031
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
2068
+ if (NG_DEV_MODE) {
2032
2069
  StoreValidators.checkThatStateNameIsUnique(stateName, stateClass, statesMap);
2033
2070
  }
2034
2071
  var unmountedState = !statesMap[stateName];
@@ -2041,7 +2078,7 @@
2041
2078
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
2042
2079
  finally {
2043
2080
  try {
2044
- if (stateClasses_1_1 && !stateClasses_1_1.done && (_a = stateClasses_1.return)) _a.call(stateClasses_1);
2081
+ if (stateClasses_1_1 && !stateClasses_1_1.done && (_b = stateClasses_1.return)) _b.call(stateClasses_1);
2045
2082
  }
2046
2083
  finally { if (e_4) throw e_4.error; }
2047
2084
  }
@@ -2054,15 +2091,10 @@
2054
2091
  // We will need to come up with an alternative in v4 because this is used by many plugins
2055
2092
  meta.path = path;
2056
2093
  };
2057
- /**
2058
- * @description
2059
- * the method checks if the state has already been added to the tree
2060
- * and completed the life cycle
2061
- * @param name
2062
- * @param path
2063
- */
2064
2094
  StateFactory.prototype.hasBeenMountedAndBootstrapped = function (name, path) {
2065
2095
  var valueIsBootstrappedInInitialState = getValue(this._initialState, path) !== undefined;
2096
+ // This checks whether a state has been already added to the global graph and
2097
+ // its lifecycle is in 'bootstrapped' state.
2066
2098
  return this.statesByName[name] && valueIsBootstrappedInInitialState;
2067
2099
  };
2068
2100
  return StateFactory;
@@ -2243,9 +2275,10 @@
2243
2275
  return Store;
2244
2276
  }());
2245
2277
  /** @nocollapse */ Store.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Store, deps: [{ token: StateStream }, { token: InternalStateOperations }, { token: NgxsConfig }, { token: InternalNgxsExecutionStrategy }, { token: StateFactory }, { token: i5.INITIAL_STATE_TOKEN, optional: true }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2246
- /** @nocollapse */ Store.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Store });
2278
+ /** @nocollapse */ Store.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Store, providedIn: 'root' });
2247
2279
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Store, decorators: [{
2248
- type: i0.Injectable
2280
+ type: i0.Injectable,
2281
+ args: [{ providedIn: 'root' }]
2249
2282
  }], ctorParameters: function () {
2250
2283
  return [{ type: StateStream }, { type: InternalStateOperations }, { type: NgxsConfig }, { type: InternalNgxsExecutionStrategy }, { type: StateFactory }, { type: undefined, decorators: [{
2251
2284
  type: i0.Optional
@@ -2255,6 +2288,30 @@
2255
2288
  }] }];
2256
2289
  } });
2257
2290
 
2291
+ /**
2292
+ * Allows the select decorator to get access to the DI store, this is used internally
2293
+ * in `@Select` decorator.
2294
+ */
2295
+ var SelectFactory = /** @class */ (function () {
2296
+ function SelectFactory(store, config) {
2297
+ SelectFactory.store = store;
2298
+ SelectFactory.config = config;
2299
+ }
2300
+ SelectFactory.prototype.ngOnDestroy = function () {
2301
+ SelectFactory.store = null;
2302
+ SelectFactory.config = null;
2303
+ };
2304
+ return SelectFactory;
2305
+ }());
2306
+ SelectFactory.store = null;
2307
+ SelectFactory.config = null;
2308
+ /** @nocollapse */ SelectFactory.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SelectFactory, deps: [{ token: Store }, { token: NgxsConfig }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2309
+ /** @nocollapse */ SelectFactory.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SelectFactory, providedIn: 'root' });
2310
+ i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SelectFactory, decorators: [{
2311
+ type: i0.Injectable,
2312
+ args: [{ providedIn: 'root' }]
2313
+ }], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
2314
+
2258
2315
  var LifecycleStateManager = /** @class */ (function () {
2259
2316
  function LifecycleStateManager(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
2260
2317
  this._store = _store;
@@ -2341,34 +2398,12 @@
2341
2398
  return LifecycleStateManager;
2342
2399
  }());
2343
2400
  /** @nocollapse */ LifecycleStateManager.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: LifecycleStateManager, deps: [{ token: Store }, { token: InternalErrorReporter }, { token: InternalStateOperations }, { token: StateContextFactory }, { token: i5__namespace.NgxsBootstrapper }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2344
- /** @nocollapse */ LifecycleStateManager.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: LifecycleStateManager });
2401
+ /** @nocollapse */ LifecycleStateManager.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: LifecycleStateManager, providedIn: 'root' });
2345
2402
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: LifecycleStateManager, decorators: [{
2346
- type: i0.Injectable
2403
+ type: i0.Injectable,
2404
+ args: [{ providedIn: 'root' }]
2347
2405
  }], ctorParameters: function () { return [{ type: Store }, { type: InternalErrorReporter }, { type: InternalStateOperations }, { type: StateContextFactory }, { type: i5__namespace.NgxsBootstrapper }]; } });
2348
2406
 
2349
- /**
2350
- * Allows the select decorator to get access to the DI store, this is used internally
2351
- * in `@Select` decorator.
2352
- */
2353
- var SelectFactory = /** @class */ (function () {
2354
- function SelectFactory(store, config) {
2355
- SelectFactory.store = store;
2356
- SelectFactory.config = config;
2357
- }
2358
- SelectFactory.prototype.ngOnDestroy = function () {
2359
- SelectFactory.store = null;
2360
- SelectFactory.config = null;
2361
- };
2362
- return SelectFactory;
2363
- }());
2364
- SelectFactory.store = null;
2365
- SelectFactory.config = null;
2366
- /** @nocollapse */ SelectFactory.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SelectFactory, deps: [{ token: Store }, { token: NgxsConfig }], target: i0__namespace.ɵɵFactoryTarget.Injectable });
2367
- /** @nocollapse */ SelectFactory.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SelectFactory });
2368
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SelectFactory, decorators: [{
2369
- type: i0.Injectable
2370
- }], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
2371
-
2372
2407
  /**
2373
2408
  * Root module
2374
2409
  * @ignore
@@ -2454,18 +2489,6 @@
2454
2489
  ngModule: NgxsRootModule,
2455
2490
  providers: __spreadArray(__spreadArray([
2456
2491
  StateFactory,
2457
- StateContextFactory,
2458
- Actions,
2459
- InternalActions,
2460
- i5.NgxsBootstrapper,
2461
- LifecycleStateManager,
2462
- InternalDispatcher,
2463
- InternalDispatchedActionResults,
2464
- InternalStateOperations,
2465
- InternalNgxsExecutionStrategy,
2466
- Store,
2467
- StateStream,
2468
- SelectFactory,
2469
2492
  PluginManager
2470
2493
  ], __read(states)), __read(NgxsModule.ngxsTokenProviders(states, options)))
2471
2494
  };
@@ -2478,6 +2501,7 @@
2478
2501
  return {
2479
2502
  ngModule: NgxsFeatureModule,
2480
2503
  providers: __spreadArray(__spreadArray([
2504
+ // This is required on the feature level, see comments in `state-factory.ts`.
2481
2505
  StateFactory,
2482
2506
  PluginManager
2483
2507
  ], __read(states)), [
@@ -2500,24 +2524,15 @@
2500
2524
  useValue: states
2501
2525
  },
2502
2526
  {
2503
- provide: NgxsModule.ROOT_OPTIONS,
2527
+ provide: ROOT_OPTIONS,
2504
2528
  useValue: options
2505
2529
  },
2506
- {
2507
- provide: NgxsConfig,
2508
- useFactory: NgxsModule.ngxsConfigFactory,
2509
- deps: [NgxsModule.ROOT_OPTIONS]
2510
- },
2511
2530
  {
2512
2531
  provide: i0.APP_BOOTSTRAP_LISTENER,
2513
2532
  useFactory: NgxsModule.appBootstrapListenerFactory,
2514
2533
  multi: true,
2515
2534
  deps: [i5.NgxsBootstrapper]
2516
2535
  },
2517
- {
2518
- provide: i5.INITIAL_STATE_TOKEN,
2519
- useFactory: NgxsModule.getInitialState
2520
- },
2521
2536
  {
2522
2537
  provide: i5["ɵNGXS_STATE_CONTEXT_FACTORY"],
2523
2538
  useExisting: StateContextFactory
@@ -2528,18 +2543,11 @@
2528
2543
  }
2529
2544
  ];
2530
2545
  };
2531
- NgxsModule.ngxsConfigFactory = function (options) {
2532
- return mergeDeep(new NgxsConfig(), options);
2533
- };
2534
2546
  NgxsModule.appBootstrapListenerFactory = function (bootstrapper) {
2535
2547
  return function () { return bootstrapper.bootstrap(); };
2536
2548
  };
2537
- NgxsModule.getInitialState = function () {
2538
- return i5.InitialState.pop();
2539
- };
2540
2549
  return NgxsModule;
2541
2550
  }());
2542
- NgxsModule.ROOT_OPTIONS = new i0.InjectionToken('ROOT_OPTIONS');
2543
2551
  /** @nocollapse */ NgxsModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule });
2544
2552
  /** @nocollapse */ NgxsModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsModule });
2545
2553
  /** @nocollapse */ NgxsModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsModule });