@ngxs/store 3.7.5-dev.master-0da56b4 → 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.
@@ -1900,6 +1900,126 @@
1900
1900
  })]));
1901
1901
  }); });
1902
1902
 
1903
+ /**
1904
+ * @fileoverview added by tsickle
1905
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1906
+ */
1907
+ /**
1908
+ * This operator is used for piping the observable result
1909
+ * from the `dispatch()`. It has a "smart" error handling
1910
+ * strategy that allows us to decide whether we propagate
1911
+ * errors to Angular's `ErrorHandler` or enable users to
1912
+ * handle them manually. We consider following cases:
1913
+ * 1) `store.dispatch()` (no subscribe) -> call `handleError()`
1914
+ * 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
1915
+ * 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
1916
+ * 4) `toPromise()` without `catch` -> do `handleError()`
1917
+ * 5) `toPromise()` with `catch` -> don't `handleError()`
1918
+ * @template T
1919
+ * @param {?} internalErrorReporter
1920
+ * @param {?} ngxsExecutionStrategy
1921
+ * @return {?}
1922
+ */
1923
+ function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
1924
+ return (/**
1925
+ * @param {?} source
1926
+ * @return {?}
1927
+ */
1928
+ function (source) {
1929
+ /** @type {?} */
1930
+ var subscribed = false;
1931
+ source.subscribe({
1932
+ error: (/**
1933
+ * @param {?} error
1934
+ * @return {?}
1935
+ */
1936
+ function (error) {
1937
+ // Do not trigger change detection for a microtask. This depends on the execution
1938
+ // strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
1939
+ // leaves the Angular zone.
1940
+ ngxsExecutionStrategy.enter((/**
1941
+ * @return {?}
1942
+ */
1943
+ function () {
1944
+ return Promise.resolve().then((/**
1945
+ * @return {?}
1946
+ */
1947
+ function () {
1948
+ if (!subscribed) {
1949
+ ngxsExecutionStrategy.leave((/**
1950
+ * @return {?}
1951
+ */
1952
+ function () {
1953
+ return internalErrorReporter.reportErrorSafely(error);
1954
+ }));
1955
+ }
1956
+ }));
1957
+ }));
1958
+ })
1959
+ });
1960
+ return new rxjs.Observable((/**
1961
+ * @param {?} subscriber
1962
+ * @return {?}
1963
+ */
1964
+ function (subscriber) {
1965
+ subscribed = true;
1966
+ return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
1967
+ }));
1968
+ });
1969
+ }
1970
+ var InternalErrorReporter = /** @class */ (function () {
1971
+ function InternalErrorReporter(_injector) {
1972
+ this._injector = _injector;
1973
+ /**
1974
+ * Will be set lazily to be backward compatible.
1975
+ */
1976
+ this._errorHandler = (/** @type {?} */ (null));
1977
+ }
1978
+ /**
1979
+ * @param {?} error
1980
+ * @return {?}
1981
+ */
1982
+ InternalErrorReporter.prototype.reportErrorSafely = /**
1983
+ * @param {?} error
1984
+ * @return {?}
1985
+ */
1986
+ function (error) {
1987
+ if (this._errorHandler === null) {
1988
+ this._errorHandler = this._injector.get(core.ErrorHandler);
1989
+ }
1990
+ // The `try-catch` is used to avoid handling the error twice. Suppose we call
1991
+ // `handleError` which re-throws the error internally. The re-thrown error will
1992
+ // be caught by zone.js which will then get to the `zone.onError.emit()` and the
1993
+ // `onError` subscriber will call `handleError` again.
1994
+ try {
1995
+ this._errorHandler.handleError(error);
1996
+ }
1997
+ catch (_a) { }
1998
+ };
1999
+ InternalErrorReporter.decorators = [
2000
+ { type: core.Injectable, args: [{ providedIn: 'root' },] }
2001
+ ];
2002
+ /** @nocollapse */
2003
+ InternalErrorReporter.ctorParameters = function () { return [
2004
+ { type: core.Injector }
2005
+ ]; };
2006
+ /** @nocollapse */ InternalErrorReporter.ngInjectableDef = core.defineInjectable({ factory: function InternalErrorReporter_Factory() { return new InternalErrorReporter(core.inject(core.INJECTOR)); }, token: InternalErrorReporter, providedIn: "root" });
2007
+ return InternalErrorReporter;
2008
+ }());
2009
+ if (false) {
2010
+ /**
2011
+ * Will be set lazily to be backward compatible.
2012
+ * @type {?}
2013
+ * @private
2014
+ */
2015
+ InternalErrorReporter.prototype._errorHandler;
2016
+ /**
2017
+ * @type {?}
2018
+ * @private
2019
+ */
2020
+ InternalErrorReporter.prototype._injector;
2021
+ }
2022
+
1903
2023
  /**
1904
2024
  * @fileoverview added by tsickle
1905
2025
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -2032,13 +2152,13 @@
2032
2152
  return InternalDispatchedActionResults;
2033
2153
  }(rxjs.Subject));
2034
2154
  var InternalDispatcher = /** @class */ (function () {
2035
- function InternalDispatcher(_injector, _actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy) {
2036
- this._injector = _injector;
2155
+ function InternalDispatcher(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
2037
2156
  this._actions = _actions;
2038
2157
  this._actionResults = _actionResults;
2039
2158
  this._pluginManager = _pluginManager;
2040
2159
  this._stateStream = _stateStream;
2041
2160
  this._ngxsExecutionStrategy = _ngxsExecutionStrategy;
2161
+ this._internalErrorReporter = _internalErrorReporter;
2042
2162
  }
2043
2163
  /**
2044
2164
  * Dispatches event(s).
@@ -2062,26 +2182,7 @@
2062
2182
  function () {
2063
2183
  return _this.dispatchByEvents(actionOrActions);
2064
2184
  }));
2065
- result.subscribe({
2066
- error: (/**
2067
- * @param {?} error
2068
- * @return {?}
2069
- */
2070
- function (error) {
2071
- return _this._ngxsExecutionStrategy.leave((/**
2072
- * @return {?}
2073
- */
2074
- function () {
2075
- try {
2076
- // Retrieve lazily to avoid cyclic dependency exception
2077
- _this._errorHandler = _this._errorHandler || _this._injector.get(core.ErrorHandler);
2078
- _this._errorHandler.handleError(error);
2079
- }
2080
- catch (_a) { }
2081
- }));
2082
- })
2083
- });
2084
- return result.pipe(leaveNgxs(this._ngxsExecutionStrategy));
2185
+ return result.pipe(ngxsErrorHandler(this._internalErrorReporter, this._ngxsExecutionStrategy));
2085
2186
  };
