@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.
@@ -1,4 +1,4 @@
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
4
  import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable, queueScheduler } from 'rxjs';
@@ -1565,6 +1565,120 @@ const compose = (/**
1565
1565
  (...nextArgs) => compose(funcs)(...nextArgs)));
1566
1566
  }));
1567
1567
 
1568
+ /**
1569
+ * @fileoverview added by tsickle
1570
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1571
+ */
1572
+ /**
1573
+ * This operator is used for piping the observable result
1574
+ * from the `dispatch()`. It has a "smart" error handling
1575
+ * strategy that allows us to decide whether we propagate
1576
+ * errors to Angular's `ErrorHandler` or enable users to
1577
+ * handle them manually. We consider following cases:
1578
+ * 1) `store.dispatch()` (no subscribe) -> call `handleError()`
1579
+ * 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
1580
+ * 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
1581
+ * 4) `toPromise()` without `catch` -> do `handleError()`
1582
+ * 5) `toPromise()` with `catch` -> don't `handleError()`
1583
+ * @template T
1584
+ * @param {?} internalErrorReporter
1585
+ * @param {?} ngxsExecutionStrategy
1586
+ * @return {?}
1587
+ */
1588
+ function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
1589
+ return (/**
1590
+ * @param {?} source
1591
+ * @return {?}
1592
+ */
1593
+ (source) => {
1594
+ /** @type {?} */
1595
+ let subscribed = false;
1596
+ source.subscribe({
1597
+ error: (/**
1598
+ * @param {?} error
1599
+ * @return {?}
1600
+ */
1601
+ error => {
1602
+ // Do not trigger change detection for a microtask. This depends on the execution
1603
+ // strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
1604
+ // leaves the Angular zone.
1605
+ ngxsExecutionStrategy.enter((/**
1606
+ * @return {?}
1607
+ */
1608
+ () => Promise.resolve().then((/**
1609
+ * @return {?}
1610
+ */
1611
+ () => {
1612
+ if (!subscribed) {
1613
+ ngxsExecutionStrategy.leave((/**
1614
+ * @return {?}
1615
+ */
1616
+ () => internalErrorReporter.reportErrorSafely(error)));
1617
+ }
1618
+ }))));
1619
+ })
1620
+ });
1621
+ return new Observable((/**
1622
+ * @param {?} subscriber
1623
+ * @return {?}
1624
+ */
1625
+ subscriber => {
1626
+ subscribed = true;
1627
+ return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
1628
+ }));
1629
+ });
1630
+ }
1631
+ class InternalErrorReporter {
1632
+ /**
1633
+ * @param {?} _injector
1634
+ */
1635
+ constructor(_injector) {
1636
+ this._injector = _injector;
1637
+ /**
1638
+ * Will be set lazily to be backward compatible.
1639
+ */
1640
+ this._errorHandler = (/** @type {?} */ (null));
1641
+ }
1642
+ /**
1643
+ * @param {?} error
1644
+ * @return {?}
1645
+ */
1646
+ reportErrorSafely(error) {
1647
+ if (this._errorHandler === null) {
1648
+ this._errorHandler = this._injector.get(ErrorHandler);
1649
+ }
1650
+ // The `try-catch` is used to avoid handling the error twice. Suppose we call
1651
+ // `handleError` which re-throws the error internally. The re-thrown error will
1652
+ // be caught by zone.js which will then get to the `zone.onError.emit()` and the
1653
+ // `onError` subscriber will call `handleError` again.
1654
+ try {
1655
+ this._errorHandler.handleError(error);
1656
+ }
1657
+ catch (_a) { }
1658
+ }
1659
+ }
1660
+ InternalErrorReporter.decorators = [
1661
+ { type: Injectable, args: [{ providedIn: 'root' },] }
1662
+ ];
1663
+ /** @nocollapse */
1664
+ InternalErrorReporter.ctorParameters = () => [
1665
+ { type: Injector }
1666
+ ];
1667
+ /** @nocollapse */ InternalErrorReporter.ngInjectableDef = defineInjectable({ factory: function InternalErrorReporter_Factory() { return new InternalErrorReporter(inject(INJECTOR)); }, token: InternalErrorReporter, providedIn: "root" });
1668
+ if (false) {
1669
+ /**
1670
+ * Will be set lazily to be backward compatible.
1671
+ * @type {?}
1672
+ * @private
1673
+ */
1674
+ InternalErrorReporter.prototype._errorHandler;
1675
+ /**
1676
+ * @type {?}
1677
+ * @private
1678
+ */
1679
+ InternalErrorReporter.prototype._injector;
1680
+ }
1681
+
1568
1682
  /**
1569
1683
  * @fileoverview added by tsickle
1570
1684
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -1678,20 +1792,20 @@ InternalDispatchedActionResults.decorators = [
1678
1792
  ];
1679
1793
  class InternalDispatcher {
1680
1794
  /**
1681
- * @param {?} _injector
1682
1795
  * @param {?} _actions
1683
1796
  * @param {?} _actionResults
1684
1797
  * @param {?} _pluginManager
1685
1798
  * @param {?} _stateStream
1686
1799
  * @param {?} _ngxsExecutionStrategy
1800
+ * @param {?} _internalErrorReporter
1687
1801
  */
