@ngxs/store 3.7.5 → 3.7.6

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.
@@ -1,8 +1,8 @@
1
- import { NgZone, Injectable, Inject, PLATFORM_ID, defineInjectable, inject, InjectionToken, INJECTOR, ɵglobal, Optional, SkipSelf, ErrorHandler, Injector, ɵivyEnabled, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
1
+ import { NgZone, Injectable, Inject, PLATFORM_ID, defineInjectable, inject, InjectionToken, INJECTOR, ɵglobal, ErrorHandler, Injector, Optional, SkipSelf, ɵivyEnabled, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
2
2
  import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, NGXS_STATE_CONTEXT_FACTORY, NGXS_STATE_FACTORY, InitialState } from '@ngxs/store/internals';
3
3
  import { isPlatformServer } from '@angular/common';
4
- import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, queueScheduler } from 'rxjs';
5
- import { filter, map, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, tap, observeOn, distinctUntilChanged } from 'rxjs/operators';
4
+ import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable, queueScheduler } from 'rxjs';
5
+ import { filter, map, share, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, observeOn, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
6
6
 
7
7
  /**
8
8
  * @fileoverview added by tsickle
@@ -477,149 +477,6 @@ if (false) {
477
477
  NgxsExecutionStrategy.prototype.leave = function (func) { };
478
478
  }
479
479
 
480
- /**
481
- * @fileoverview added by tsickle
482
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
483
- */
484
- /**
485
- * Returns the type from an action instance/class.
486
- * @ignore
487
- * @param {?} action
488
- * @return {?}
489
- */
490
- function getActionTypeFromInstance(action) {
491
- if (action.constructor && action.constructor.type) {
492
- return action.constructor.type;
493
- }
494
- else {
495
- return action.type;
496
- }
497
- }
498
- /**
499
- * Matches a action
500
- * @ignore
501
- * @param {?} action1
502
- * @return {?}
503
- */
504
- function actionMatcher(action1) {
505
- /** @type {?} */
506
- const type1 = getActionTypeFromInstance(action1);
507
- return (/**
508
- * @param {?} action2
509
- * @return {?}
510
- */
511
- function (action2) {
512
- return type1 === getActionTypeFromInstance(action2);
513
- });
514
- }
515
- /**
516
- * Set a deeply nested value. Example:
517
- *
518
- * setValue({ foo: { bar: { eat: false } } },
519
- * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
520
- *
521
- * While it traverses it also creates new objects from top down.
522
- *
523
- * @ignore
524
- * @type {?}
525
- */
526
- const setValue = (/**
527
- * @param {?} obj
528
- * @param {?} prop
529
- * @param {?} val
530
- * @return {?}
531
- */
532
- (obj, prop, val) => {
533
- obj = Object.assign({}, obj);
534
- /** @type {?} */
535
- const split = prop.split('.');
536
- /** @type {?} */
537
- const lastIndex = split.length - 1;
538
- split.reduce((/**
539
- * @param {?} acc
540
- * @param {?} part
541
- * @param {?} index
542
- * @return {?}
543
- */
544
- (acc, part, index) => {
545
- if (index === lastIndex) {
546
- acc[part] = val;
547
- }
548
- else {
549
- acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
550
- }
551
- return acc && acc[part];
552
- }), obj);
553
- return obj;
554
- });
555
- /**
556
- * Get a deeply nested value. Example:
557
- *
558
- * getValue({ foo: bar: [] }, 'foo.bar') //=> []
559
- *
560
- * @ignore
561
- * @type {?}
562
- */
563
- const getValue = (/**
564
- * @param {?} obj
565
- * @param {?} prop
566
- * @return {?}
567
- */
568
- (obj, prop) => prop.split('.').reduce((/**
569
- * @param {?} acc
570
- * @param {?} part
571
- * @return {?}
572
- */
573
- (acc, part) => acc && acc[part]), obj));
574
- /**
575
- * Simple object check.
576
- *
577
- * isObject({a:1}) //=> true
578
- * isObject(1) //=> false
579
- *
580
- * @ignore
581
- * @type {?}
582
- */
583
- const isObject = (/**
584
- * @param {?} item
585
- * @return {?}
586
- */
587
- (item) => {
588
- return item && typeof item === 'object' && !Array.isArray(item);
589
- });
590
- /**
591
- * Deep merge two objects.
592
- *
593
- * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
594
- *
595
- * \@param base base object onto which `sources` will be applied
596
- * @type {?}
597
- */
598
- const mergeDeep = (/**
599
- * @param {?} base
600
- * @param {...?} sources
601
- * @return {?}
602
- */
603
- (base, ...sources) => {
604
- if (!sources.length)
605
- return base;
606
- /** @type {?} */
607
- const source = sources.shift();
608
- if (isObject(base) && isObject(source)) {
609
- for (const key in source) {
610
- if (isObject(source[key])) {
611
- if (!base[key])
612
- Object.assign(base, { [key]: {} });
613
- mergeDeep(base[key], source[key]);
614
- }
615
- else {
616
- Object.assign(base, { [key]: source[key] });
617
- }
618
- }
619
- }
620
- return mergeDeep(base, ...sources);
621
- });
622
-
623
480
  /**
624
481
  * @fileoverview added by tsickle
625
482
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -744,17 +601,6 @@ if (false) {
744
601
  /** @type {?} */
745
602
  StatesAndDefaults.prototype.states;
746
603
  }
