@ngxs/store 3.8.0-dev.master-a827bb0 → 3.8.0-dev.master-4f8f372

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.
@@ -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
  *
@@ -1290,9 +1296,10 @@
1290
1296
  return InternalNgxsExecutionStrategy;
1291
1297
  }());
1292
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 });
1293
- /** @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' });
1294
1300
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalNgxsExecutionStrategy, decorators: [{
1295
- type: i0.Injectable
1301
+ type: i0.Injectable,
1302
+ args: [{ providedIn: 'root' }]
1296
1303
  }], ctorParameters: function () {
1297
1304
  return [{ type: undefined, decorators: [{
1298
1305
  type: i0.Inject,
@@ -1314,9 +1321,10 @@
1314
1321
  return InternalActions;
1315
1322
  }(OrderedSubject));
1316
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 });
1317
- /** @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' });
1318
1325
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalActions, decorators: [{
1319
- type: i0.Injectable
1326
+ type: i0.Injectable,
1327
+ args: [{ providedIn: 'root' }]
1320
1328
  }] });
1321
1329
  /**
1322
1330
  * Action stream that is emitted anytime an action is dispatched.
@@ -1346,9 +1354,10 @@
1346
1354
  return Actions;
1347
1355
  }(rxjs.Observable));
1348
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 });
1349
- /** @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' });
1350
1358
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Actions, decorators: [{
1351
- type: i0.Injectable
1359
+ type: i0.Injectable,
1360
+ args: [{ providedIn: 'root' }]
1352
1361
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalNgxsExecutionStrategy }]; } });
1353
1362
 
1354
1363
  /**
@@ -1508,9 +1517,10 @@
1508
1517
  return StateStream;
1509
1518
  }(OrderedBehaviorSubject));
1510
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 });
1511
- /** @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' });
1512
1521
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateStream, decorators: [{
1513
- type: i0.Injectable
1522
+ type: i0.Injectable,
1523
+ args: [{ providedIn: 'root' }]
1514
1524
  }], ctorParameters: function () { return []; } });
1515
1525
 
1516
1526
  /**
@@ -1527,9 +1537,10 @@
1527
1537
  return InternalDispatchedActionResults;
1528
1538
  }(rxjs.Subject));
1529
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 });
1530
- /** @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' });
1531
1541
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatchedActionResults, decorators: [{
1532
- type: i0.Injectable
1542
+ type: i0.Injectable,
1543
+ args: [{ providedIn: 'root' }]
1533
1544
  }] });
1534
1545
  var InternalDispatcher = /** @class */ (function () {
1535
1546
  function InternalDispatcher(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
@@ -1603,9 +1614,10 @@
1603
1614
  return InternalDispatcher;
1604
1615
  }());
1605
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 });
1606
- /** @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' });
1607
1618
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalDispatcher, decorators: [{
1608
- type: i0.Injectable
1619
+ type: i0.Injectable,
1620
+ args: [{ providedIn: 'root' }]
1609
1621
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalDispatchedActionResults }, { type: PluginManager }, { type: StateStream }, { type: InternalNgxsExecutionStrategy }, { type: InternalErrorReporter }]; } });
1610
1622
 
1611
1623
  function simplePatch(value) {
@@ -1648,7 +1660,6 @@
1648
1660
  };
1649
1661
 
1650
1662
  /**
1651
- * State Context factory class
1652
1663
  * @ignore
1653
1664
  */
1654
1665
  var InternalStateOperations = /** @class */ (function () {
@@ -1686,9 +1697,10 @@
1686
1697
  return InternalStateOperations;
1687
1698
  }());
1688
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 });
1689
- /** @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' });
1690
1701
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: InternalStateOperations, decorators: [{
1691
- type: i0.Injectable
1702
+ type: i0.Injectable,
1703
+ args: [{ providedIn: 'root' }]
1692
1704
  }], ctorParameters: function () { return [{ type: StateStream }, { type: InternalDispatcher }, { type: NgxsConfig }]; } });
1693
1705
  function ensureStateAndActionsAreImmutable(root) {
1694
1706
  return {
@@ -1762,13 +1774,24 @@
1762
1774
  return StateContextFactory;
1763
1775
  }());
1764
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 });
1765
- /** @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' });
1766
1778
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: StateContextFactory, decorators: [{
1767
- type: i0.Injectable
1779
+ type: i0.Injectable,
1780
+ args: [{ providedIn: 'root' }]
1768
1781
  }], ctorParameters: function () { return [{ type: InternalStateOperations }]; } });
1769
1782
 
1783
+ var NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
1770
1784
  /**
1771
- * 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)`.
1772
1795
  * @ignore
1773
1796
  */