1688
- constructor(_injector, _actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy) {
1689
- this._injector = _injector;
1802
+ constructor(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
1690
1803
  this._actions = _actions;
1691
1804
  this._actionResults = _actionResults;
1692
1805
  this._pluginManager = _pluginManager;
1693
1806
  this._stateStream = _stateStream;
1694
1807
  this._ngxsExecutionStrategy = _ngxsExecutionStrategy;
1808
+ this._internalErrorReporter = _internalErrorReporter;
1695
1809
  }
1696
1810
  /**
1697
1811
  * Dispatches event(s).
@@ -1704,24 +1818,7 @@ class InternalDispatcher {
1704
1818
  * @return {?}
1705
1819
  */
1706
1820
  () => this.dispatchByEvents(actionOrActions)));
1707
- result.subscribe({
1708
- error: (/**
1709
- * @param {?} error
1710
- * @return {?}
1711
- */
1712
- error => this._ngxsExecutionStrategy.leave((/**
1713
- * @return {?}
1714
- */
1715
- () => {
1716
- try {
1717
- // Retrieve lazily to avoid cyclic dependency exception
1718
- this._errorHandler = this._errorHandler || this._injector.get(ErrorHandler);
1719
- this._errorHandler.handleError(error);
1720
- }
1721
- catch (_a) { }
1722
- })))
1723
- });
1724
- return result.pipe(leaveNgxs(this._ngxsExecutionStrategy));
1821
+ return result.pipe(ngxsErrorHandler(this._internalErrorReporter, this._ngxsExecutionStrategy));
1725
1822
  }
1726
1823
  /**
1727
1824
  * @private
@@ -1825,24 +1922,14 @@ InternalDispatcher.decorators = [
1825
1922
  ];
1826
1923
  /** @nocollapse */
1827
1924
  InternalDispatcher.ctorParameters = () => [
1828
- { type: Injector },
1829
1925
  { type: InternalActions },
1830
1926
  { type: InternalDispatchedActionResults },
1831
1927
  { type: PluginManager },
1832
1928
  { type: StateStream },
1833
- { type: InternalNgxsExecutionStrategy }
1929
+ { type: InternalNgxsExecutionStrategy },
1930
+ { type: InternalErrorReporter }
1834
1931
  ];
1835
1932
  if (false) {
1836
- /**
1837
- * @type {?}
1838
- * @private
1839
- */
1840
- InternalDispatcher.prototype._errorHandler;
1841
- /**
1842
- * @type {?}
1843
- * @private
1844
- */
1845
- InternalDispatcher.prototype._injector;
1846
1933
  /**
1847
1934
  * @type {?}
1848
1935
  * @private
@@ -1868,6 +1955,11 @@ if (false) {
1868
1955
  * @private
1869
1956
  */
1870
1957
  InternalDispatcher.prototype._ngxsExecutionStrategy;
1958
+ /**
1959
+ * @type {?}
1960
+ * @private
1961
+ */
1962
+ InternalDispatcher.prototype._internalErrorReporter;
1871
1963
  }
1872
1964
 
1873
1965
  /**
@@ -3111,12 +3203,14 @@ if (false) {
3111
3203
  class LifecycleStateManager {
3112
3204
  /**
3113
3205
  * @param {?} _store
3206
+ * @param {?} _internalErrorReporter
3114
3207
  * @param {?} _internalStateOperations
3115
3208
  * @param {?} _stateContextFactory
3116
3209
  * @param {?} _bootstrapper
3117
3210
  */
