@ngxs/store 3.7.5 → 3.7.6-dev.master-a585f14

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.
Files changed (71) hide show
  1. package/bundles/ngxs-store-operators.umd.js +13 -12
  2. package/bundles/ngxs-store-operators.umd.js.map +1 -1
  3. package/bundles/ngxs-store-operators.umd.min.js +1 -1
  4. package/bundles/ngxs-store-operators.umd.min.js.map +1 -1
  5. package/bundles/ngxs-store.umd.js +611 -485
  6. package/bundles/ngxs-store.umd.js.map +1 -1
  7. package/bundles/ngxs-store.umd.min.js +1 -1
  8. package/bundles/ngxs-store.umd.min.js.map +1 -1
  9. package/esm2015/ngxs-store.js +6 -5
  10. package/esm2015/operators/append.js +3 -3
  11. package/esm2015/operators/compose.js +1 -1
  12. package/esm2015/operators/iif.js +1 -1
  13. package/esm2015/operators/index.js +1 -1
  14. package/esm2015/operators/insert-item.js +3 -3
  15. package/esm2015/operators/patch.js +4 -5
  16. package/esm2015/operators/update-item.js +7 -5
  17. package/esm2015/operators/utils.js +1 -1
  18. package/esm2015/src/actions-stream.js +16 -6
  19. package/esm2015/src/internal/dispatcher.js +14 -36
  20. package/esm2015/src/internal/error-handler.js +118 -0
  21. package/esm2015/src/internal/internals.js +2 -27
  22. package/esm2015/src/internal/lifecycle-state-manager.js +85 -38
  23. package/esm2015/src/internal/state-context-factory.js +1 -12
  24. package/esm2015/src/internal/state-factory.js +4 -4
  25. package/esm2015/src/operators/of-action.js +7 -1
  26. package/esm2015/src/public_api.js +1 -1
  27. package/esm5/ngxs-store.js +6 -5
  28. package/esm5/operators/append.js +3 -3
  29. package/esm5/operators/compose.js +1 -1
  30. package/esm5/operators/iif.js +1 -1
  31. package/esm5/operators/index.js +1 -1
  32. package/esm5/operators/insert-item.js +3 -3
  33. package/esm5/operators/patch.js +4 -5
  34. package/esm5/operators/update-item.js +7 -5
  35. package/esm5/operators/utils.js +1 -1
  36. package/esm5/src/actions-stream.js +22 -7
  37. package/esm5/src/internal/dispatcher.js +13 -37
  38. package/esm5/src/internal/error-handler.js +125 -0
  39. package/esm5/src/internal/internals.js +2 -27
  40. package/esm5/src/internal/lifecycle-state-manager.js +97 -50
  41. package/esm5/src/internal/state-context-factory.js +1 -12
  42. package/esm5/src/internal/state-factory.js +4 -4
  43. package/esm5/src/operators/of-action.js +7 -1
  44. package/esm5/src/public_api.js +1 -1
  45. package/fesm2015/ngxs-store-operators.js +13 -12
  46. package/fesm2015/ngxs-store-operators.js.map +1 -1
  47. package/fesm2015/ngxs-store.js +459 -343
  48. package/fesm2015/ngxs-store.js.map +1 -1
  49. package/fesm5/ngxs-store-operators.js +13 -12
  50. package/fesm5/ngxs-store-operators.js.map +1 -1
  51. package/fesm5/ngxs-store.js +608 -483
  52. package/fesm5/ngxs-store.js.map +1 -1
  53. package/ngxs-store.d.ts +6 -5
  54. package/ngxs-store.metadata.json +1 -1
  55. package/operators/append.d.ts +2 -2
  56. package/operators/compose.d.ts +2 -1
  57. package/operators/iif.d.ts +2 -2
  58. package/operators/index.d.ts +1 -1
  59. package/operators/insert-item.d.ts +2 -2
  60. package/operators/ngxs-store-operators.metadata.json +1 -1
  61. package/operators/patch.d.ts +2 -6
  62. package/operators/update-item.d.ts +2 -2
  63. package/operators/utils.d.ts +2 -1
  64. package/package.json +3 -3
  65. package/src/actions-stream.d.ts +4 -2
  66. package/src/internal/dispatcher.d.ts +3 -4
  67. package/src/internal/error-handler.d.ts +23 -0
  68. package/src/internal/internals.d.ts +1 -6
  69. package/src/internal/lifecycle-state-manager.d.ts +16 -15
  70. package/src/operators/of-action.d.ts +20 -7
  71. package/src/public_api.d.ts +1 -1