2086
2187
  /**
2087
2188
  * @private
@@ -2206,26 +2307,16 @@
2206
2307
  ];
2207
2308
  /** @nocollapse */
2208
2309
  InternalDispatcher.ctorParameters = function () { return [
2209
- { type: core.Injector },
2210
2310
  { type: InternalActions },
2211
2311
  { type: InternalDispatchedActionResults },
2212
2312
  { type: PluginManager },
2213
2313
  { type: StateStream },
2214
- { type: InternalNgxsExecutionStrategy }
2314
+ { type: InternalNgxsExecutionStrategy },
2315
+ { type: InternalErrorReporter }
2215
2316
  ]; };
2216
2317
  return InternalDispatcher;
2217
2318
  }());
2218
2319
  if (false) {
2219
- /**
2220
- * @type {?}
2221
- * @private
2222
- */
2223
- InternalDispatcher.prototype._errorHandler;
2224
- /**
2225
- * @type {?}
2226
- * @private
2227
- */
2228
- InternalDispatcher.prototype._injector;
2229
2320
  /**
2230
2321
  * @type {?}
2231
2322
  * @private
@@ -2251,6 +2342,11 @@
2251
2342
  * @private
2252
2343
  */
2253
2344
  InternalDispatcher.prototype._ngxsExecutionStrategy;
2345
+ /**
2346
+ * @type {?}
2347
+ * @private
2348
+ */
2349
+ InternalDispatcher.prototype._internalErrorReporter;
2254
2350
  }
2255
2351
 
2256
2352
  /**
@@ -3705,8 +3801,9 @@
3705
3801
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3706
3802
  */
