@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.
- package/bundles/ngxs-store.umd.js +171 -57
- package/bundles/ngxs-store.umd.js.map +1 -1
- package/bundles/ngxs-store.umd.min.js +1 -1
- package/bundles/ngxs-store.umd.min.js.map +1 -1
- package/esm2015/ngxs-store.js +6 -5
- package/esm2015/src/actions-stream.js +7 -1
- package/esm2015/src/internal/dispatcher.js +14 -36
- package/esm2015/src/internal/error-handler.js +118 -0
- package/esm2015/src/internal/lifecycle-state-manager.js +29 -11
- package/esm5/ngxs-store.js +6 -5
- package/esm5/src/actions-stream.js +10 -1
- package/esm5/src/internal/dispatcher.js +13 -37
- package/esm5/src/internal/error-handler.js +125 -0
- package/esm5/src/internal/lifecycle-state-manager.js +28 -19
- package/fesm2015/ngxs-store.js +158 -43
- package/fesm2015/ngxs-store.js.map +1 -1
- package/fesm5/ngxs-store.js +165 -52
- package/fesm5/ngxs-store.js.map +1 -1
- package/ngxs-store.d.ts +6 -5
- package/ngxs-store.metadata.json +1 -1
- package/package.json +1 -1
- package/src/actions-stream.d.ts +3 -1
- package/src/internal/dispatcher.d.ts +3 -4
- package/src/internal/error-handler.d.ts +23 -0
- package/src/internal/lifecycle-state-manager.d.ts +5 -9
package/fesm2015/ngxs-store.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { NgZone, Injectable, Inject, PLATFORM_ID, defineInjectable, inject, InjectionToken, INJECTOR, ɵglobal,
|
|
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';
|
|
@@ -1463,6 +1463,12 @@ if (false) {
|
|
|
1463
1463
|
* Internal Action stream that is emitted anytime an action is dispatched.
|
|
1464
1464
|
*/
|
|
1465
1465
|
class InternalActions extends OrderedSubject {
|
|
1466
|
+
/**
|
|
1467
|
+
* @return {?}
|
|
1468
|
+
*/
|
|
1469
|
+
ngOnDestroy() {
|
|
1470
|
+
this.complete();
|
|
1471
|
+
}
|
|
1466
1472
|
}
|
|
1467
1473
|
InternalActions.decorators = [
|
|
1468
1474
|
{ type: Injectable }
|
|
@@ -1559,6 +1565,120 @@ const compose = (/**
|
|
|
1559
1565
|
(...nextArgs) => compose(funcs)(...nextArgs)));
|
|
1560
1566
|
}));
|
|
1561
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
|
+
|
|
1562
1682
|
/**
|
|
1563
1683
|
* @fileoverview added by tsickle
|
|
1564
1684
|
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
@@ -1672,20 +1792,20 @@ InternalDispatchedActionResults.decorators = [
|
|
|
1672
1792
|
];
|
|
1673
1793
|
class InternalDispatcher {
|
|
1674
1794
|
/**
|
|
1675
|
-
* @param {?} _injector
|
|
1676
1795
|
* @param {?} _actions
|
|
1677
1796
|
* @param {?} _actionResults
|
|
1678
1797
|
* @param {?} _pluginManager
|
|
1679
1798
|
* @param {?} _stateStream
|
|
1680
1799
|
* @param {?} _ngxsExecutionStrategy
|
|
1800
|
+
* @param {?} _internalErrorReporter
|
|
1681
1801
|
*/
|
|
1682
|
-
constructor(
|
|
1683
|
-
this._injector = _injector;
|
|
1802
|
+
constructor(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
|
|
1684
1803
|
this._actions = _actions;
|
|
1685
1804
|
this._actionResults = _actionResults;
|
|
1686
1805
|
this._pluginManager = _pluginManager;
|
|
1687
1806
|
this._stateStream = _stateStream;
|
|
1688
1807
|
this._ngxsExecutionStrategy = _ngxsExecutionStrategy;
|
|
1808
|
+
this._internalErrorReporter = _internalErrorReporter;
|
|
1689
1809
|
}
|
|
1690
1810
|
/**
|
|
1691
1811
|
* Dispatches event(s).
|
|
@@ -1698,24 +1818,7 @@ class InternalDispatcher {
|
|
|
1698
1818
|
* @return {?}
|
|
1699
1819
|
*/
|
|
1700
1820
|
() => this.dispatchByEvents(actionOrActions)));
|
|
1701
|
-
result.
|
|
1702
|
-
error: (/**
|
|
1703
|
-
* @param {?} error
|
|
1704
|
-
* @return {?}
|
|
1705
|
-
*/
|
|
1706
|
-
error => this._ngxsExecutionStrategy.leave((/**
|
|
1707
|
-
* @return {?}
|
|
1708
|
-
*/
|
|
1709
|
-
() => {
|
|
1710
|
-
try {
|
|
1711
|
-
// Retrieve lazily to avoid cyclic dependency exception
|
|
1712
|
-
this._errorHandler = this._errorHandler || this._injector.get(ErrorHandler);
|
|
1713
|
-
this._errorHandler.handleError(error);
|
|
1714
|
-
}
|
|
1715
|
-
catch (_a) { }
|
|
1716
|
-
})))
|
|
1717
|
-
});
|
|
1718
|
-
return result.pipe(leaveNgxs(this._ngxsExecutionStrategy));
|
|
1821
|
+
return result.pipe(ngxsErrorHandler(this._internalErrorReporter, this._ngxsExecutionStrategy));
|
|
1719
1822
|
}
|
|
1720
1823
|
/**
|
|
1721
1824
|
* @private
|
|
@@ -1819,24 +1922,14 @@ InternalDispatcher.decorators = [
|
|
|
1819
1922
|
];
|
|
1820
1923
|
/** @nocollapse */
|
|
1821
1924
|
InternalDispatcher.ctorParameters = () => [
|
|
1822
|
-
{ type: Injector },
|
|
1823
1925
|
{ type: InternalActions },
|
|
1824
1926
|
{ type: InternalDispatchedActionResults },
|
|
1825
1927
|
{ type: PluginManager },
|
|
1826
1928
|
{ type: StateStream },
|
|
1827
|
-
{ type: InternalNgxsExecutionStrategy }
|
|
1929
|
+
{ type: InternalNgxsExecutionStrategy },
|
|
1930
|
+
{ type: InternalErrorReporter }
|
|
1828
1931
|
];
|
|
1829
1932
|
if (false) {
|
|
1830
|
-
/**
|
|
1831
|
-
* @type {?}
|
|
1832
|
-
* @private
|
|
1833
|
-
*/
|
|
1834
|
-
InternalDispatcher.prototype._errorHandler;
|
|
1835
|
-
/**
|
|
1836
|
-
* @type {?}
|
|
1837
|
-
* @private
|
|
1838
|
-
*/
|
|
1839
|
-
InternalDispatcher.prototype._injector;
|
|
1840
1933
|
/**
|
|
1841
1934
|
* @type {?}
|
|
1842
1935
|
* @private
|
|
@@ -1862,6 +1955,11 @@ if (false) {
|
|
|
1862
1955
|
* @private
|
|
1863
1956
|
*/
|
|
1864
1957
|
InternalDispatcher.prototype._ngxsExecutionStrategy;
|
|
1958
|
+
/**
|
|
1959
|
+
* @type {?}
|
|
1960
|
+
* @private
|
|
1961
|
+
*/
|
|
1962
|
+
InternalDispatcher.prototype._internalErrorReporter;
|
|
1865
1963
|
}
|
|
1866
1964
|
|
|
1867
1965
|
/**
|
|
@@ -3105,12 +3203,14 @@ if (false) {
|
|
|
3105
3203
|
class LifecycleStateManager {
|
|
3106
3204
|
/**
|
|
3107
3205
|
* @param {?} _store
|
|
3206
|
+
* @param {?} _internalErrorReporter
|
|
3108
3207
|
* @param {?} _internalStateOperations
|
|
3109
3208
|
* @param {?} _stateContextFactory
|
|
3110
3209
|
* @param {?} _bootstrapper
|
|
3111
3210
|
*/
|
|
3112
|
-
constructor(_store, _internalStateOperations, _stateContextFactory, _bootstrapper) {
|
|
3211
|
+
constructor(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
|
|
3113
3212
|
this._store = _store;
|
|
3213
|
+
this._internalErrorReporter = _internalErrorReporter;
|
|
3114
3214
|
this._internalStateOperations = _internalStateOperations;
|
|
3115
3215
|
this._stateContextFactory = _stateContextFactory;
|
|
3116
3216
|
this._bootstrapper = _bootstrapper;
|
|
@@ -3138,26 +3238,36 @@ class LifecycleStateManager {
|
|
|
3138
3238
|
() => !!results)), tap((/**
|
|
3139
3239
|
* @return {?}
|
|
3140
3240
|
*/
|
|
3141
|
-
() => this.
|
|
3241
|
+
() => this._invokeInitOnStates((/** @type {?} */ (results)).states))), mergeMap((/**
|
|
3142
3242
|
* @return {?}
|
|
3143
3243
|
*/
|
|
3144
3244
|
() => this._bootstrapper.appBootstrapped$)), filter((/**
|
|
3145
3245
|
* @param {?} appBootstrapped
|
|
3146
3246
|
* @return {?}
|
|
3147
3247
|
*/
|
|
3148
|
-
appBootstrapped => !!appBootstrapped)),
|
|
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$))
|
|
3149
3260
|
.subscribe((/**
|
|
3150
3261
|
* @return {?}
|
|
3151
3262
|
*/
|
|
3152
|
-
() => this.
|
|
3263
|
+
() => this._invokeBootstrapOnStates((/** @type {?} */ (results)).states)));
|
|
3153
3264
|
}
|
|
3154
3265
|
/**
|
|
3155
|
-
* Invoke the init function on the states.
|
|
3156
3266
|
* @private
|
|
3157
3267
|
* @param {?} mappedStores
|
|
3158
3268
|
* @return {?}
|
|
3159
3269
|
*/
|
|
3160
|
-
|
|
3270
|
+
_invokeInitOnStates(mappedStores) {
|
|
3161
3271
|
for (const mappedStore of mappedStores) {
|
|
3162
3272
|
/** @type {?} */
|
|
3163
3273
|
const instance = mappedStore.instance;
|
|
@@ -3186,12 +3296,11 @@ class LifecycleStateManager {
|
|
|
3186
3296
|
}
|
|
3187
3297
|
}
|
|
3188
3298
|
/**
|
|
3189
|
-
* Invoke the bootstrap function on the states.
|
|
3190
3299
|
* @private
|
|
3191
3300
|
* @param {?} mappedStores
|
|
3192
3301
|
* @return {?}
|
|
3193
3302
|
*/
|
|
3194
|
-
|
|
3303
|
+
_invokeBootstrapOnStates(mappedStores) {
|
|
3195
3304
|
for (const mappedStore of mappedStores) {
|
|
3196
3305
|
/** @type {?} */
|
|
3197
3306
|
const instance = mappedStore.instance;
|
|
@@ -3215,6 +3324,7 @@ LifecycleStateManager.decorators = [
|
|
|
3215
3324
|
/** @nocollapse */
|
|
3216
3325
|
LifecycleStateManager.ctorParameters = () => [
|
|
3217
3326
|
{ type: Store },
|
|
3327
|
+
{ type: InternalErrorReporter },
|
|
3218
3328
|
{ type: InternalStateOperations },
|
|
3219
3329
|
{ type: StateContextFactory },
|
|
3220
3330
|
{ type: NgxsBootstrapper }
|
|
@@ -3230,6 +3340,11 @@ if (false) {
|
|
|
3230
3340
|
* @private
|
|
3231
3341
|
*/
|
|
3232
3342
|
LifecycleStateManager.prototype._store;
|
|
3343
|
+
/**
|
|
3344
|
+
* @type {?}
|
|
3345
|
+
* @private
|
|
3346
|
+
*/
|
|
3347
|
+
LifecycleStateManager.prototype._internalErrorReporter;
|
|
3233
3348
|
/**
|
|
3234
3349
|
* @type {?}
|
|
3235
3350
|
* @private
|
|
@@ -3994,5 +4109,5 @@ if (false) {
|
|
|
3994
4109
|
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
3995
4110
|
*/
|
|
3996
4111
|
|
|
3997
|
-
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,
|
|
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 };
|
|
3998
4113
|
//# sourceMappingURL=ngxs-store.js.map
|