1774
1797
  var StateFactory = /** @class */ (function () {
@@ -1846,7 +1869,7 @@
1846
1869
  if (Array.isArray(defaults)) {
1847
1870
  value = defaults.slice();
1848
1871
  }
1849
- else if (isObject$1(defaults)) {
1872
+ else if (isObject(defaults)) {
1850
1873
  value = Object.assign({}, defaults);
1851
1874
  }
1852
1875
  else if (defaults === undefined) {
@@ -1858,18 +1881,15 @@
1858
1881
  return value;
1859
1882
  };
1860
1883
  StateFactory.prototype.ngOnDestroy = function () {
1861
- // This is being non-null asserted since `_actionsSubscrition` is
1862
- // initialized within the constructor.
1863
- this._actionsSubscription.unsubscribe();
1884
+ var _a;
1885
+ (_a = this._actionsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1864
1886
  };
1865
1887
  /**
1866
1888
  * Add a new state to the global defs.
1867
1889
  */
1868
1890
  StateFactory.prototype.add = function (stateClasses) {
1869
- var e_1, _a;
1870
- // Caretaker note: we have still left the `typeof` condition in order to avoid
1871
- // creating a breaking change for projects that still use the View Engine.
1872
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
1891
+ var e_1, _b;
1892
+ if (NG_DEV_MODE) {
1873
1893
  StoreValidators.checkThatStateClassesHaveBeenDecorated(stateClasses);
1874
1894
  }
1875
1895
  var newStates = this.addToStatesMap(stateClasses).newStates;
@@ -1914,7 +1934,7 @@
1914
1934
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
1915
1935
  finally {
1916
1936
  try {
1917
- 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);
1918
1938
  }
1919
1939
  finally { if (e_1) throw e_1.error; }
1920
1940
  }
@@ -1929,13 +1949,14 @@
1929
1949
  var defaults = mappedStores.reduce(function (result, mappedStore) { return setValue(result, mappedStore.path, mappedStore.defaults); }, {});
1930
1950
  return { defaults: defaults, states: mappedStores };
1931
1951
  };
1932
- /**
1933
- * Bind the actions to the handlers
1934
- */
1935
1952
  StateFactory.prototype.connectActionHandlers = function () {
1936
1953
  var _this = this;
1937
- 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) {
1938
1958
  return;
1959
+ }
1939
1960
  var dispatched$ = new rxjs.Subject();
1940
1961
  this._actionsSubscription = this._actions
1941
1962
  .pipe(operators.filter(function (ctx) { return ctx.status === "DISPATCHED"; } /* Dispatched */), operators.mergeMap(function (ctx) {
@@ -1949,15 +1970,15 @@
1949
1970
  * Invoke actions on the states.
1950
1971
  */
1951
1972
  StateFactory.prototype.invokeActions = function (dispatched$, action) {
1952
- var e_2, _a, e_3, _b;
1973
+ var e_2, _b, e_3, _c;
1953
1974
  var type = getActionTypeFromInstance(action);
1954
1975
  var results = [];
1955
1976
  // Determines whether the dispatched action has been handled, this is assigned
1956
1977
  // to `true` within the below `for` loop if any `actionMetas` has been found.
1957
1978
  var actionHasBeenHandled = false;
1958
1979
  try {
1959
- for (var _c = __values(this.states), _d = _c.next(); !_d.done; _d = _c.next()) {
1960
- var metadata = _d.value;
1980
+ for (var _d = __values(this.states), _e = _d.next(); !_e.done; _e = _d.next()) {
1981
+ var metadata = _e.value;
1961
1982
  var actionMetas = metadata.actions[type];
1962
1983
  if (actionMetas) {
1963
1984
  try {
@@ -2006,7 +2027,7 @@
2006
2027
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
2007
2028
  finally {
2008
2029
  try {
2009
- 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);
2010
2031
  }
2011
2032
  finally { if (e_3) throw e_3.error; }
2012
2033
  }
@@ -2016,13 +2037,13 @@
2016
2037
  catch (e_2_1) { e_2 = { error: e_2_1 }; }
2017
2038
  finally {
2018
2039
  try {
2019
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
2040
+ if (_e && !_e.done && (_b = _d.return)) _b.call(_d);
2020
2041
  }
2021
2042
  finally { if (e_2) throw e_2.error; }
2022
2043
  }
2023
2044
  // The `NgxsUnhandledActionsLogger` is a tree-shakable class which functions
2024
2045
  // only during development.
2025
- if ((typeof ngDevMode === 'undefined' || ngDevMode) && !actionHasBeenHandled) {
2046
+ if (NG_DEV_MODE && !actionHasBeenHandled) {
2026
2047
  var unhandledActionsLogger = this._injector.get(NgxsUnhandledActionsLogger, null);
2027
2048
  // The `NgxsUnhandledActionsLogger` will not be resolved by the injector if the
2028
2049
  // `NgxsDevelopmentModule` is not provided. It's enough to check whether the `injector.get`
@@ -2037,16 +2058,14 @@
2037
2058
  return rxjs.forkJoin(results);
2038
2059
  };
2039
2060
  StateFactory.prototype.addToStatesMap = function (stateClasses) {
2040
- var e_4, _a;
2061
+ var e_4, _b;
2041
2062
  var newStates = [];
2042
2063
  var statesMap = this.statesByName;
2043
2064
  try {
2044
2065
  for (var stateClasses_1 = __values(stateClasses), stateClasses_1_1 = stateClasses_1.next(); !stateClasses_1_1.done; stateClasses_1_1 = stateClasses_1.next()) {
2045
2066
  var stateClass = stateClasses_1_1.value;
2046
2067
  var stateName = getStoreMetadata$1(stateClass).name;
2047
- // Caretaker note: we have still left the `typeof` condition in order to avoid
2048
- // creating a breaking change for projects that still use the View Engine.
2049
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
2068
+ if (NG_DEV_MODE) {
2050
2069
  StoreValidators.checkThatStateNameIsUnique(stateName, stateClass, statesMap);
2051
2070
  }
2052
2071
  var unmountedState = !statesMap[stateName];
@@ -2059,7 +2078,7 @@
2059
2078
  catch (e_4_1) { e_4 = { error: e_4_1 }; }
2060
2079
  finally {
2061
2080
  try {
2062
- 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);
2063
2082
  }
2064
2083
  finally { if (e_4) throw e_4.error; }
2065
2084
  }
@@ -2072,15 +2091,10 @@
2072
2091
  // We will need to come up with an alternative in v4 because this is used by many plugins
2073
2092
  meta.path = path;
2074
2093
  };
2075
- /**
2076
- * @description
2077
- * the method checks if the state has already been added to the tree
2078
- * and completed the life cycle
2079
- * @param name
2080
- * @param path
2081
- */
2082
2094
  StateFactory.prototype.hasBeenMountedAndBootstrapped = function (name, path) {
2083
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.
2084
2098
  return this.statesByName[name] && valueIsBootstrappedInInitialState;
2085
2099
  };
2086
2100
  return StateFactory;
@@ -2261,9 +2275,10 @@
2261
2275
  return Store;
2262
2276
  }());
2263
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 });
2264
- /** @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' });
2265
2279
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: Store, decorators: [{
2266
- type: i0.Injectable
2280
+ type: i0.Injectable,
2281
+ args: [{ providedIn: 'root' }]
2267
2282
  }], ctorParameters: function () {
2268
2283
  return [{ type: StateStream }, { type: InternalStateOperations }, { type: NgxsConfig }, { type: InternalNgxsExecutionStrategy }, { type: StateFactory }, { type: undefined, decorators: [{
2269
2284
  type: i0.Optional
@@ -2273,6 +2288,30 @@
2273
2288
  }] }];
2274
2289
  } });
2275
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
+
2276
2315
  var LifecycleStateManager = /** @class */ (function () {
2277
2316
  function LifecycleStateManager(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
2278
2317
  this._store = _store;
@@ -2359,34 +2398,12 @@
2359
2398
  return LifecycleStateManager;
2360
2399
  }());
2361
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 });
2362
- /** @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' });
2363
2402
  i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: LifecycleStateManager, decorators: [{
2364
- type: i0.Injectable
2403
+ type: i0.Injectable,
2404
+ args: [{ providedIn: 'root' }]
2365
2405
  }], ctorParameters: function () { return [{ type: Store }, { type: InternalErrorReporter }, { type: InternalStateOperations }, { type: StateContextFactory }, { type: i5__namespace.NgxsBootstrapper }]; } });
2366
2406
 
2367
- /**
2368
- * Allows the select decorator to get access to the DI store, this is used internally
2369
- * in `@Select` decorator.
2370
- */
2371
- var SelectFactory = /** @class */ (function () {
2372
- function SelectFactory(store, config) {
2373
- SelectFactory.store = store;
2374
- SelectFactory.config = config;
2375
- }
2376
- SelectFactory.prototype.ngOnDestroy = function () {
2377
- SelectFactory.store = null;
2378
- SelectFactory.config = null;
2379
- };
2380
- return SelectFactory;
2381
- }());
2382
- SelectFactory.store = null;
2383
- SelectFactory.config = null;
2384
- /** @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 });
2385
- /** @nocollapse */ SelectFactory.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SelectFactory });
2386
- i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: SelectFactory, decorators: [{
2387
- type: i0.Injectable
2388
- }], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
2389
-
2390
2407
  /**
2391
2408
  * Root module
2392
2409
  * @ignore
@@ -2472,18 +2489,6 @@
2472
2489
  ngModule: NgxsRootModule,
2473
2490
  providers: __spreadArray(__spreadArray([
2474
2491
  StateFactory,
2475
- StateContextFactory,
2476
- Actions,
2477
- InternalActions,
2478
- i5.NgxsBootstrapper,
2479
- LifecycleStateManager,
2480
- InternalDispatcher,
2481
- InternalDispatchedActionResults,
2482
- InternalStateOperations,
2483
- InternalNgxsExecutionStrategy,
2484
- Store,
2485
- StateStream,
2486
- SelectFactory,
2487
2492
  PluginManager
2488
2493
  ], __read(states)), __read(NgxsModule.ngxsTokenProviders(states, options)))
2489
2494
  };
@@ -2496,6 +2501,7 @@
2496
2501
  return {
2497
2502
  ngModule: NgxsFeatureModule,
2498
2503
  providers: __spreadArray(__spreadArray([
2504
+ // This is required on the feature level, see comments in `state-factory.ts`.
2499
2505
  StateFactory,
2500
2506
  PluginManager
2501
2507
  ], __read(states)), [
@@ -2518,24 +2524,15 @@
2518
2524
  useValue: states
2519
2525
  },
2520
2526
  {
2521
- provide: NgxsModule.ROOT_OPTIONS,
2527
+ provide: ROOT_OPTIONS,
2522
2528
  useValue: options
2523
2529
  },
2524
- {
2525
- provide: NgxsConfig,
2526
- useFactory: NgxsModule.ngxsConfigFactory,
2527
- deps: [NgxsModule.ROOT_OPTIONS]
2528
- },
2529
2530
  {
2530
2531
  provide: i0.APP_BOOTSTRAP_LISTENER,
2531
2532
  useFactory: NgxsModule.appBootstrapListenerFactory,
2532
2533
  multi: true,
2533
2534
  deps: [i5.NgxsBootstrapper]
2534
2535
  },
2535
- {
2536
- provide: i5.INITIAL_STATE_TOKEN,
2537
- useFactory: NgxsModule.getInitialState
2538
- },
2539
2536
  {
2540
2537
  provide: i5["ɵNGXS_STATE_CONTEXT_FACTORY"],
2541
2538
  useExisting: StateContextFactory
@@ -2546,18 +2543,11 @@
2546
2543
  }
2547
2544
  ];
2548
2545
  };
2549
- NgxsModule.ngxsConfigFactory = function (options) {
2550
- return mergeDeep(new NgxsConfig(), options);
2551
- };
2552
2546
  NgxsModule.appBootstrapListenerFactory = function (bootstrapper) {
2553
2547
  return function () { return bootstrapper.bootstrap(); };
2554
2548
  };
2555
- NgxsModule.getInitialState = function () {
2556
- return i5.InitialState.pop();
2557
- };
2558
2549
  return NgxsModule;
2559
2550
  }());
2560
- NgxsModule.ROOT_OPTIONS = new i0.InjectionToken('ROOT_OPTIONS');
2561
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 });
2562
2552
  /** @nocollapse */ NgxsModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsModule });
2563
2553
  /** @nocollapse */ NgxsModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0__namespace, type: NgxsModule });