@ngxs/store 3.6.2 → 3.7.0

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 (43) hide show
  1. package/README.md +2 -2
  2. package/bundles/ngxs-store-operators.umd.js +36 -14
  3. package/bundles/ngxs-store-operators.umd.js.map +1 -1
  4. package/bundles/ngxs-store-operators.umd.min.js +10 -10
  5. package/bundles/ngxs-store-operators.umd.min.js.map +1 -1
  6. package/bundles/ngxs-store.umd.js +76 -44
  7. package/bundles/ngxs-store.umd.js.map +1 -1
  8. package/bundles/ngxs-store.umd.min.js +11 -11
  9. package/bundles/ngxs-store.umd.min.js.map +1 -1
  10. package/esm2015/src/decorators/select/select.js +1 -2
  11. package/esm2015/src/decorators/select/symbols.js +1 -1
  12. package/esm2015/src/internal/dispatcher.js +9 -1
  13. package/esm2015/src/internal/internals.js +3 -3
  14. package/esm2015/src/internal/state-factory.js +12 -3
  15. package/esm2015/src/internal/state-operations.js +3 -3
  16. package/esm2015/src/ivy/ensure-state-class-is-injectable.js +3 -3
  17. package/esm2015/src/ivy/ivy-enabled-in-dev-mode.js +6 -16
  18. package/esm2015/src/operators/of-action.js +6 -3
  19. package/esm2015/src/store.js +4 -4
  20. package/esm2015/src/utils/utils.js +4 -2
  21. package/esm5/src/decorators/select/select.js +1 -2
  22. package/esm5/src/decorators/select/symbols.js +1 -1
  23. package/esm5/src/internal/dispatcher.js +9 -1
  24. package/esm5/src/internal/internals.js +3 -3
  25. package/esm5/src/internal/state-factory.js +12 -3
  26. package/esm5/src/internal/state-operations.js +3 -3
  27. package/esm5/src/ivy/ensure-state-class-is-injectable.js +3 -3
  28. package/esm5/src/ivy/ivy-enabled-in-dev-mode.js +6 -16
  29. package/esm5/src/operators/of-action.js +6 -3
  30. package/esm5/src/store.js +5 -5
  31. package/esm5/src/utils/utils.js +4 -2
  32. package/fesm2015/ngxs-store.js +39 -29
  33. package/fesm2015/ngxs-store.js.map +1 -1
  34. package/fesm5/ngxs-store.js +40 -30
  35. package/fesm5/ngxs-store.js.map +1 -1
  36. package/ngxs-store.metadata.json +1 -1
  37. package/package.json +3 -3
  38. package/src/decorators/select/select.d.ts +1 -2
  39. package/src/decorators/select/symbols.d.ts +0 -4
  40. package/src/internal/internals.d.ts +1 -1
  41. package/src/ivy/ivy-enabled-in-dev-mode.d.ts +2 -2
  42. package/src/operators/of-action.d.ts +9 -8
  43. package/src/store.d.ts +1 -1
@@ -488,7 +488,9 @@ function getActionTypeFromInstance(action) {
488
488
  if (action.constructor && action.constructor.type) {
489
489
  return action.constructor.type;
490
490
  }
491
- return action.type;
491
+ else {
492
+ return action.type;
493
+ }
492
494
  }
493
495
  /**
494
496
  * Matches a action
@@ -600,10 +602,10 @@ if (false) {
600
602
  */
601
603
  StateOperations.prototype.setState = function (val) { };
602
604
  /**
603
- * @param {?} actions
605
+ * @param {?} actionOrActions
604
606
  * @return {?}
605
607
  */
606
- StateOperations.prototype.dispatch = function (actions) { };
608
+ StateOperations.prototype.dispatch = function (actionOrActions) { };
607
609
  }
608
610
  /**
609
611
  * @record
@@ -1164,13 +1166,16 @@ function ofActionErrored() {
1164
1166
  return ofActionOperator(allowedTypes, ["ERRORED" /* Errored */]);