747
- /**
748
- * @record
749
- * @template T
750
- */
751
- function RootStateDiff() { }
752
- if (false) {
753
- /** @type {?} */
754
- RootStateDiff.prototype.currentAppState;
755
- /** @type {?} */
756
- RootStateDiff.prototype.newAppState;
757
- }
758
604
  /**
759
605
  * Ensures metadata is attached to the class and returns it.
760
606
  *
@@ -1094,22 +940,152 @@ function topologicalSort(graph) {
1094
940
  * @param {?} obj
1095
941
  * @return {?}
1096
942
  */
1097
- function isObject$1(obj) {
943
+ function isObject(obj) {
1098
944
  return (typeof obj === 'object' && obj !== null) || typeof obj === 'function';
1099
945
  }
946
+
1100
947
  /**
1101
- * @template T
1102
- * @param {?} mappedStore
1103
- * @param {?} diff
948
+ * @fileoverview added by tsickle
949
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
950
+ */
951
+ /**
952
+ * Returns the type from an action instance/class.
953
+ * @ignore
954
+ * @param {?} action
1104
955
  * @return {?}
1105
956
  */
1106
- function getStateDiffChanges(mappedStore, diff) {
1107
- /** @type {?} */
1108
- const previousValue = getValue(diff.currentAppState, mappedStore.path);
957
+ function getActionTypeFromInstance(action) {
958
+ if (action.constructor && action.constructor.type) {
959
+ return action.constructor.type;
960
+ }
961
+ else {
962
+ return action.type;
963
+ }
964
+ }
965
+ /**
966
+ * Matches a action
967
+ * @ignore
968
+ * @param {?} action1
969
+ * @return {?}
970
+ */
971
+ function actionMatcher(action1) {
1109
972
  /** @type {?} */
1110
- const currentValue = getValue(diff.newAppState, mappedStore.path);
1111
- return new NgxsSimpleChange(previousValue, currentValue, !mappedStore.isInitialised);
973
+ const type1 = getActionTypeFromInstance(action1);
974
+ return (/**
975
+ * @param {?} action2
976
+ * @return {?}
977
+ */
978
+ function (action2) {
979
+ return type1 === getActionTypeFromInstance(action2);
980
+ });
1112
981
  }
982
+ /**
983
+ * Set a deeply nested value. Example:
984
+ *
985
+ * setValue({ foo: { bar: { eat: false } } },
986
+ * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
987
+ *
988
+ * While it traverses it also creates new objects from top down.
989
+ *
990
+ * @ignore
991
+ * @type {?}
992
+ */
993
+ const setValue = (/**
994
+ * @param {?} obj
995
+ * @param {?} prop
996
+ * @param {?} val
997
+ * @return {?}
998
+ */
999
+ (obj, prop, val) => {
1000
+ obj = Object.assign({}, obj);
1001
+ /** @type {?} */
1002
+ const split = prop.split('.');
1003
+ /** @type {?} */
1004
+ const lastIndex = split.length - 1;
1005
+ split.reduce((/**
1006
+ * @param {?} acc
1007
+ * @param {?} part
1008
+ * @param {?} index
1009
+ * @return {?}
1010
+ */
1011
+ (acc, part, index) => {
1012
+ if (index === lastIndex) {
1013
+ acc[part] = val;
1014
+ }
1015
+ else {
1016
+ acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
1017
+ }
1018
+ return acc && acc[part];
1019
+ }), obj);
1020
+ return obj;
1021
+ });
1022
+ /**
1023
+ * Get a deeply nested value. Example:
1024
+ *
1025
+ * getValue({ foo: bar: [] }, 'foo.bar') //=> []
1026
+ *
1027
+ * @ignore
1028
+ * @type {?}
1029
+ */
1030
+ const getValue = (/**
1031
+ * @param {?} obj
1032
+ * @param {?} prop
1033
+ * @return {?}
1034
+ */
1035
+ (obj, prop) => prop.split('.').reduce((/**
1036
+ * @param {?} acc
1037
+ * @param {?} part
1038
+ * @return {?}
1039
+ */
1040
+ (acc, part) => acc && acc[part]), obj));
1041
+ /**
1042
+ * Simple object check.
1043
+ *
1044
+ * isObject({a:1}) //=> true
1045
+ * isObject(1) //=> false
1046
+ *
1047
+ * @ignore
1048
+ * @type {?}
1049
+ */
1050
+ const isObject$1 = (/**
1051
+ * @param {?} item
1052
+ * @return {?}
1053
+ */
1054
+ (item) => {
1055
+ return item && typeof item === 'object' && !Array.isArray(item);
1056
+ });
1057
+ /**
1058
+ * Deep merge two objects.
1059
+ *
1060
+ * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
1061
+ *
1062
+ * \@param base base object onto which `sources` will be applied
1063
+ * @type {?}
1064
+ */
1065
+ const mergeDeep = (/**
1066
+ * @param {?} base
1067
+ * @param {...?} sources
1068
+ * @return {?}
1069
+ */
1070
+ (base, ...sources) => {
1071
+ if (!sources.length)
1072
+ return base;
1073
+ /** @type {?} */
1074
+ const source = sources.shift();
1075
+ if (isObject$1(base) && isObject$1(source)) {
1076
+ for (const key in source) {
1077
+ if (isObject$1(source[key])) {
1078
+ if (!base[key])
1079
+ Object.assign(base, { [key]: {} });
1080
+ mergeDeep(base[key], source[key]);
1081
+ }
1082
+ else {
1083
+ Object.assign(base, { [key]: source[key] });
1084
+ }
1085
+ }
1086
+ }
1087
+ return mergeDeep(base, ...sources);
1088
+ });
1113
1089
 
1114
1090
  /**
1115
1091
  * @fileoverview added by tsickle
@@ -1481,6 +1457,12 @@ if (false) {
1481
1457
  * Internal Action stream that is emitted anytime an action is dispatched.
1482
1458
  */
1483
1459
  class InternalActions extends OrderedSubject {
1460
+ /**
1461
+ * @return {?}
1462
+ */
1463
+ ngOnDestroy() {
1464
+ this.complete();
1465
+ }
1484
1466
  }
1485
1467
  InternalActions.decorators = [
1486
1468
  { type: Injectable }
@@ -1498,15 +1480,20 @@ class Actions extends Observable {
1498
1480
  * @param {?} internalExecutionStrategy
1499
1481
  */
1500
1482
  constructor(internalActions$, internalExecutionStrategy) {
1483
+ /** @type {?} */
1484
+ const sharedInternalActions$ = internalActions$.pipe(leaveNgxs(internalExecutionStrategy),
1485
+ // The `InternalActions` subject emits outside of the Angular zone.
1486
+ // We have to re-enter the Angular zone for any incoming consumer.
1487
+ // The `share()` operator reduces the number of change detections.
1488
+ // This would call leave only once for any stream emission across all active subscribers.
1489
+ share());
1501
1490
  super((/**
1502
1491
  * @param {?} observer
1503
1492
  * @return {?}
1504
1493
  */
1505
1494
  observer => {
1506
1495
  /** @type {?} */
1507
- const childSubscription = internalActions$
1508
- .pipe(leaveNgxs(internalExecutionStrategy))
1509
- .subscribe({
1496
+ const childSubscription = sharedInternalActions$.subscribe({
1510
1497
  next: (/**
1511
1498
  * @param {?} ctx
1512
1499
  * @return {?}
@@ -1576,8 +1563,122 @@ const compose = (/**
1576
1563
  * @param {...?} nextArgs
1577
1564
  * @return {?}
1578
1565
  */
1579
- (...nextArgs) => compose(funcs)(...nextArgs)));
1580
- }));
1566
+ (...nextArgs) => compose(funcs)(...nextArgs)));
1567
+ }));
1568
+
1569
+ /**
1570
+ * @fileoverview added by tsickle
1571
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1572
+ */
1573
+ /**
1574
+ * This operator is used for piping the observable result
1575
+ * from the `dispatch()`. It has a "smart" error handling
1576
+ * strategy that allows us to decide whether we propagate
1577
+ * errors to Angular's `ErrorHandler` or enable users to
1578
+ * handle them manually. We consider following cases:
1579
+ * 1) `store.dispatch()` (no subscribe) -> call `handleError()`
1580
+ * 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
1581
+ * 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
1582
+ * 4) `toPromise()` without `catch` -> do `handleError()`
1583
+ * 5) `toPromise()` with `catch` -> don't `handleError()`
1584
+ * @template T
1585
+ * @param {?} internalErrorReporter
1586
+ * @param {?} ngxsExecutionStrategy
1587
+ * @return {?}
1588
+ */
1589
+ function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
1590
+ return (/**
1591
+ * @param {?} source
1592
+ * @return {?}
1593
+ */
1594
+ (source) => {
1595
+ /** @type {?} */
1596
+ let subscribed = false;
1597
+ source.subscribe({
1598
+ error: (/**
1599
+ * @param {?} error
1600
+ * @return {?}
1601
+ */
1602
+ error => {
1603
+ // Do not trigger change detection for a microtask. This depends on the execution
1604
+ // strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
1605
+ // leaves the Angular zone.
1606
+ ngxsExecutionStrategy.enter((/**
1607
+ * @return {?}
1608
+ */
1609
+ () => Promise.resolve().then((/**
1610
+ * @return {?}
1611
+ */
1612
+ () => {
1613
+ if (!subscribed) {
1614
+ ngxsExecutionStrategy.leave((/**
1615
+ * @return {?}
1616
+ */
1617
+ () => internalErrorReporter.reportErrorSafely(error)));
1618
+ }
1619
+ }))));
1620
+ })
1621
+ });
1622
+ return new Observable((/**
1623
+ * @param {?} subscriber
1624
+ * @return {?}
1625
+ */
1626
+ subscriber => {
1627
+ subscribed = true;
1628
+ return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
1629
+ }));
1630
+ });
1631
+ }
1632
+ class InternalErrorReporter {
1633
+ /**
1634
+ * @param {?} _injector
1635
+ */
1636
+ constructor(_injector) {
1637
+ this._injector = _injector;
1638
+ /**
1639
+ * Will be set lazily to be backward compatible.
1640
+ */
1641
+ this._errorHandler = (/** @type {?} */ (null));
1642
+ }
1643
+ /**
1644
+ * @param {?} error
1645
+ * @return {?}
1646
+ */
1647
+ reportErrorSafely(error) {
1648
+ if (this._errorHandler === null) {
1649
+ this._errorHandler = this._injector.get(ErrorHandler);
1650
+ }
1651
+ // The `try-catch` is used to avoid handling the error twice. Suppose we call
1652
+ // `handleError` which re-throws the error internally. The re-thrown error will
1653
+ // be caught by zone.js which will then get to the `zone.onError.emit()` and the
1654
+ // `onError` subscriber will call `handleError` again.
1655
+ try {
1656
+ this._errorHandler.handleError(error);
1657
+ }
1658
+ catch (_a) { }
1659
+ }
1660
+ }
1661
+ InternalErrorReporter.decorators = [
1662
+ { type: Injectable, args: [{ providedIn: 'root' },] }
1663
+ ];
1664
+ /** @nocollapse */
1665
+ InternalErrorReporter.ctorParameters = () => [
1666
+ { type: Injector }
1667
+ ];
1668
+ /** @nocollapse */ InternalErrorReporter.ngInjectableDef = defineInjectable({ factory: function InternalErrorReporter_Factory() { return new InternalErrorReporter(inject(INJECTOR)); }, token: InternalErrorReporter, providedIn: "root" });
1669
+ if (false) {
1670
+ /**
1671
+ * Will be set lazily to be backward compatible.
1672
+ * @type {?}
1673
+ * @private
1674
+ */
1675
+ InternalErrorReporter.prototype._errorHandler;
1676
+ /**
1677
+ * @type {?}
1678
+ * @private
1679
+ */
1680
+ InternalErrorReporter.prototype._injector;
1681
+ }
1581
1682
 
1582
1683
  /**
1583
1684
  * @fileoverview added by tsickle
@@ -1692,20 +1793,20 @@ InternalDispatchedActionResults.decorators = [
1692
1793
  ];
1693
1794
  class InternalDispatcher {
1694
1795
  /**
1695
- * @param {?} _injector
1696
1796
  * @param {?} _actions
1697
1797
  * @param {?} _actionResults
1698
1798
  * @param {?} _pluginManager
1699
1799
  * @param {?} _stateStream
1700
1800
  * @param {?} _ngxsExecutionStrategy
1801
+ * @param {?} _internalErrorReporter
1701
1802
  */
1702
- constructor(_injector, _actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy) {
1703
- this._injector = _injector;
1803
+ constructor(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
1704
1804
  this._actions = _actions;
1705
1805
  this._actionResults = _actionResults;
1706
1806
  this._pluginManager = _pluginManager;
1707
1807
  this._stateStream = _stateStream;
1708
1808
  this._ngxsExecutionStrategy = _ngxsExecutionStrategy;
1809
+ this._internalErrorReporter = _internalErrorReporter;
1709
1810
  }
1710
1811
  /**
1711
1812
  * Dispatches event(s).
@@ -1718,24 +1819,7 @@ class InternalDispatcher {
1718
1819
  * @return {?}
1719
1820
  */
1720
1821
  () => this.dispatchByEvents(actionOrActions)));
1721
- result.subscribe({
1722
- error: (/**
1723
- * @param {?} error
1724
- * @return {?}
1725
- */
1726
- error => this._ngxsExecutionStrategy.leave((/**
1727
- * @return {?}
1728
- */
1729
- () => {
1730
- try {
1731
- // Retrieve lazily to avoid cyclic dependency exception
1732
- this._errorHandler = this._errorHandler || this._injector.get(ErrorHandler);
1733
- this._errorHandler.handleError(error);
1734
- }
1735
- catch (_a) { }
1736
- })))
1737
- });
1738
- return result.pipe(leaveNgxs(this._ngxsExecutionStrategy));
1822
+ return result.pipe(ngxsErrorHandler(this._internalErrorReporter, this._ngxsExecutionStrategy));
1739
1823
  }