@@ -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
@@ -1130,6 +1106,7 @@ if (false) {
1130
1106
  * RxJS operator for selecting out specific actions.
1131
1107
  *
1132
1108
  * This will grab actions that have just been dispatched as well as actions that have completed
1109
+ * @template T
1133
1110
  * @param {...?} allowedTypes
1134
1111
  * @return {?}
1135
1112
  */
@@ -1140,6 +1117,7 @@ function ofAction(...allowedTypes) {
1140
1117
  * RxJS operator for selecting out specific actions.
1141
1118
  *
1142
1119
  * This will ONLY grab actions that have just been dispatched
1120
+ * @template T
1143
1121
  * @param {...?} allowedTypes
1144
1122
  * @return {?}
1145
1123
  */
@@ -1150,6 +1128,7 @@ function ofActionDispatched(...allowedTypes) {
1150
1128
  * RxJS operator for selecting out specific actions.
1151
1129
  *
1152
1130
  * This will ONLY grab actions that have just been successfully completed
1131
+ * @template T
1153
1132
  * @param {...?} allowedTypes
1154
1133
  * @return {?}
1155
1134
  */
@@ -1160,6 +1139,7 @@ function ofActionSuccessful(...allowedTypes) {
1160
1139
  * RxJS operator for selecting out specific actions.
1161
1140
  *
1162
1141
  * This will ONLY grab actions that have just been canceled
1142
+ * @template T
1163
1143
  * @param {...?} allowedTypes
1164
1144
  * @return {?}
1165
1145
  */
@@ -1170,6 +1150,7 @@ function ofActionCanceled(...allowedTypes) {
1170
1150
  * RxJS operator for selecting out specific actions.
1171
1151
  *
1172
1152
  * This will ONLY grab actions that have just been completed
1153
+ * @template T
1173
1154
  * @param {...?} allowedTypes
1174
1155
  * @return {?}
1175
1156
  */
@@ -1186,6 +1167,7 @@ function ofActionCompleted(...allowedTypes) {
1186
1167
  * RxJS operator for selecting out specific actions.
1187
1168
  *
1188
1169
  * This will ONLY grab actions that have just thrown an error
1170
+ * @template T
1189
1171
  * @param {...?} allowedTypes
1190
1172
  * @return {?}
1191
1173
  */
@@ -1481,6 +1463,12 @@ if (false) {
1481
1463
  * Internal Action stream that is emitted anytime an action is dispatched.
1482
1464
  */
1483
1465
  class InternalActions extends OrderedSubject {
1466
+ /**
1467
+ * @return {?}
1468
+ */
1469
+ ngOnDestroy() {
1470
+ this.complete();
1471
+ }
1484
1472
  }
1485
1473
  InternalActions.decorators = [
1486
1474
  { type: Injectable }
@@ -1491,22 +1479,25 @@ InternalActions.decorators = [
1491
1479
  * You can listen to this in services to react without stores.
1492
1480
  */
1493
1481
  class Actions extends Observable {
1494
- // This has to be `Observable<ActionContext>` in the v4. Because `InternalActions`
1495
- // is a `Subject<ActionContext>`. Leave it as `any` to avoid breaking changes
1496
1482
  /**
1497
1483
  * @param {?} internalActions$
1498
1484
  * @param {?} internalExecutionStrategy
1499
1485
  */
1500
1486
  constructor(internalActions$, internalExecutionStrategy) {
1487
+ /** @type {?} */
1488
+ const sharedInternalActions$ = internalActions$.pipe(leaveNgxs(internalExecutionStrategy),
1489
+ // The `InternalActions` subject emits outside of the Angular zone.
1490
+ // We have to re-enter the Angular zone for any incoming consumer.
1491
+ // The `share()` operator reduces the number of change detections.
1492
+ // This would call leave only once for any stream emission across all active subscribers.
1493
+ share());
1501
1494
  super((/**
1502
1495
  * @param {?} observer
1503
1496
  * @return {?}
1504
1497
  */
1505
1498
  observer => {
1506
1499
  /** @type {?} */
1507
- const childSubscription = internalActions$
1508
- .pipe(leaveNgxs(internalExecutionStrategy))
1509
- .subscribe({
1500
+ const childSubscription = sharedInternalActions$.subscribe({
1510
1501
  next: (/**
1511
1502
  * @param {?} ctx
1512
1503
  * @return {?}
@@ -1576,8 +1567,122 @@ const compose = (/**
1576
1567
  * @param {...?} nextArgs
1577
1568
  * @return {?}
1578
1569
  */
1579
- (...nextArgs) => compose(funcs)(...nextArgs)));
1580
- }));
1570
+ (...nextArgs) => compose(funcs)(...nextArgs)));
1571
+ }));
1572
+
1573
+ /**
1574
+ * @fileoverview added by tsickle
1575
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
1576
+ */
1577
+ /**
1578
+ * This operator is used for piping the observable result
1579
+ * from the `dispatch()`. It has a "smart" error handling
1580
+ * strategy that allows us to decide whether we propagate
1581
+ * errors to Angular's `ErrorHandler` or enable users to
1582
+ * handle them manually. We consider following cases:
1583
+ * 1) `store.dispatch()` (no subscribe) -> call `handleError()`
1584
+ * 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
1585
+ * 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
1586
+ * 4) `toPromise()` without `catch` -> do `handleError()`
1587
+ * 5) `toPromise()` with `catch` -> don't `handleError()`
1588
+ * @template T
1589
+ * @param {?} internalErrorReporter
1590
+ * @param {?} ngxsExecutionStrategy
1591
+ * @return {?}
1592
+ */
1593
+ function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
1594
+ return (/**
1595
+ * @param {?} source
1596
+ * @return {?}
1597
+ */
1598
+ (source) => {
1599
+ /** @type {?} */
1600
+ let subscribed = false;
1601
+ source.subscribe({
1602
+ error: (/**
1603
+ * @param {?} error
1604
+ * @return {?}
1605
+ */
1606
+ error => {
1607
+ // Do not trigger change detection for a microtask. This depends on the execution
1608
+ // strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
1609
+ // leaves the Angular zone.
1610
+ ngxsExecutionStrategy.enter((/**
1611
+ * @return {?}
1612
+ */
1613
+ () => Promise.resolve().then((/**
1614
+ * @return {?}
1615
+ */
1616
+ () => {
1617
+ if (!subscribed) {
1618
+ ngxsExecutionStrategy.leave((/**
1619
+ * @return {?}
1620
+ */
1621
+ () => internalErrorReporter.reportErrorSafely(error)));
1622
+ }
1623
+ }))));
1624
+ })
1625
+ });
1626
+ return new Observable((/**
1627
+ * @param {?} subscriber
1628
+ * @return {?}
1629
+ */
1630
+ subscriber => {
1631
+ subscribed = true;
1632
+ return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
1633
+ }));
1634
+ });
1635
+ }
1636
+ class InternalErrorReporter {
1637
+ /**
1638
+ * @param {?} _injector
1639
+ */
1640
+ constructor(_injector) {
1641
+ this._injector = _injector;
1642
+ /**
1643
+ * Will be set lazily to be backward compatible.
1644
+ */
1645
+ this._errorHandler = (/** @type {?} */ (null));
1646
+ }
1647
+ /**
1648
+ * @param {?} error
1649
+ * @return {?}
1650
+ */
1651
+ reportErrorSafely(error) {
1652
+ if (this._errorHandler === null) {
1653
+ this._errorHandler = this._injector.get(ErrorHandler);
1654
+ }
1655
+ // The `try-catch` is used to avoid handling the error twice. Suppose we call
1656
+ // `handleError` which re-throws the error internally. The re-thrown error will
1657
+ // be caught by zone.js which will then get to the `zone.onError.emit()` and the
1658
+ // `onError` subscriber will call `handleError` again.
1659
+ try {
1660
+ this._errorHandler.handleError(error);
1661
+ }
1662
+ catch (_a) { }
1663
+ }
1664
+ }
1665
+ InternalErrorReporter.decorators = [
1666
+ { type: Injectable, args: [{ providedIn: 'root' },] }
1667
+ ];
1668
+ /** @nocollapse */
1669
+ InternalErrorReporter.ctorParameters = () => [
1670
+ { type: Injector }
1671
+ ];
1672
+ /** @nocollapse */ InternalErrorReporter.ngInjectableDef = defineInjectable({ factory: function InternalErrorReporter_Factory() { return new InternalErrorReporter(inject(INJECTOR)); }, token: InternalErrorReporter, providedIn: "root" });
1673
+ if (false) {
1674
+ /**
1675
+ * Will be set lazily to be backward compatible.
1676
+ * @type {?}
1677
+ * @private
1678
+ */
1679
+ InternalErrorReporter.prototype._errorHandler;
1680
+ /**
1681
+ * @type {?}
1682
+ * @private
1683
+ */
1684
+ InternalErrorReporter.prototype._injector;
1685
+ }
1581
1686
 
1582
1687
  /**
1583
1688
  * @fileoverview added by tsickle
@@ -1692,20 +1797,20 @@ InternalDispatchedActionResults.decorators = [
1692
1797
  ];
1693
1798
  class InternalDispatcher {
1694
1799
  /**
1695
- * @param {?} _injector
1696
1800
  * @param {?} _actions
1697
1801
  * @param {?} _actionResults
1698
1802
  * @param {?} _pluginManager
1699
1803
  * @param {?} _stateStream
1700
1804
  * @param {?} _ngxsExecutionStrategy
1805
+ * @param {?} _internalErrorReporter
1701
1806
  */
1702
- constructor(_injector, _actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy) {
1703
- this._injector = _injector;
1807
+ constructor(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
1704
1808
  this._actions = _actions;
1705
1809
  this._actionResults = _actionResults;
1706
1810
  this._pluginManager = _pluginManager;
1707
1811
  this._stateStream = _stateStream;
1708
1812
  this._ngxsExecutionStrategy = _ngxsExecutionStrategy;
1813
+ this._internalErrorReporter = _internalErrorReporter;
1709
1814
  }
1710
1815
  /**
1711
1816
  * Dispatches event(s).
@@ -1718,24 +1823,7 @@ class InternalDispatcher {
1718
1823
  * @return {?}
1719
1824
  */
1720
1825
  () => 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));
1826
+ return result.pipe(ngxsErrorHandler(this._internalErrorReporter, this._ngxsExecutionStrategy));
1739
1827
  }
1740
1828
  /**
1741
1829
  * @private
@@ -1839,24 +1927,14 @@ InternalDispatcher.decorators = [
1839
1927
  ];
1840
1928
  /** @nocollapse */
1841
1929
  InternalDispatcher.ctorParameters = () => [
1842
- { type: Injector },
1843
1930
  { type: InternalActions },
1844
1931
  { type: InternalDispatchedActionResults },
1845
1932
  { type: PluginManager },
1846
1933
  { type: StateStream },
1847
- { type: InternalNgxsExecutionStrategy }
1934
+ { type: InternalNgxsExecutionStrategy },
1935
+ { type: InternalErrorReporter }
1848
1936
  ];
1849
1937
  if (false) {
1850
- /**
1851
- * @type {?}
1852
- * @private
1853
- */
1854
- InternalDispatcher.prototype._errorHandler;
1855
- /**
1856
- * @type {?}
1857
- * @private
1858
- */
1859
- InternalDispatcher.prototype._injector;
1860
1938
  /**
1861
1939
  * @type {?}
1862
1940
  * @private
@@ -1882,6 +1960,11 @@ if (false) {
1882
1960
  * @private
1883
1961
  */
1884
1962
  InternalDispatcher.prototype._ngxsExecutionStrategy;
1963
+ /**
1964
+ * @type {?}
1965
+ * @private
1966
+ */
1967
+ InternalDispatcher.prototype._internalErrorReporter;
1885
1968
  }
1886
1969
 
1887
1970
  /**
@@ -2109,16 +2192,6 @@ class StateContextFactory {
2109
2192
  function setStateValue(currentAppState, newValue) {
2110
2193
  /** @type {?} */
2111
2194
  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
2195
  root.setState(newAppState);
2123
2196
  return newAppState;
2124
2197
  // In doing this refactoring I noticed that there is a 'bug' where the
@@ -2401,7 +2474,7 @@ class StateFactory {
2401
2474
  if (Array.isArray(defaults)) {
2402
2475
  value = defaults.slice();
2403
2476
  }
2404
- else if (isObject$1(defaults)) {
2477
+ else if (isObject(defaults)) {
2405
2478
  value = Object.assign({}, defaults);
2406
2479
  }
2407
2480
  else if (defaults === undefined) {
@@ -2560,7 +2633,7 @@ class StateFactory {
2560
2633
  if (result instanceof Promise) {
2561
2634
  result = from(result);
2562
2635
  }
2563
- if (result instanceof Observable) {
2636
+ if (isObservable(result)) {
2564
2637
  // If this observable has been completed w/o emitting
2565
2638
  // any value then we wouldn't want to complete the whole chain
2566
2639
  // of actions. Since if any observable completes then
@@ -2577,7 +2650,7 @@ class StateFactory {
2577
2650
  if (value instanceof Promise) {
2578
2651
  return from(value);
2579
2652
  }
2580
- if (value instanceof Observable) {
2653
+ if (isObservable(value)) {
2581
2654
  return value;
2582
2655
  }
2583
2656
  return of(value);
@@ -2731,129 +2804,6 @@ if (false) {
2731
2804
  StateFactory.prototype._initialState;
2732
2805
  }
2733
2806
 
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
2807
  /**
2858
2808
  * @fileoverview added by tsickle
2859
2809
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -3251,6 +3201,172 @@ if (false) {
3251
3201
  Store.prototype._stateFactory;
3252
3202
  }
3253
3203
 
3204
+ /**
3205
+ * @fileoverview added by tsickle
3206
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3207
+ */
3208
+ class LifecycleStateManager {
3209
+ /**
3210
+ * @param {?} _store
3211
+ * @param {?} _internalErrorReporter
3212
+ * @param {?} _internalStateOperations
3213
+ * @param {?} _stateContextFactory
3214
+ * @param {?} _bootstrapper
3215
+ */
3216
+ constructor(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3217
+ this._store = _store;
3218
+ this._internalErrorReporter = _internalErrorReporter;
3219
+ this._internalStateOperations = _internalStateOperations;
3220
+ this._stateContextFactory = _stateContextFactory;
3221
+ this._bootstrapper = _bootstrapper;
3222
+ this._destroy$ = new Subject();
3223
+ }
3224
+ /**
3225
+ * @return {?}
3226
+ */
3227
+ ngOnDestroy() {
3228
+ this._destroy$.next();
3229
+ }
3230
+ /**
3231
+ * @template T
3232
+ * @param {?} action
3233
+ * @param {?} results
3234
+ * @return {?}
3235
+ */
3236
+ ngxsBootstrap(action, results) {
3237
+ this._internalStateOperations
3238
+ .getRootStateOperations()
3239
+ .dispatch(action)
3240
+ .pipe(filter((/**
3241
+ * @return {?}
3242
+ */
3243
+ () => !!results)), tap((/**
3244
+ * @return {?}
3245
+ */
3246
+ () => this._invokeInitOnStates((/** @type {?} */ (results)).states))), mergeMap((/**
3247
+ * @return {?}
3248
+ */
3249
+ () => this._bootstrapper.appBootstrapped$)), filter((/**
3250
+ * @param {?} appBootstrapped
3251
+ * @return {?}
3252
+ */
3253
+ appBootstrapped => !!appBootstrapped)), catchError((/**
3254
+ * @param {?} error
3255
+ * @return {?}
3256
+ */
3257
+ error => {
3258
+ // The `SafeSubscriber` (which is used by most RxJS operators) re-throws
3259
+ // errors asynchronously (`setTimeout(() => { throw error })`). This might
3260
+ // break existing user's code or unit tests. We catch the error manually to
3261
+ // be backward compatible with the old behavior.
3262
+ this._internalErrorReporter.reportErrorSafely(error);
3263
+ return EMPTY;
3264
+ })), takeUntil(this._destroy$))
3265
+ .subscribe((/**
3266
+ * @return {?}
3267
+ */
3268
+ () => this._invokeBootstrapOnStates((/** @type {?} */ (results)).states)));
3269
+ }
3270
+ /**
3271
+ * @private
3272
+ * @param {?} mappedStores
3273
+ * @return {?}
3274
+ */
3275
+ _invokeInitOnStates(mappedStores) {
3276
+ for (const mappedStore of mappedStores) {
3277
+ /** @type {?} */
3278
+ const instance = mappedStore.instance;
3279
+ if (instance.ngxsOnChanges) {
3280
+ this._store
3281
+ .select((/**
3282
+ * @param {?} state
3283
+ * @return {?}
3284
+ */
3285
+ state => getValue(state, mappedStore.path)))
3286
+ .pipe(startWith(undefined), pairwise(), takeUntil(this._destroy$))
3287
+ .subscribe((/**
3288
+ * @param {?} __0
3289
+ * @return {?}
3290
+ */
3291
+ ([previousValue, currentValue]) => {
3292
+ /** @type {?} */
3293
+ const change = new NgxsSimpleChange(previousValue, currentValue, !mappedStore.isInitialised);
3294
+ (/** @type {?} */ (instance.ngxsOnChanges))(change);
3295
+ }));
3296
+ }
3297
+ if (instance.ngxsOnInit) {
3298
+ instance.ngxsOnInit(this._getStateContext(mappedStore));
3299
+ }
3300
+ mappedStore.isInitialised = true;
3301
+ }
3302
+ }
3303
+ /**
3304
+ * @private
3305
+ * @param {?} mappedStores
3306
+ * @return {?}
3307
+ */
3308
+ _invokeBootstrapOnStates(mappedStores) {
3309
+ for (const mappedStore of mappedStores) {
3310
+ /** @type {?} */
3311
+ const instance = mappedStore.instance;
3312
+ if (instance.ngxsAfterBootstrap) {
3313
+ instance.ngxsAfterBootstrap(this._getStateContext(mappedStore));
3314
+ }
3315
+ }
3316
+ }
3317
+ /**
3318
+ * @private
3319
+ * @param {?} mappedStore
3320
+ * @return {?}
3321
+ */
3322
+ _getStateContext(mappedStore) {
3323
+ return this._stateContextFactory.createStateContext(mappedStore);
3324
+ }
3325
+ }
3326
+ LifecycleStateManager.decorators = [
3327
+ { type: Injectable }
3328
+ ];
3329
+ /** @nocollapse */
3330
+ LifecycleStateManager.ctorParameters = () => [
3331
+ { type: Store },
3332
+ { type: InternalErrorReporter },
3333
+ { type: InternalStateOperations },
3334
+ { type: StateContextFactory },
3335
+ { type: NgxsBootstrapper }
3336
+ ];
3337
+ if (false) {
3338
+ /**
3339
+ * @type {?}
3340
+ * @private
3341
+ */
3342
+ LifecycleStateManager.prototype._destroy$;
3343
+ /**
3344
+ * @type {?}
3345
+ * @private
3346
+ */
3347
+ LifecycleStateManager.prototype._store;
3348
+ /**
3349
+ * @type {?}
3350
+ * @private
3351
+ */
3352
+ LifecycleStateManager.prototype._internalErrorReporter;
3353
+ /**
3354
+ * @type {?}
3355
+ * @private
3356
+ */
3357
+ LifecycleStateManager.prototype._internalStateOperations;
3358
+ /**
3359
+ * @type {?}
3360
+ * @private
3361
+ */
3362
+ LifecycleStateManager.prototype._stateContextFactory;
3363
+ /**
3364
+ * @type {?}
3365
+ * @private
3366
+ */
3367
+ LifecycleStateManager.prototype._bootstrapper;
3368
+ }
3369
+
3254
3370
  /**
3255
3371
  * @fileoverview added by tsickle
3256
3372
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -3998,5 +4114,5 @@ if (false) {
3998
4114
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3999
4115
  */
4000
4116
 
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 };
4117
+ 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
4118
  //# sourceMappingURL=ngxs-store.js.map