1165
1167
  }
1166
1168
  /**
1167
- * @template T
1168
1169
  * @param {?} allowedTypes
1169
1170
  * @param {?=} statuses
1170
1171
  * @param {?=} mapOperator
1171
1172
  * @return {?}
1172
1173
  */
1173
- function ofActionOperator(allowedTypes, statuses, mapOperator) {
1174
+ function ofActionOperator(allowedTypes, statuses,
1175
+ // This actually could've been `OperatorFunction<ActionContext, ActionCompletion | any>`,
1176
+ // since it maps either to `ctx.action` OR to `ActionCompletion`. But `ActionCompleteion | any`
1177
+ // defaults to `any`, thus there is no sense from union type.
1178
+ mapOperator) {
1174
1179
  if (mapOperator === void 0) { mapOperator = mapAction; }
1175
1180
  /** @type {?} */
1176
1181
  var allowedMap = createAllowedActionTypesMap(allowedTypes);
@@ -1800,6 +1805,13 @@ var InternalDispatcher = /** @class */ (function () {
1800
1805
  function (action) {
1801
1806
  var _this = this;
1802
1807
  /** @type {?} */
1808
+ var type = getActionTypeFromInstance(action);
1809
+ if (!type) {
1810
+ /** @type {?} */
1811
+ var error = new Error("This action doesn't have a type property: " + action.constructor.name);
1812
+ return throwError(error);
1813
+ }
1814
+ /** @type {?} */
1803
1815
  var prevState = this._stateStream.getValue();
1804
1816
  /** @type {?} */
1805
1817
  var plugins = this._pluginManager.plugins;
@@ -2090,10 +2102,10 @@ var InternalStateOperations = /** @class */ (function () {
2090
2102
  */
2091
2103
  function (newState) { return _this._stateStream.next(newState); }),
2092
2104
  dispatch: (/**
2093
- * @param {?} actions
2105
+ * @param {?} actionOrActions
2094
2106
  * @return {?}
2095
2107
  */
2096
- function (actions) { return _this._dispatcher.dispatch(actions); })
2108
+ function (actionOrActions) { return _this._dispatcher.dispatch(actionOrActions); })
2097
2109
  };
2098
2110
  if (this._config.developmentMode) {
2099
2111
  return this.ensureStateAndActionsAreImmutable(rootStateOperations);
@@ -2721,13 +2733,13 @@ var StateFactory = /** @class */ (function () {
2721
2733
  function (actions$, action) {
2722
2734
  var e_2, _a, e_3, _b;
2723
2735
  /** @type {?} */
2736
+ var type = (/** @type {?} */ (getActionTypeFromInstance(action)));
2737
+ /** @type {?} */
2724
2738
  var results = [];
2725
2739
  try {
2726
2740
  for (var _c = __values(this.states), _d = _c.next(); !_d.done; _d = _c.next()) {
2727
2741
  var metadata = _d.value;
2728
2742
  /** @type {?} */
2729
- var type = (/** @type {?} */ (getActionTypeFromInstance(action)));
2730
- /** @type {?} */
2731
2743
  var actionMetas = metadata.actions[type];
2732
2744
  if (actionMetas) {
2733
2745
  try {
@@ -2742,6 +2754,15 @@ var StateFactory = /** @class */ (function () {
2742
2754
  result = from(result);
2743
2755
  }
2744
2756
  if (result instanceof Observable) {
2757
+ // If this observable has been completed w/o emitting
2758
+ // any value then we wouldn't want to complete the whole chain
2759
+ // of actions. Since if any observable completes then
2760
+ // action will be canceled.
2761
+ // For instance if any action handler would've had such statement:
2762
+ // `handler(ctx) { return EMPTY; }`
2763
+ // then the action will be canceled.
2764
+ // See https://github.com/ngxs/store/issues/1568
2765
+ result = result.pipe(defaultIfEmpty({}));
2745
2766
  if (actionMeta.options.cancelUncompleted) {
2746
2767
  // todo: ofActionDispatched should be used with action class
2747
2768
  result = result.pipe(takeUntil(actions$.pipe(ofActionDispatched((/** @type {?} */ (action))))));
@@ -3355,16 +3376,16 @@ var Store = /** @class */ (function () {
3355
3376
  */
3356
3377
  /**
3357
3378
  * Dispatches event(s).
3358
- * @param {?} event
3379
+ * @param {?} actionOrActions
3359
3380
  * @return {?}
3360
3381
  */
3361
3382
  Store.prototype.dispatch = /**
3362
3383
  * Dispatches event(s).
3363
- * @param {?} event
3384
+ * @param {?} actionOrActions
3364
3385
  * @return {?}
3365
3386
  */
3366
- function (event) {
3367
- return this._internalStateOperations.getRootStateOperations().dispatch(event);
3387
+ function (actionOrActions) {
3388
+ return this._internalStateOperations.getRootStateOperations().dispatch(actionOrActions);
3368
3389
  };
3369
3390
  /**
3370
3391
  * @param {?} selector
@@ -3639,12 +3660,8 @@ if (false) {
3639
3660
  * @fileoverview added by tsickle
3640
3661
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3641
3662
  */
3642
- /**
3643
- * Keep it as a single `const` variable since this `ReplaySubject`
3644
- * will be private and accessible only within this file.
3645
- * @type {?}
3646
- */
3647
- var _ivyEnabledInDevMode$ = new ReplaySubject(1);
3663
+ /** @type {?} */
3664
+ var ivyEnabledInDevMode$ = new ReplaySubject(1);
3648
3665
  /**
3649
3666
  * Ivy exposes helper functions to the global `window.ng` object.
3650
3667
  * Those functions are `getComponent, getContext,
@@ -3667,20 +3684,14 @@ function setIvyEnabledInDevMode() {
3667
3684
  var _viewEngineEnabled = !!ng.probe && !!ng.coreTokens;
3668
3685
  /** @type {?} */
3669
3686
  var _ivyEnabledInDevMode = !_viewEngineEnabled && isDevMode();
3670
- _ivyEnabledInDevMode$.next(_ivyEnabledInDevMode);
3687
+ ivyEnabledInDevMode$.next(_ivyEnabledInDevMode);
3671
3688
  }
3672
3689
  catch (_a) {
3673
- _ivyEnabledInDevMode$.next(false);
3690
+ ivyEnabledInDevMode$.next(false);
3674
3691
  }
3675
3692
  finally {
3676
- _ivyEnabledInDevMode$.complete();
3693
+ ivyEnabledInDevMode$.complete();
3677
3694
  }
3678
- }
3679
- /**
3680
- * @return {?}
3681
- */
3682
- function ivyEnabledInDevMode() {
3683
- return _ivyEnabledInDevMode$.asObservable();
3684
3695
  }
3685
3696
 
3686
3697
  /**
@@ -4038,7 +4049,7 @@ function ensureStateClassIsInjectable(target) {
4038
4049
  // AOT mode because this property is added before runtime. If an application is running in
4039
4050
  // JIT mode then this property can be added by the `@Injectable()` decorator. The `@Injectable()`
4040
4051
  // decorator has to go after the `@State()` decorator, thus we prevent users from unwanted DI errors.
4041
- ivyEnabledInDevMode().subscribe((/**
4052
+ ivyEnabledInDevMode$.subscribe((/**
4042
4053
  * @param {?} _ivyEnabledInDevMode
4043
4054
  * @return {?}
4044
4055
  */
@@ -4189,7 +4200,6 @@ function Select(rawSelector) {
4189
4200
  paths[_i - 1] = arguments[_i];
4190
4201
  }
4191
4202
  return (/**
4192
- * @template U, K
4193
4203
  * @param {?} target
4194
4204
  * @param {?} key
4195
4205
  * @return {?}