1740
1824
  /**
1741
1825
  * @private
@@ -1839,24 +1923,14 @@ InternalDispatcher.decorators = [
1839
1923
  ];
1840
1924
  /** @nocollapse */
1841
1925
  InternalDispatcher.ctorParameters = () => [
1842
- { type: Injector },
1843
1926
  { type: InternalActions },
1844
1927
  { type: InternalDispatchedActionResults },
1845
1928
  { type: PluginManager },
1846
1929
  { type: StateStream },
1847
- { type: InternalNgxsExecutionStrategy }
1930
+ { type: InternalNgxsExecutionStrategy },
1931
+ { type: InternalErrorReporter }
1848
1932
  ];
1849
1933
  if (false) {
1850
- /**
1851
- * @type {?}
1852
- * @private
1853
- */
1854
- InternalDispatcher.prototype._errorHandler;
1855
- /**
1856
- * @type {?}
1857
- * @private
1858
- */
1859
- InternalDispatcher.prototype._injector;
1860
1934
  /**
1861
1935
  * @type {?}
1862
1936
  * @private
@@ -1882,6 +1956,11 @@ if (false) {
1882
1956
  * @private
1883
1957
  */
1884
1958
  InternalDispatcher.prototype._ngxsExecutionStrategy;
1959
+ /**
1960
+ * @type {?}
1961
+ * @private
1962
+ */
1963
+ InternalDispatcher.prototype._internalErrorReporter;
1885
1964
  }
1886
1965
 
1887
1966
  /**
@@ -2109,16 +2188,6 @@ class StateContextFactory {
2109
2188
  function setStateValue(currentAppState, newValue) {
2110
2189
  /** @type {?} */
2111
2190
  const newAppState = setValue(currentAppState, mappedStore.path, newValue);
2112
- /** @type {?} */
2113
- const instance = mappedStore.instance;
2114
- if (instance.ngxsOnChanges) {
2115
- /** @type {?} */
2116
- const change = getStateDiffChanges(mappedStore, {
2117
- currentAppState,
2118
- newAppState
2119
- });
2120
- instance.ngxsOnChanges(change);
2121
- }
2122
2191
  root.setState(newAppState);
2123
2192
  return newAppState;
2124
2193
  // In doing this refactoring I noticed that there is a 'bug' where the
@@ -2401,7 +2470,7 @@ class StateFactory {
2401
2470
  if (Array.isArray(defaults)) {
2402
2471
  value = defaults.slice();
2403
2472
  }
2404
- else if (isObject$1(defaults)) {
2473
+ else if (isObject(defaults)) {
2405
2474
  value = Object.assign({}, defaults);
2406
2475
  }
2407
2476
  else if (defaults === undefined) {
@@ -2560,7 +2629,7 @@ class StateFactory {
2560
2629
  if (result instanceof Promise) {
2561
2630
  result = from(result);
2562
2631
  }
2563
- if (result instanceof Observable) {
2632
+ if (isObservable(result)) {
2564
2633
  // If this observable has been completed w/o emitting
2565
2634
  // any value then we wouldn't want to complete the whole chain
2566
2635
  // of actions. Since if any observable completes then
@@ -2577,7 +2646,7 @@ class StateFactory {
2577
2646
  if (value instanceof Promise) {
2578
2647
  return from(value);
2579
2648
  }
2580
- if (value instanceof Observable) {
2649
+ if (isObservable(value)) {
2581
2650
  return value;
2582
2651
  }
2583
2652
  return of(value);
@@ -2731,129 +2800,6 @@ if (false) {
2731
2800
  StateFactory.prototype._initialState;
2732
2801
  }
2733
2802
 
2734
- /**
2735
- * @fileoverview added by tsickle
2736
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2737
- */
2738
- class LifecycleStateManager {
2739
- /**
2740
- * @param {?} internalStateOperations
2741
- * @param {?} stateContextFactory
2742
- * @param {?} bootstrapper
2743
- */
2744
- constructor(internalStateOperations, stateContextFactory, bootstrapper) {
2745
- this.internalStateOperations = internalStateOperations;
2746
- this.stateContextFactory = stateContextFactory;
2747
- this.bootstrapper = bootstrapper;
2748
- }
2749
- /**
2750
- * @template T
2751
- * @param {?} action
2752
- * @param {?} results
2753
- * @return {?}
2754
- */
2755
- ngxsBootstrap(action, results) {
2756
- this.internalStateOperations
2757
- .getRootStateOperations()
2758
- .dispatch(action)
2759
- .pipe(filter((/**
2760
- * @return {?}
2761
- */
2762
- () => !!results)), tap((/**
2763
- * @return {?}
2764
- */
2765
- () => this.invokeInit((/** @type {?} */ (results)).states))), mergeMap((/**
2766
- * @return {?}
2767
- */
2768
- () => this.bootstrapper.appBootstrapped$)), filter((/**
2769
- * @param {?} appBootstrapped
2770
- * @return {?}
2771
- */
2772
- appBootstrapped => !!appBootstrapped)))
2773
- .subscribe((/**
2774
- * @return {?}
2775
- */
2776
- () => this.invokeBootstrap((/** @type {?} */ (results)).states)));
2777
- }
2778
- /**
2779
- * Invoke the init function on the states.
2780
- * @param {?} mappedStores
2781
- * @return {?}
2782
- */
2783
- invokeInit(mappedStores) {
2784
- for (const mappedStore of mappedStores) {
2785
- /** @type {?} */
2786
- const instance = mappedStore.instance;
2787
- if (instance.ngxsOnChanges) {
2788
- /** @type {?} */
2789
- const currentAppState = {};
2790
- /** @type {?} */
2791
- const newAppState = this.internalStateOperations
2792
- .getRootStateOperations()
2793
- .getState();
2794
- /** @type {?} */
2795
- const firstDiffChange = getStateDiffChanges(mappedStore, {
2796
- currentAppState,
2797
- newAppState
2798
- });
2799
- instance.ngxsOnChanges(firstDiffChange);
2800
- }
2801
- if (instance.ngxsOnInit) {
2802
- instance.ngxsOnInit(this.getStateContext(mappedStore));
2803
- }
2804
- mappedStore.isInitialised = true;
2805
- }
2806
- }
2807
- /**
2808
- * Invoke the bootstrap function on the states.
2809
- * @param {?} mappedStores
2810
- * @return {?}
2811
- */
2812
- invokeBootstrap(mappedStores) {
2813
- for (const mappedStore of mappedStores) {
2814
- /** @type {?} */
2815
- const instance = mappedStore.instance;
2816
- if (instance.ngxsAfterBootstrap) {
2817
- instance.ngxsAfterBootstrap(this.getStateContext(mappedStore));
2818
- }
2819
- }
2820
- }
2821
- /**
2822
- * @private
2823
- * @param {?} mappedStore
2824
- * @return {?}
2825
- */
2826
- getStateContext(mappedStore) {
2827
- return this.stateContextFactory.createStateContext(mappedStore);
2828
- }
2829
- }
2830
- LifecycleStateManager.decorators = [
2831
- { type: Injectable }
2832
- ];
2833
- /** @nocollapse */
2834
- LifecycleStateManager.ctorParameters = () => [
2835
- { type: InternalStateOperations },
2836
- { type: StateContextFactory },
2837
- { type: NgxsBootstrapper }
2838
- ];
2839
- if (false) {
2840
- /**
2841
- * @type {?}
2842
- * @private
2843
- */
2844
- LifecycleStateManager.prototype.internalStateOperations;
2845
- /**
2846
- * @type {?}
2847
- * @private
2848
- */
2849
- LifecycleStateManager.prototype.stateContextFactory;
2850
- /**
2851
- * @type {?}
2852
- * @private
2853
- */
2854
- LifecycleStateManager.prototype.bootstrapper;
2855
- }
2856
-
2857
2803
  /**
2858
2804
  * @fileoverview added by tsickle
2859
2805
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -3251,6 +3197,172 @@ if (false) {
3251
3197
  Store.prototype._stateFactory;
3252
3198
  }
3253
3199
 
3200
+ /**
3201
+ * @fileoverview added by tsickle
3202
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3203
+ */
3204
+ class LifecycleStateManager {
3205
+ /**
3206
+ * @param {?} _store
3207
+ * @param {?} _internalErrorReporter
3208
+ * @param {?} _internalStateOperations
3209
+ * @param {?} _stateContextFactory
3210
+ * @param {?} _bootstrapper
3211
+ */
3212
+ constructor(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3213
+ this._store = _store;
3214
+ this._internalErrorReporter = _internalErrorReporter;
3215
+ this._internalStateOperations = _internalStateOperations;
3216
+ this._stateContextFactory = _stateContextFactory;
3217
+ this._bootstrapper = _bootstrapper;
3218
+ this._destroy$ = new Subject();
3219
+ }
3220
+ /**
3221
+ * @return {?}
3222
+ */
3223
+ ngOnDestroy() {
3224
+ this._destroy$.next();
3225
+ }
3226
+ /**
3227
+ * @template T
3228
+ * @param {?} action
3229
+ * @param {?} results
3230
+ * @return {?}
3231
+ */
3232
+ ngxsBootstrap(action, results) {
3233
+ this._internalStateOperations
3234
+ .getRootStateOperations()
3235
+ .dispatch(action)
3236
+ .pipe(filter((/**
3237
+ * @return {?}
3238
+ */
3239
+ () => !!results)), tap((/**
3240
+ * @return {?}
3241
+ */
3242
+ () => this._invokeInitOnStates((/** @type {?} */ (results)).states))), mergeMap((/**
3243
+ * @return {?}
3244
+ */
3245
+ () => this._bootstrapper.appBootstrapped$)), filter((/**
3246
+ * @param {?} appBootstrapped
3247
+ * @return {?}
3248
+ */
3249
+ appBootstrapped => !!appBootstrapped)), catchError((/**
3250
+ * @param {?} error
3251
+ * @return {?}
3252
+ */
3253
+ error => {
3254
+ // The `SafeSubscriber` (which is used by most RxJS operators) re-throws
3255
+ // errors asynchronously (`setTimeout(() => { throw error })`). This might
3256
+ // break existing user's code or unit tests. We catch the error manually to
3257
+ // be backward compatible with the old behavior.
3258
+ this._internalErrorReporter.reportErrorSafely(error);
3259
+ return EMPTY;
3260
+ })), takeUntil(this._destroy$))
3261
+ .subscribe((/**
3262
+ * @return {?}
3263
+ */
3264
+ () => this._invokeBootstrapOnStates((/** @type {?} */ (results)).states)));
3265
+ }
3266
+ /**
3267
+ * @private
3268
+ * @param {?} mappedStores
3269
+ * @return {?}
3270
+ */
3271
+ _invokeInitOnStates(mappedStores) {
3272
+ for (const mappedStore of mappedStores) {
3273
+ /** @type {?} */
3274
+ const instance = mappedStore.instance;
3275
+ if (instance.ngxsOnChanges) {
3276
+ this._store
3277
+ .select((/**
3278
+ * @param {?} state
3279
+ * @return {?}
3280
+ */
3281
+ state => getValue(state, mappedStore.path)))
3282
+ .pipe(startWith(undefined), pairwise(), takeUntil(this._destroy$))
3283
+ .subscribe((/**
3284
+ * @param {?} __0
3285
+ * @return {?}
3286
+ */
3287
+ ([previousValue, currentValue]) => {
3288
+ /** @type {?} */
3289
+ const change = new NgxsSimpleChange(previousValue, currentValue, !mappedStore.isInitialised);
3290
+ (/** @type {?} */ (instance.ngxsOnChanges))(change);
3291
+ }));
3292
+ }
3293
+ if (instance.ngxsOnInit) {
3294
+ instance.ngxsOnInit(this._getStateContext(mappedStore));
3295
+ }
3296
+ mappedStore.isInitialised = true;
3297
+ }
3298
+ }
3299
+ /**
3300
+ * @private
3301
+ * @param {?} mappedStores
3302
+ * @return {?}
3303
+ */
3304
+ _invokeBootstrapOnStates(mappedStores) {
3305
+ for (const mappedStore of mappedStores) {
3306
+ /** @type {?} */
3307
+ const instance = mappedStore.instance;
3308
+ if (instance.ngxsAfterBootstrap) {
3309
+ instance.ngxsAfterBootstrap(this._getStateContext(mappedStore));
3310
+ }
3311
+ }
3312
+ }
3313
+ /**
3314
+ * @private
3315
+ * @param {?} mappedStore
3316
+ * @return {?}
3317
+ */
3318
+ _getStateContext(mappedStore) {
3319
+ return this._stateContextFactory.createStateContext(mappedStore);
3320
+ }
3321
+ }
3322
+ LifecycleStateManager.decorators = [
3323
+ { type: Injectable }
3324
+ ];
3325
+ /** @nocollapse */
3326
+ LifecycleStateManager.ctorParameters = () => [
3327
+ { type: Store },
3328
+ { type: InternalErrorReporter },
3329
+ { type: InternalStateOperations },
3330
+ { type: StateContextFactory },
3331
+ { type: NgxsBootstrapper }
3332
+ ];
3333
+ if (false) {
3334
+ /**
3335
+ * @type {?}
3336
+ * @private
3337
+ */
3338
+ LifecycleStateManager.prototype._destroy$;
3339
+ /**
3340
+ * @type {?}
3341
+ * @private
3342
+ */
3343
+ LifecycleStateManager.prototype._store;
3344
+ /**
3345
+ * @type {?}
3346
+ * @private
3347
+ */
3348
+ LifecycleStateManager.prototype._internalErrorReporter;
3349
+ /**
3350
+ * @type {?}
3351
+ * @private
3352
+ */
3353
+ LifecycleStateManager.prototype._internalStateOperations;
3354
+ /**
3355
+ * @type {?}
3356
+ * @private
3357
+ */
3358
+ LifecycleStateManager.prototype._stateContextFactory;
3359
+ /**
3360
+ * @type {?}
3361
+ * @private
3362
+ */
3363
+ LifecycleStateManager.prototype._bootstrapper;
3364
+ }
3365
+
3254
3366
  /**
3255
3367
  * @fileoverview added by tsickle
3256
3368
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -3998,5 +4110,5 @@ if (false) {
3998
4110
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3999
4111
  */
4000
4112
 
4001
- export { Action, Actions, InitState, NGXS_PLUGINS, NgxsModule, NgxsSimpleChange, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, StateStream, StateToken, Store, UpdateState, actionMatcher, createSelector, ensureSelectorMetadata$1 as ensureSelectorMetadata, ensureStoreMetadata$1 as ensureStoreMetadata, getActionTypeFromInstance, getSelectorMetadata$1 as getSelectorMetadata, getStoreMetadata$1 as getStoreMetadata, getValue, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, setValue, OrderedSubject as ɵa, InternalActions as ɵb, ROOT_STATE_TOKEN as ɵc, FEATURE_STATE_TOKEN as ɵd, SELECTOR_META_KEY as ɵe, NgxsConfig as ɵf, mergeDeep as ɵg, USER_PROVIDED_NGXS_EXECUTION_STRATEGY as ɵh, NGXS_EXECUTION_STRATEGY as ɵi, NgxsRootModule as ɵj, StateFactory as ɵk, InternalDispatchedActionResults as ɵl, InternalDispatcher as ɵm, StateContextFactory as ɵn, InternalStateOperations as ɵo, PluginManager as ɵp, InternalNgxsExecutionStrategy as ɵq, SelectFactory as ɵr, ensureStoreMetadata as ɵt, getStoreMetadata as ɵu, ensureSelectorMetadata as ɵv, getSelectorMetadata as ɵw, LifecycleStateManager as ɵx, NgxsFeatureModule as ɵy };
4113
+ export { Action, Actions, InitState, NGXS_PLUGINS, NgxsModule, NgxsSimpleChange, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, StateStream, StateToken, Store, UpdateState, actionMatcher, createSelector, ensureSelectorMetadata$1 as ensureSelectorMetadata, ensureStoreMetadata$1 as ensureStoreMetadata, getActionTypeFromInstance, getSelectorMetadata$1 as getSelectorMetadata, getStoreMetadata$1 as getStoreMetadata, getValue, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, setValue, OrderedSubject as ɵa, InternalActions as ɵb, ROOT_STATE_TOKEN as ɵc, FEATURE_STATE_TOKEN as ɵd, SELECTOR_META_KEY as ɵe, NgxsConfig as ɵf, mergeDeep as ɵg, USER_PROVIDED_NGXS_EXECUTION_STRATEGY as ɵh, NGXS_EXECUTION_STRATEGY as ɵi, NgxsRootModule as ɵj, StateFactory as ɵk, InternalDispatchedActionResults as ɵl, InternalDispatcher as ɵm, StateContextFactory as ɵn, InternalStateOperations as ɵo, PluginManager as ɵp, InternalNgxsExecutionStrategy as ɵq, InternalErrorReporter as ɵr, SelectFactory as ɵs, ensureStoreMetadata as ɵu, getStoreMetadata as ɵv, ensureSelectorMetadata as ɵw, getSelectorMetadata as ɵx, LifecycleStateManager as ɵy, NgxsFeatureModule as ɵz };
4002
4114
  //# sourceMappingURL=ngxs-store.js.map