3118
- constructor(_store, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3211
+ constructor(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3119
3212
  this._store = _store;
3213
+ this._internalErrorReporter = _internalErrorReporter;
3120
3214
  this._internalStateOperations = _internalStateOperations;
3121
3215
  this._stateContextFactory = _stateContextFactory;
3122
3216
  this._bootstrapper = _bootstrapper;
@@ -3144,26 +3238,36 @@ class LifecycleStateManager {
3144
3238
  () => !!results)), tap((/**
3145
3239
  * @return {?}
3146
3240
  */
3147
- () => this._invokeInit((/** @type {?} */ (results)).states))), mergeMap((/**
3241
+ () => this._invokeInitOnStates((/** @type {?} */ (results)).states))), mergeMap((/**
3148
3242
  * @return {?}
3149
3243
  */
3150
3244
  () => this._bootstrapper.appBootstrapped$)), filter((/**
3151
3245
  * @param {?} appBootstrapped
3152
3246
  * @return {?}
3153
3247
  */
3154
- appBootstrapped => !!appBootstrapped)), takeUntil(this._destroy$))
3248
+ appBootstrapped => !!appBootstrapped)), catchError((/**
3249
+ * @param {?} error
3250
+ * @return {?}
3251
+ */
3252
+ error => {
3253
+ // The `SafeSubscriber` (which is used by most RxJS operators) re-throws
3254
+ // errors asynchronously (`setTimeout(() => { throw error })`). This might
3255
+ // break existing user's code or unit tests. We catch the error manually to
3256
+ // be backward compatible with the old behavior.
3257
+ this._internalErrorReporter.reportErrorSafely(error);
3258
+ return EMPTY;
3259
+ })), takeUntil(this._destroy$))
3155
3260
  .subscribe((/**
3156
3261
  * @return {?}
3157
3262
  */
3158
- () => this._invokeBootstrap((/** @type {?} */ (results)).states)));
3263
+ () => this._invokeBootstrapOnStates((/** @type {?} */ (results)).states)));
3159
3264
  }
3160
3265
  /**
3161
- * Invoke the init function on the states.
3162
3266
  * @private
3163
3267
  * @param {?} mappedStores
3164
3268
  * @return {?}
3165
3269
  */
3166
- _invokeInit(mappedStores) {
3270
+ _invokeInitOnStates(mappedStores) {
3167
3271
  for (const mappedStore of mappedStores) {
3168
3272
  /** @type {?} */
3169
3273
  const instance = mappedStore.instance;
@@ -3192,12 +3296,11 @@ class LifecycleStateManager {
3192
3296
  }
3193
3297
  }
3194
3298
  /**
3195
- * Invoke the bootstrap function on the states.
3196
3299
  * @private
3197
3300
  * @param {?} mappedStores
3198
3301
  * @return {?}
3199
3302
  */
3200
- _invokeBootstrap(mappedStores) {
3303
+ _invokeBootstrapOnStates(mappedStores) {
3201
3304
  for (const mappedStore of mappedStores) {
3202
3305
  /** @type {?} */
3203
3306
  const instance = mappedStore.instance;
@@ -3221,6 +3324,7 @@ LifecycleStateManager.decorators = [
3221
3324
  /** @nocollapse */
3222
3325
  LifecycleStateManager.ctorParameters = () => [
3223
3326
  { type: Store },
3327
+ { type: InternalErrorReporter },
3224
3328
  { type: InternalStateOperations },
3225
3329
  { type: StateContextFactory },
3226
3330
  { type: NgxsBootstrapper }
@@ -3236,6 +3340,11 @@ if (false) {
3236
3340
  * @private
3237
3341
  */
3238
3342
  LifecycleStateManager.prototype._store;
3343
+ /**
3344
+ * @type {?}
3345
+ * @private
3346
+ */
3347
+ LifecycleStateManager.prototype._internalErrorReporter;
3239
3348
  /**
3240
3349
  * @type {?}
3241
3350
  * @private
@@ -4000,5 +4109,5 @@ if (false) {
4000
4109
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
4001
4110
  */
4002
4111
 
4003
- 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 };
4112
+ 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 };
4004
4113
  //# sourceMappingURL=ngxs-store.js.map