3707
3803
  var LifecycleStateManager = /** @class */ (function () {
3708
- function LifecycleStateManager(_store, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3804
+ function LifecycleStateManager(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3709
3805
  this._store = _store;
3806
+ this._internalErrorReporter = _internalErrorReporter;
3710
3807
  this._internalStateOperations = _internalStateOperations;
3711
3808
  this._stateContextFactory = _stateContextFactory;
3712
3809
  this._bootstrapper = _bootstrapper;
@@ -3744,30 +3841,36 @@
3744
3841
  function () { return !!results; })), operators.tap((/**
3745
3842
  * @return {?}
3746
3843
  */
3747
- function () { return _this._invokeInit((/** @type {?} */ (results)).states); })), operators.mergeMap((/**
3844
+ function () { return _this._invokeInitOnStates((/** @type {?} */ (results)).states); })), operators.mergeMap((/**
3748
3845
  * @return {?}
3749
3846
  */
3750
3847
  function () { return _this._bootstrapper.appBootstrapped$; })), operators.filter((/**
3751
3848
  * @param {?} appBootstrapped
3752
3849
  * @return {?}
3753
3850
  */
3754
- function (appBootstrapped) { return !!appBootstrapped; })), operators.takeUntil(this._destroy$))
3851
+ function (appBootstrapped) { return !!appBootstrapped; })), operators.catchError((/**
3852
+ * @param {?} error
3853
+ * @return {?}
3854
+ */
3855
+ function (error) {
3856
+ // The `SafeSubscriber` (which is used by most RxJS operators) re-throws
3857
+ // errors asynchronously (`setTimeout(() => { throw error })`). This might
3858
+ // break existing user's code or unit tests. We catch the error manually to
3859
+ // be backward compatible with the old behavior.
3860
+ _this._internalErrorReporter.reportErrorSafely(error);
3861
+ return rxjs.EMPTY;
3862
+ })), operators.takeUntil(this._destroy$))
3755
3863
  .subscribe((/**
3756
3864
  * @return {?}
3757
3865
  */
3758
- function () { return _this._invokeBootstrap((/** @type {?} */ (results)).states); }));
3866
+ function () { return _this._invokeBootstrapOnStates((/** @type {?} */ (results)).states); }));
3759
3867
  };
3760
3868
  /**
3761
- * Invoke the init function on the states.
3762
- */
3763
- /**
3764
- * Invoke the init function on the states.
3765
3869
  * @private
3766
3870
  * @param {?} mappedStores
3767
3871
  * @return {?}
3768
3872
  */
3769
- LifecycleStateManager.prototype._invokeInit = /**
3770
- * Invoke the init function on the states.
3873
+ LifecycleStateManager.prototype._invokeInitOnStates = /**
3771
3874
  * @private
3772
3875
  * @param {?} mappedStores
3773
3876
  * @return {?}
@@ -3817,16 +3920,11 @@
3817
3920
  }
3818
3921
  };
3819
3922
  /**
3820
- * Invoke the bootstrap function on the states.
3821
- */
3822
- /**
3823
- * Invoke the bootstrap function on the states.
3824
3923
  * @private
3825
3924
  * @param {?} mappedStores
3826
3925
  * @return {?}
3827
3926
  */
3828
- LifecycleStateManager.prototype._invokeBootstrap = /**
3829
- * Invoke the bootstrap function on the states.
3927
+ LifecycleStateManager.prototype._invokeBootstrapOnStates = /**
3830
3928
  * @private
3831
3929
  * @param {?} mappedStores
3832
3930
  * @return {?}
@@ -3870,6 +3968,7 @@
3870
3968
  /** @nocollapse */
3871
3969
  LifecycleStateManager.ctorParameters = function () { return [
3872
3970
  { type: Store },
3971
+ { type: InternalErrorReporter },
3873
3972
  { type: InternalStateOperations },
3874
3973
  { type: StateContextFactory },
3875
3974
  { type: internals.NgxsBootstrapper }
@@ -3887,6 +3986,11 @@
3887
3986
  * @private
3888
3987
  */
3889
3988
  LifecycleStateManager.prototype._store;
3989
+ /**
3990
+ * @type {?}
3991
+ * @private
3992
+ */
3993
+ LifecycleStateManager.prototype._internalErrorReporter;
3890
3994
  /**
3891
3995
  * @type {?}
3892
3996
  * @private
@@ -4753,13 +4857,14 @@
4753
4857
  exports.ɵo = InternalStateOperations;
4754
4858
  exports.ɵp = PluginManager;
4755
4859
  exports.ɵq = InternalNgxsExecutionStrategy;
4756
- exports.ɵr = SelectFactory;
4757
- exports.ɵt = ensureStoreMetadata;
4758
- exports.ɵu = getStoreMetadata;
4759
- exports.ɵv = ensureSelectorMetadata;
4760
- exports.ɵw = getSelectorMetadata;
4761
- exports.ɵx = LifecycleStateManager;
4762
- exports.ɵy = NgxsFeatureModule;
4860
+ exports.ɵr = InternalErrorReporter;
4861
+ exports.ɵs = SelectFactory;
4862
+ exports.ɵu = ensureStoreMetadata;
4863
+ exports.ɵv = getStoreMetadata;
4864
+ exports.ɵw = ensureSelectorMetadata;
4865
+ exports.ɵx = getSelectorMetadata;
4866
+ exports.ɵy = LifecycleStateManager;
4867
+ exports.ɵz = NgxsFeatureModule;
4763
4868
 
4764
4869
  Object.defineProperty(exports, '__esModule', { value: true });
4765
4870