@ngxs/store 3.7.5-dev.master-708406e → 3.7.5-dev.master-0da56b4

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.
@@ -2,7 +2,7 @@ import { NgZone, Injectable, Inject, PLATFORM_ID, defineInjectable, inject, Inje
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';
5
- import { filter, map, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, tap, observeOn, distinctUntilChanged } from 'rxjs/operators';
5
+ import { filter, map, 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
@@ -1487,6 +1463,12 @@ if (false) {
1487
1463
  * Internal Action stream that is emitted anytime an action is dispatched.
1488
1464
  */
1489
1465
  class InternalActions extends OrderedSubject {
1466
+ /**
1467
+ * @return {?}
1468
+ */
1469
+ ngOnDestroy() {
1470
+ this.complete();
1471
+ }
1490
1472
  }
1491
1473
  InternalActions.decorators = [
1492
1474
  { type: Injectable }
@@ -2113,16 +2095,6 @@ class StateContextFactory {
2113
2095
  function setStateValue(currentAppState, newValue) {
2114
2096
  /** @type {?} */
2115
2097
  const newAppState = setValue(currentAppState, mappedStore.path, newValue);
2116
- /** @type {?} */
2117
- const instance = mappedStore.instance;
2118
- if (instance.ngxsOnChanges) {
2119
- /** @type {?} */
2120
- const change = getStateDiffChanges(mappedStore, {
2121
- currentAppState,
2122
- newAppState
2123
- });
2124
- instance.ngxsOnChanges(change);
2125
- }
2126
2098
  root.setState(newAppState);
2127
2099
  return newAppState;
2128
2100
  // In doing this refactoring I noticed that there is a 'bug' where the
@@ -2405,7 +2377,7 @@ class StateFactory {
2405
2377
  if (Array.isArray(defaults)) {
2406
2378
  value = defaults.slice();
2407
2379
  }
2408
- else if (isObject$1(defaults)) {
2380
+ else if (isObject(defaults)) {
2409
2381
  value = Object.assign({}, defaults);
2410
2382
  }
2411
2383
  else if (defaults === undefined) {
@@ -2735,129 +2707,6 @@ if (false) {
2735
2707
  StateFactory.prototype._initialState;
2736
2708
  }
2737
2709
 
2738
- /**
2739
- * @fileoverview added by tsickle
2740
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
2741
- */
2742
- class LifecycleStateManager {
2743
- /**
2744
- * @param {?} internalStateOperations
2745
- * @param {?} stateContextFactory
2746
- * @param {?} bootstrapper
2747
- */
2748
- constructor(internalStateOperations, stateContextFactory, bootstrapper) {
2749
- this.internalStateOperations = internalStateOperations;
2750
- this.stateContextFactory = stateContextFactory;
2751
- this.bootstrapper = bootstrapper;
2752
- }
2753
- /**
2754
- * @template T
2755
- * @param {?} action
2756
- * @param {?} results
2757
- * @return {?}
2758
- */
2759
- ngxsBootstrap(action, results) {
2760
- this.internalStateOperations
2761
- .getRootStateOperations()
2762
- .dispatch(action)
2763
- .pipe(filter((/**
2764
- * @return {?}
2765
- */
2766
- () => !!results)), tap((/**
2767
- * @return {?}
2768
- */
2769
- () => this.invokeInit((/** @type {?} */ (results)).states))), mergeMap((/**
2770
- * @return {?}
2771
- */
2772
- () => this.bootstrapper.appBootstrapped$)), filter((/**
2773
- * @param {?} appBootstrapped
2774
- * @return {?}
2775
- */
2776
- appBootstrapped => !!appBootstrapped)))
2777
- .subscribe((/**
2778
- * @return {?}
2779
- */
2780
- () => this.invokeBootstrap((/** @type {?} */ (results)).states)));
2781
- }
2782
- /**
2783
- * Invoke the init function on the states.
2784
- * @param {?} mappedStores
2785
- * @return {?}
2786
- */
2787
- invokeInit(mappedStores) {
2788
- for (const mappedStore of mappedStores) {
2789
- /** @type {?} */
2790
- const instance = mappedStore.instance;
2791
- if (instance.ngxsOnChanges) {
2792
- /** @type {?} */
2793
- const currentAppState = {};
2794
- /** @type {?} */
2795
- const newAppState = this.internalStateOperations
2796
- .getRootStateOperations()
2797
- .getState();
2798
- /** @type {?} */
2799
- const firstDiffChange = getStateDiffChanges(mappedStore, {
2800
- currentAppState,
2801
- newAppState
2802
- });
2803
- instance.ngxsOnChanges(firstDiffChange);
2804
- }
2805
- if (instance.ngxsOnInit) {
2806
- instance.ngxsOnInit(this.getStateContext(mappedStore));
2807
- }
2808
- mappedStore.isInitialised = true;
2809
- }
2810
- }
2811
- /**
2812
- * Invoke the bootstrap function on the states.
2813
- * @param {?} mappedStores
2814
- * @return {?}
2815
- */
2816
- invokeBootstrap(mappedStores) {
2817
- for (const mappedStore of mappedStores) {
2818
- /** @type {?} */
2819
- const instance = mappedStore.instance;
2820
- if (instance.ngxsAfterBootstrap) {
2821
- instance.ngxsAfterBootstrap(this.getStateContext(mappedStore));
2822
- }
2823
- }
2824
- }
2825
- /**
2826
- * @private
2827
- * @param {?} mappedStore
2828
- * @return {?}
2829
- */
2830
- getStateContext(mappedStore) {
2831
- return this.stateContextFactory.createStateContext(mappedStore);
2832
- }
2833
- }
2834
- LifecycleStateManager.decorators = [
2835
- { type: Injectable }
2836
- ];
2837
- /** @nocollapse */
2838
- LifecycleStateManager.ctorParameters = () => [
2839
- { type: InternalStateOperations },
2840
- { type: StateContextFactory },
2841
- { type: NgxsBootstrapper }
2842
- ];
2843
- if (false) {
2844
- /**
2845
- * @type {?}
2846
- * @private
2847
- */
2848
- LifecycleStateManager.prototype.internalStateOperations;
2849
- /**
2850
- * @type {?}
2851
- * @private
2852
- */
2853
- LifecycleStateManager.prototype.stateContextFactory;
2854
- /**
2855
- * @type {?}
2856
- * @private
2857
- */
2858
- LifecycleStateManager.prototype.bootstrapper;
2859
- }
2860
-
2861
2710
  /**
2862
2711
  * @fileoverview added by tsickle
2863
2712
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -3255,6 +3104,155 @@ if (false) {
3255
3104
  Store.prototype._stateFactory;
3256
3105
  }
3257
3106
 
3107
+ /**
3108
+ * @fileoverview added by tsickle
3109
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3110
+ */
3111
+ class LifecycleStateManager {
3112
+ /**
3113
+ * @param {?} _store
3114
+ * @param {?} _internalStateOperations
3115
+ * @param {?} _stateContextFactory
3116
+ * @param {?} _bootstrapper
3117
+ */
3118
+ constructor(_store, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3119
+ this._store = _store;
3120
+ this._internalStateOperations = _internalStateOperations;
3121
+ this._stateContextFactory = _stateContextFactory;
3122
+ this._bootstrapper = _bootstrapper;
3123
+ this._destroy$ = new Subject();
3124
+ }
3125
+ /**
3126
+ * @return {?}
3127
+ */
3128
+ ngOnDestroy() {
3129
+ this._destroy$.next();
3130
+ }
3131
+ /**
3132
+ * @template T
3133
+ * @param {?} action
3134
+ * @param {?} results
3135
+ * @return {?}
3136
+ */
3137
+ ngxsBootstrap(action, results) {
3138
+ this._internalStateOperations
3139
+ .getRootStateOperations()
3140
+ .dispatch(action)
3141
+ .pipe(filter((/**
3142
+ * @return {?}
3143
+ */
3144
+ () => !!results)), tap((/**
3145
+ * @return {?}
3146
+ */
3147
+ () => this._invokeInit((/** @type {?} */ (results)).states))), mergeMap((/**
3148
+ * @return {?}
3149
+ */
3150
+ () => this._bootstrapper.appBootstrapped$)), filter((/**
3151
+ * @param {?} appBootstrapped
3152
+ * @return {?}
3153
+ */
3154
+ appBootstrapped => !!appBootstrapped)), takeUntil(this._destroy$))
3155
+ .subscribe((/**
3156
+ * @return {?}
3157
+ */
3158
+ () => this._invokeBootstrap((/** @type {?} */ (results)).states)));
3159
+ }
3160
+ /**
3161
+ * Invoke the init function on the states.
3162
+ * @private
3163
+ * @param {?} mappedStores
3164
+ * @return {?}
3165
+ */
3166
+ _invokeInit(mappedStores) {
3167
+ for (const mappedStore of mappedStores) {
3168
+ /** @type {?} */
3169
+ const instance = mappedStore.instance;
3170
+ if (instance.ngxsOnChanges) {
3171
+ this._store
3172
+ .select((/**
3173
+ * @param {?} state
3174
+ * @return {?}
3175
+ */
3176
+ state => getValue(state, mappedStore.path)))
3177
+ .pipe(startWith(undefined), pairwise(), takeUntil(this._destroy$))
3178
+ .subscribe((/**
3179
+ * @param {?} __0
3180
+ * @return {?}
3181
+ */
3182
+ ([previousValue, currentValue]) => {
3183
+ /** @type {?} */
3184
+ const change = new NgxsSimpleChange(previousValue, currentValue, !mappedStore.isInitialised);
3185
+ (/** @type {?} */ (instance.ngxsOnChanges))(change);
3186
+ }));
3187
+ }
3188
+ if (instance.ngxsOnInit) {
3189
+ instance.ngxsOnInit(this._getStateContext(mappedStore));
3190
+ }
3191
+ mappedStore.isInitialised = true;
3192
+ }
3193
+ }
3194
+ /**
3195
+ * Invoke the bootstrap function on the states.
3196
+ * @private
3197
+ * @param {?} mappedStores
3198
+ * @return {?}
3199
+ */
3200
+ _invokeBootstrap(mappedStores) {
3201
+ for (const mappedStore of mappedStores) {
3202
+ /** @type {?} */
3203
+ const instance = mappedStore.instance;
3204
+ if (instance.ngxsAfterBootstrap) {
3205
+ instance.ngxsAfterBootstrap(this._getStateContext(mappedStore));
3206
+ }
3207
+ }
3208
+ }
3209
+ /**
3210
+ * @private
3211
+ * @param {?} mappedStore
3212
+ * @return {?}
3213
+ */
3214
+ _getStateContext(mappedStore) {
3215
+ return this._stateContextFactory.createStateContext(mappedStore);
3216
+ }
3217
+ }
3218
+ LifecycleStateManager.decorators = [
3219
+ { type: Injectable }
3220
+ ];
3221
+ /** @nocollapse */
3222
+ LifecycleStateManager.ctorParameters = () => [
3223
+ { type: Store },
3224
+ { type: InternalStateOperations },
3225
+ { type: StateContextFactory },
3226
+ { type: NgxsBootstrapper }
3227
+ ];
3228
+ if (false) {
3229
+ /**
3230
+ * @type {?}
3231
+ * @private
3232
+ */
3233
+ LifecycleStateManager.prototype._destroy$;
3234
+ /**
3235
+ * @type {?}
3236
+ * @private
3237
+ */
3238
+ LifecycleStateManager.prototype._store;
3239
+ /**
3240
+ * @type {?}
3241
+ * @private
3242
+ */
3243
+ LifecycleStateManager.prototype._internalStateOperations;
3244
+ /**
3245
+ * @type {?}
3246
+ * @private
3247
+ */
3248
+ LifecycleStateManager.prototype._stateContextFactory;
3249
+ /**
3250
+ * @type {?}
3251
+ * @private
3252
+ */
3253
+ LifecycleStateManager.prototype._bootstrapper;
3254
+ }
3255
+
3258
3256
  /**
3259
3257
  * @fileoverview added by tsickle
3260
3258
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc