@ngxs/store 3.7.5-dev.master-f9549a3 → 3.7.5-dev.master-b4f4da3

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,5 +1,5 @@
1
1
  import { __assign, __spread, __extends, __values, __read } from 'tslib';
2
- import { NgZone, Injectable, Inject, PLATFORM_ID, defineInjectable, inject, InjectionToken, INJECTOR, ɵglobal, Optional, SkipSelf, ErrorHandler, Injector, ɵivyEnabled, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
2
+ import { NgZone, Injectable, Inject, PLATFORM_ID, defineInjectable, inject, InjectionToken, INJECTOR, ɵglobal, ErrorHandler, Injector, Optional, SkipSelf, ɵivyEnabled, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
3
3
  import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, NGXS_STATE_CONTEXT_FACTORY, NGXS_STATE_FACTORY, InitialState } from '@ngxs/store/internals';
4
4
  import { isPlatformServer } from '@angular/common';
5
5
  import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable, queueScheduler } from 'rxjs';
@@ -1568,6 +1568,15 @@ var InternalActions = /** @class */ (function (_super) {
1568
1568
  function InternalActions() {
1569
1569
  return _super !== null && _super.apply(this, arguments) || this;
1570
1570
  }
1571
+ /**
1572
+ * @return {?}
1573
+ */
1574
+ InternalActions.prototype.ngOnDestroy = /**
1575
+ * @return {?}
1576
+ */
1577
+ function () {
1578
+ this.complete();
1579
+ };
1571
1580
  InternalActions.decorators = [
1572
1581
  { type: Injectable }
1573
1582
  ];
@@ -1673,6 +1682,126 @@ function () {
1673
1682
  })]));
1674
1683
  }); });
1675
1684
 
1685
+ /**
1686
+ * @fileoverview added by tsickle
1687
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1688
+ */
1689
+ /**
1690
+ * This operator is used for piping the observable result
1691
+ * from the `dispatch()`. It has a "smart" error handling
1692
+ * strategy that allows us to decide whether we propagate
1693
+ * errors to Angular's `ErrorHandler` or enable users to
1694
+ * handle them manually. We consider following cases:
1695
+ * 1) `store.dispatch()` (no subscribe) -> call `handleError()`
1696
+ * 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
1697
+ * 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
1698
+ * 4) `toPromise()` without `catch` -> do `handleError()`
1699
+ * 5) `toPromise()` with `catch` -> don't `handleError()`
1700
+ * @template T
1701
+ * @param {?} internalErrorReporter
1702
+ * @param {?} ngxsExecutionStrategy
1703
+ * @return {?}
1704
+ */
1705
+ function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
1706
+ return (/**
1707
+ * @param {?} source
1708
+ * @return {?}
1709
+ */
1710
+ function (source) {
1711
+ /** @type {?} */
1712
+ var subscribed = false;
1713
+ source.subscribe({
1714
+ error: (/**
1715
+ * @param {?} error
1716
+ * @return {?}
1717
+ */
1718
+ function (error) {
1719
+ // Do not trigger change detection for a microtask. This depends on the execution
1720
+ // strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
1721
+ // leaves the Angular zone.
1722
+ ngxsExecutionStrategy.enter((/**
1723
+ * @return {?}
1724
+ */
1725
+ function () {
1726
+ return Promise.resolve().then((/**
1727
+ * @return {?}
1728
+ */
1729
+ function () {
1730
+ if (!subscribed) {
1731
+ ngxsExecutionStrategy.leave((/**
1732
+ * @return {?}
1733
+ */
1734
+ function () {
1735
+ return internalErrorReporter.reportErrorSafely(error);
1736
+ }));
1737
+ }
1738
+ }));
1739
+ }));
1740
+ })
1741
+ });
1742
+ return new Observable((/**
1743
+ * @param {?} subscriber
1744
+ * @return {?}
1745
+ */
1746
+ function (subscriber) {
1747
+ subscribed = true;
1748
+ return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
1749
+ }));
1750
+ });
1751
+ }
1752
+ var InternalErrorReporter = /** @class */ (function () {
1753
+ function InternalErrorReporter(_injector) {
1754
+ this._injector = _injector;
1755
+ /**
1756
+ * Will be set lazily to be backward compatible.
1757
+ */
1758
+ this._errorHandler = (/** @type {?} */ (null));
1759
+ }
1760
+ /**
1761
+ * @param {?} error
1762
+ * @return {?}
1763
+ */
1764
+ InternalErrorReporter.prototype.reportErrorSafely = /**
1765
+ * @param {?} error
1766
+ * @return {?}
1767
+ */
1768
+ function (error) {
1769
+ if (this._errorHandler === null) {
1770
+ this._errorHandler = this._injector.get(ErrorHandler);
1771
+ }
1772
+ // The `try-catch` is used to avoid handling the error twice. Suppose we call
1773
+ // `handleError` which re-throws the error internally. The re-thrown error will
1774
+ // be caught by zone.js which will then get to the `zone.onError.emit()` and the
1775
+ // `onError` subscriber will call `handleError` again.
1776
+ try {
1777
+ this._errorHandler.handleError(error);
1778
+ }
1779
+ catch (_a) { }
1780
+ };
1781
+ InternalErrorReporter.decorators = [
1782
+ { type: Injectable, args: [{ providedIn: 'root' },] }
1783
+ ];
1784
+ /** @nocollapse */
1785
+ InternalErrorReporter.ctorParameters = function () { return [
1786
+ { type: Injector }
1787
+ ]; };
1788
+ /** @nocollapse */ InternalErrorReporter.ngInjectableDef = defineInjectable({ factory: function InternalErrorReporter_Factory() { return new InternalErrorReporter(inject(INJECTOR)); }, token: InternalErrorReporter, providedIn: "root" });
1789
+ return InternalErrorReporter;
1790
+ }());
1791
+ if (false) {
1792
+ /**
1793
+ * Will be set lazily to be backward compatible.
1794
+ * @type {?}
1795
+ * @private
1796
+ */
1797
+ InternalErrorReporter.prototype._errorHandler;
1798
+ /**
1799
+ * @type {?}
1800
+ * @private
1801
+ */
1802
+ InternalErrorReporter.prototype._injector;
1803
+ }
1804
+
1676
1805
  /**
1677
1806
  * @fileoverview added by tsickle
1678
1807
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -1805,13 +1934,13 @@ var InternalDispatchedActionResults = /** @class */ (function (_super) {
1805
1934
  return InternalDispatchedActionResults;
1806
1935
  }(Subject));
1807
1936
  var InternalDispatcher = /** @class */ (function () {
1808
- function InternalDispatcher(_injector, _actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy) {
1809
- this._injector = _injector;
1937
+ function InternalDispatcher(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
1810
1938
  this._actions = _actions;
1811
1939
  this._actionResults = _actionResults;
1812
1940
  this._pluginManager = _pluginManager;
1813
1941
  this._stateStream = _stateStream;
1814
1942
  this._ngxsExecutionStrategy = _ngxsExecutionStrategy;
1943
+ this._internalErrorReporter = _internalErrorReporter;
1815
1944
  }
1816
1945
  /**
1817
1946
  * Dispatches event(s).
@@ -1835,26 +1964,7 @@ var InternalDispatcher = /** @class */ (function () {
1835
1964
  function () {
1836
1965
  return _this.dispatchByEvents(actionOrActions);
1837
1966
  }));
1838
- result.subscribe({
1839
- error: (/**
1840
- * @param {?} error
1841
- * @return {?}
1842
- */
1843
- function (error) {
1844
- return _this._ngxsExecutionStrategy.leave((/**
1845
- * @return {?}
1846
- */
1847
- function () {
1848
- try {
1849
- // Retrieve lazily to avoid cyclic dependency exception
1850
- _this._errorHandler = _this._errorHandler || _this._injector.get(ErrorHandler);
1851
- _this._errorHandler.handleError(error);
1852
- }
1853
- catch (_a) { }
1854
- }));
1855
- })
1856
- });
1857
- return result.pipe(leaveNgxs(this._ngxsExecutionStrategy));
1967
+ return result.pipe(ngxsErrorHandler(this._internalErrorReporter, this._ngxsExecutionStrategy));
1858
1968
  };
1859
1969
  /**
1860
1970
  * @private
@@ -1979,26 +2089,16 @@ var InternalDispatcher = /** @class */ (function () {
1979
2089
  ];
1980
2090
  /** @nocollapse */
1981
2091
  InternalDispatcher.ctorParameters = function () { return [
1982
- { type: Injector },
1983
2092
  { type: InternalActions },
1984
2093
  { type: InternalDispatchedActionResults },
1985
2094
  { type: PluginManager },
1986
2095
  { type: StateStream },
1987
- { type: InternalNgxsExecutionStrategy }
2096
+ { type: InternalNgxsExecutionStrategy },
2097
+ { type: InternalErrorReporter }
1988
2098
  ]; };
1989
2099
  return InternalDispatcher;
1990
2100
  }());
1991
2101
  if (false) {
1992
- /**
1993
- * @type {?}
1994
- * @private
1995
- */
1996
- InternalDispatcher.prototype._errorHandler;
1997
- /**
1998
- * @type {?}
1999
- * @private
2000
- */
2001
- InternalDispatcher.prototype._injector;
2002
2102
  /**
2003
2103
  * @type {?}
2004
2104
  * @private
@@ -2024,6 +2124,11 @@ if (false) {
2024
2124
  * @private
2025
2125
  */
2026
2126
  InternalDispatcher.prototype._ngxsExecutionStrategy;
2127
+ /**
2128
+ * @type {?}
2129
+ * @private
2130
+ */
2131
+ InternalDispatcher.prototype._internalErrorReporter;
2027
2132
  }
2028
2133
 
2029
2134
  /**
@@ -3478,8 +3583,9 @@ if (false) {
3478
3583
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3479
3584
  */
3480
3585
  var LifecycleStateManager = /** @class */ (function () {
3481
- function LifecycleStateManager(_store, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3586
+ function LifecycleStateManager(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3482
3587
  this._store = _store;
3588
+ this._internalErrorReporter = _internalErrorReporter;
3483
3589
  this._internalStateOperations = _internalStateOperations;
3484
3590
  this._stateContextFactory = _stateContextFactory;
3485
3591
  this._bootstrapper = _bootstrapper;
@@ -3517,30 +3623,36 @@ var LifecycleStateManager = /** @class */ (function () {
3517
3623
  function () { return !!results; })), tap((/**
3518
3624
  * @return {?}
3519
3625
  */
3520
- function () { return _this._invokeInit((/** @type {?} */ (results)).states); })), mergeMap((/**
3626
+ function () { return _this._invokeInitOnStates((/** @type {?} */ (results)).states); })), mergeMap((/**
3521
3627
  * @return {?}
3522
3628
  */
3523
3629
  function () { return _this._bootstrapper.appBootstrapped$; })), filter((/**
3524
3630
  * @param {?} appBootstrapped
3525
3631
  * @return {?}
3526
3632
  */
3527
- function (appBootstrapped) { return !!appBootstrapped; })), takeUntil(this._destroy$))
3633
+ function (appBootstrapped) { return !!appBootstrapped; })), catchError((/**
3634
+ * @param {?} error
3635
+ * @return {?}
3636
+ */
3637
+ function (error) {
3638
+ // The `SafeSubscriber` (which is used by most RxJS operators) re-throws
3639
+ // errors asynchronously (`setTimeout(() => { throw error })`). This might
3640
+ // break existing user's code or unit tests. We catch the error manually to
3641
+ // be backward compatible with the old behavior.
3642
+ _this._internalErrorReporter.reportErrorSafely(error);
3643
+ return EMPTY;
3644
+ })), takeUntil(this._destroy$))
3528
3645
  .subscribe((/**
3529
3646
  * @return {?}
3530
3647
  */
3531
- function () { return _this._invokeBootstrap((/** @type {?} */ (results)).states); }));
3648
+ function () { return _this._invokeBootstrapOnStates((/** @type {?} */ (results)).states); }));
3532
3649
  };
3533
3650
  /**
3534
- * Invoke the init function on the states.
3535
- */
3536
- /**
3537
- * Invoke the init function on the states.
3538
3651
  * @private
3539
3652
  * @param {?} mappedStores
3540
3653
  * @return {?}
3541
3654
  */
3542
- LifecycleStateManager.prototype._invokeInit = /**
3543
- * Invoke the init function on the states.
3655
+ LifecycleStateManager.prototype._invokeInitOnStates = /**
3544
3656
  * @private
3545
3657
  * @param {?} mappedStores
3546
3658
  * @return {?}
@@ -3590,16 +3702,11 @@ var LifecycleStateManager = /** @class */ (function () {
3590
3702
  }
3591
3703
  };
3592
3704
  /**
3593
- * Invoke the bootstrap function on the states.
3594
- */
3595
- /**
3596
- * Invoke the bootstrap function on the states.
3597
3705
  * @private
3598
3706
  * @param {?} mappedStores
3599
3707
  * @return {?}
3600
3708
  */
3601
- LifecycleStateManager.prototype._invokeBootstrap = /**
3602
- * Invoke the bootstrap function on the states.
3709
+ LifecycleStateManager.prototype._invokeBootstrapOnStates = /**
3603
3710
  * @private
3604
3711
  * @param {?} mappedStores
3605
3712
  * @return {?}
@@ -3643,6 +3750,7 @@ var LifecycleStateManager = /** @class */ (function () {
3643
3750
  /** @nocollapse */
3644
3751
  LifecycleStateManager.ctorParameters = function () { return [
3645
3752
  { type: Store },
3753
+ { type: InternalErrorReporter },
3646
3754
  { type: InternalStateOperations },
3647
3755
  { type: StateContextFactory },
3648
3756
  { type: NgxsBootstrapper }
@@ -3660,6 +3768,11 @@ if (false) {
3660
3768
  * @private
3661
3769
  */
3662
3770
  LifecycleStateManager.prototype._store;
3771
+ /**
3772
+ * @type {?}
3773
+ * @private
3774
+ */
3775
+ LifecycleStateManager.prototype._internalErrorReporter;
3663
3776
  /**
3664
3777
  * @type {?}
3665
3778
  * @private
@@ -4499,5 +4612,5 @@ if (false) {
4499
4612
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
4500
4613
  */
4501
4614
 
4502
- 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 };
4615
+ 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 };
4503
4616
  //# sourceMappingURL=ngxs-store.js.map