@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.
@@ -1,9 +1,9 @@
1
- import { __assign, __spread, __extends, __values } from 'tslib';
1
+ import { __assign, __spread, __extends, __values, __read } from 'tslib';
2
2
  import { NgZone, Injectable, Inject, PLATFORM_ID, defineInjectable, inject, InjectionToken, INJECTOR, ɵglobal, Optional, SkipSelf, ErrorHandler, Injector, ɵivyEnabled, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
3
3
  import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, NGXS_STATE_CONTEXT_FACTORY, NGXS_STATE_FACTORY, InitialState } from '@ngxs/store/internals';
4
4
  import { isPlatformServer } from '@angular/common';
5
5
  import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable, queueScheduler } from 'rxjs';
6
- import { filter, map, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, tap, observeOn, distinctUntilChanged } from 'rxjs/operators';
6
+ import { filter, map, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, observeOn, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
7
7
 
8
8
  /**
9
9
  * @fileoverview added by tsickle
@@ -512,156 +512,6 @@ if (false) {
512
512
  NgxsExecutionStrategy.prototype.leave = function (func) { };
513
513
  }
514
514
 
515
- /**
516
- * @fileoverview added by tsickle
517
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
518
- */
519
- /**
520
- * Returns the type from an action instance/class.
521
- * @ignore
522
- * @param {?} action
523
- * @return {?}
524
- */
525
- function getActionTypeFromInstance(action) {
526
- if (action.constructor && action.constructor.type) {
527
- return action.constructor.type;
528
- }
529
- else {
530
- return action.type;
531
- }
532
- }
533
- /**
534
- * Matches a action
535
- * @ignore
536
- * @param {?} action1
537
- * @return {?}
538
- */
539
- function actionMatcher(action1) {
540
- /** @type {?} */
541
- var type1 = getActionTypeFromInstance(action1);
542
- return (/**
543
- * @param {?} action2
544
- * @return {?}
545
- */
546
- function (action2) {
547
- return type1 === getActionTypeFromInstance(action2);
548
- });
549
- }
550
- /**
551
- * Set a deeply nested value. Example:
552
- *
553
- * setValue({ foo: { bar: { eat: false } } },
554
- * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
555
- *
556
- * While it traverses it also creates new objects from top down.
557
- *
558
- * @ignore
559
- * @type {?}
560
- */
561
- var setValue = (/**
562
- * @param {?} obj
563
- * @param {?} prop
564
- * @param {?} val
565
- * @return {?}
566
- */
567
- function (obj, prop, val) {
568
- obj = __assign({}, obj);
569
- /** @type {?} */
570
- var split = prop.split('.');
571
- /** @type {?} */
572
- var lastIndex = split.length - 1;
573
- split.reduce((/**
574
- * @param {?} acc
575
- * @param {?} part
576
- * @param {?} index
577
- * @return {?}
578
- */
579
- function (acc, part, index) {
580
- if (index === lastIndex) {
581
- acc[part] = val;
582
- }
583
- else {
584
- acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : __assign({}, acc[part]);
585
- }
586
- return acc && acc[part];
587
- }), obj);
588
- return obj;
589
- });
590
- /**
591
- * Get a deeply nested value. Example:
592
- *
593
- * getValue({ foo: bar: [] }, 'foo.bar') //=> []
594
- *
595
- * @ignore
596
- * @type {?}
597
- */
598
- var getValue = (/**
599
- * @param {?} obj
600
- * @param {?} prop
601
- * @return {?}
602
- */
603
- function (obj, prop) {
604
- return prop.split('.').reduce((/**
605
- * @param {?} acc
606
- * @param {?} part
607
- * @return {?}
608
- */
609
- function (acc, part) { return acc && acc[part]; }), obj);
610
- });
611
- /**
612
- * Simple object check.
613
- *
614
- * isObject({a:1}) //=> true
615
- * isObject(1) //=> false
616
- *
617
- * @ignore
618
- * @type {?}
619
- */
620
- var isObject = (/**
621
- * @param {?} item
622
- * @return {?}
623
- */
624
- function (item) {
625
- return item && typeof item === 'object' && !Array.isArray(item);
626
- });
627
- /**
628
- * Deep merge two objects.
629
- *
630
- * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
631
- *
632
- * \@param base base object onto which `sources` will be applied
633
- * @type {?}
634
- */
635
- var mergeDeep = (/**
636
- * @param {?} base
637
- * @param {...?} sources
638
- * @return {?}
639
- */
640
- function (base) {
641
- var sources = [];
642
- for (var _i = 1; _i < arguments.length; _i++) {
643
- sources[_i - 1] = arguments[_i];
644
- }
645
- var _a, _b;
646
- if (!sources.length)
647
- return base;
648
- /** @type {?} */
649
- var source = sources.shift();
650
- if (isObject(base) && isObject(source)) {
651
- for (var key in source) {
652
- if (isObject(source[key])) {
653
- if (!base[key])
654
- Object.assign(base, (_a = {}, _a[key] = {}, _a));
655
- mergeDeep(base[key], source[key]);
656
- }
657
- else {
658
- Object.assign(base, (_b = {}, _b[key] = source[key], _b));
659
- }
660
- }
661
- }
662
- return mergeDeep.apply(void 0, __spread([base], sources));
663
- });
664
-
665
515
  /**
666
516
  * @fileoverview added by tsickle
667
517
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
@@ -786,17 +636,6 @@ if (false) {
786
636
  /** @type {?} */
787
637
  StatesAndDefaults.prototype.states;
788
638
  }
789
- /**
790
- * @record
791
- * @template T
792
- */
793
- function RootStateDiff() { }
794
- if (false) {
795
- /** @type {?} */
796
- RootStateDiff.prototype.currentAppState;
797
- /** @type {?} */
798
- RootStateDiff.prototype.newAppState;
799
- }
800
639
  /**
801
640
  * Ensures metadata is attached to the class and returns it.
802
641
  *
@@ -1138,22 +977,159 @@ function topologicalSort(graph) {
1138
977
  * @param {?} obj
1139
978
  * @return {?}
1140
979
  */
1141
- function isObject$1(obj) {
980
+ function isObject(obj) {
1142
981
  return (typeof obj === 'object' && obj !== null) || typeof obj === 'function';
1143
982
  }
983
+
1144
984
  /**
1145
- * @template T
1146
- * @param {?} mappedStore
1147
- * @param {?} diff
985
+ * @fileoverview added by tsickle
986
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
987
+ */
988
+ /**
989
+ * Returns the type from an action instance/class.
990
+ * @ignore
991
+ * @param {?} action
992
+ * @return {?}
993
+ */
994
+ function getActionTypeFromInstance(action) {
995
+ if (action.constructor && action.constructor.type) {
996
+ return action.constructor.type;
997
+ }
998
+ else {
999
+ return action.type;
1000
+ }
1001
+ }
1002
+ /**
1003
+ * Matches a action
1004
+ * @ignore
1005
+ * @param {?} action1
1006
+ * @return {?}
1007
+ */
1008
+ function actionMatcher(action1) {
1009
+ /** @type {?} */
1010
+ var type1 = getActionTypeFromInstance(action1);
1011
+ return (/**
1012
+ * @param {?} action2
1013
+ * @return {?}
1014
+ */
1015
+ function (action2) {
1016
+ return type1 === getActionTypeFromInstance(action2);
1017
+ });
1018
+ }
1019
+ /**
1020
+ * Set a deeply nested value. Example:
1021
+ *
1022
+ * setValue({ foo: { bar: { eat: false } } },
1023
+ * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
1024
+ *
1025
+ * While it traverses it also creates new objects from top down.
1026
+ *
1027
+ * @ignore
1028
+ * @type {?}
1029
+ */
1030
+ var setValue = (/**
1031
+ * @param {?} obj
1032
+ * @param {?} prop
1033
+ * @param {?} val
1034
+ * @return {?}
1035
+ */
1036
+ function (obj, prop, val) {
1037
+ obj = __assign({}, obj);
1038
+ /** @type {?} */
1039
+ var split = prop.split('.');
1040
+ /** @type {?} */
1041
+ var lastIndex = split.length - 1;
1042
+ split.reduce((/**
1043
+ * @param {?} acc
1044
+ * @param {?} part
1045
+ * @param {?} index
1046
+ * @return {?}
1047
+ */
1048
+ function (acc, part, index) {
1049
+ if (index === lastIndex) {
1050
+ acc[part] = val;
1051
+ }
1052
+ else {
1053
+ acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : __assign({}, acc[part]);
1054
+ }
1055
+ return acc && acc[part];
1056
+ }), obj);
1057
+ return obj;
1058
+ });
1059
+ /**
1060
+ * Get a deeply nested value. Example:
1061
+ *
1062
+ * getValue({ foo: bar: [] }, 'foo.bar') //=> []
1063
+ *
1064
+ * @ignore
1065
+ * @type {?}
1066
+ */
1067
+ var getValue = (/**
1068
+ * @param {?} obj
1069
+ * @param {?} prop
1070
+ * @return {?}
1071
+ */
1072
+ function (obj, prop) {
1073
+ return prop.split('.').reduce((/**
1074
+ * @param {?} acc
1075
+ * @param {?} part
1076
+ * @return {?}
1077
+ */
1078
+ function (acc, part) { return acc && acc[part]; }), obj);
1079
+ });
1080
+ /**
1081
+ * Simple object check.
1082
+ *
1083
+ * isObject({a:1}) //=> true
1084
+ * isObject(1) //=> false
1085
+ *
1086
+ * @ignore
1087
+ * @type {?}
1088
+ */
1089
+ var isObject$1 = (/**
1090
+ * @param {?} item
1091
+ * @return {?}
1092
+ */
1093
+ function (item) {
1094
+ return item && typeof item === 'object' && !Array.isArray(item);
1095
+ });
1096
+ /**
1097
+ * Deep merge two objects.
1098
+ *
1099
+ * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
1100
+ *
1101
+ * \@param base base object onto which `sources` will be applied
1102
+ * @type {?}
1103
+ */
1104
+ var mergeDeep = (/**
1105
+ * @param {?} base
1106
+ * @param {...?} sources
1148
1107
  * @return {?}
1149
1108
  */
1150
- function getStateDiffChanges(mappedStore, diff) {
1151
- /** @type {?} */
1152
- var previousValue = getValue(diff.currentAppState, mappedStore.path);
1109
+ function (base) {
1110
+ var sources = [];
1111
+ for (var _i = 1; _i < arguments.length; _i++) {
1112
+ sources[_i - 1] = arguments[_i];
1113
+ }
1114
+ var _a, _b;
1115
+ if (!sources.length)
1116
+ return base;
1153
1117
  /** @type {?} */
1154
- var currentValue = getValue(diff.newAppState, mappedStore.path);
1155
- return new NgxsSimpleChange(previousValue, currentValue, !mappedStore.isInitialised);
1156
- }
1118
+ var source = sources.shift();
1119
+ if (isObject$1(base) && isObject$1(source)) {
1120
+ for (var key in source) {
1121
+ if (isObject$1(source[key])) {
1122
+ if (!base[key])
1123
+ Object.assign(base, (_a = {}, _a[key] = {}, _a));
1124
+ mergeDeep(base[key], source[key]);
1125
+ }
1126
+ else {
1127
+ Object.assign(base, (_b = {}, _b[key] = source[key], _b));
1128
+ }
1129
+ }
1130
+ }
1131
+ return mergeDeep.apply(void 0, __spread([base], sources));
1132
+ });
1157
1133
 
1158
1134
  /**
1159
1135
  * @fileoverview added by tsickle
@@ -1592,6 +1568,15 @@ var InternalActions = /** @class */ (function (_super) {
1592
1568
  function InternalActions() {
1593
1569
  return _super !== null && _super.apply(this, arguments) || this;
1594
1570
  }
1571
+ /**
1572
+ * @return {?}
1573
+ */
1574
+ InternalActions.prototype.ngOnDestroy = /**
1575
+ * @return {?}
1576
+ */
1577
+ function () {
1578
+ this.complete();
1579
+ };
1595
1580
  InternalActions.decorators = [
1596
1581
  { type: Injectable }
1597
1582
  ];
@@ -2289,16 +2274,6 @@ var StateContextFactory = /** @class */ (function () {
2289
2274
  function setStateValue(currentAppState, newValue) {
2290
2275
  /** @type {?} */
2291
2276
  var newAppState = setValue(currentAppState, mappedStore.path, newValue);
2292
- /** @type {?} */
2293
- var instance = mappedStore.instance;
2294
- if (instance.ngxsOnChanges) {
2295
- /** @type {?} */
2296
- var change = getStateDiffChanges(mappedStore, {
2297
- currentAppState: currentAppState,
2298
- newAppState: newAppState
2299
- });
2300
- instance.ngxsOnChanges(change);
2301
- }
2302
2277
  root.setState(newAppState);
2303
2278
  return newAppState;
2304
2279
  // In doing this refactoring I noticed that there is a 'bug' where the
@@ -2612,7 +2587,7 @@ var StateFactory = /** @class */ (function () {
2612
2587
  if (Array.isArray(defaults)) {
2613
2588
  value = defaults.slice();
2614
2589
  }
2615
- else if (isObject$1(defaults)) {
2590
+ else if (isObject(defaults)) {
2616
2591
  value = __assign({}, defaults);
2617
2592
  }
2618
2593
  else if (defaults === undefined) {
@@ -2941,285 +2916,116 @@ var StateFactory = /** @class */ (function () {
2941
2916
  * @param {?} path
2942
2917
  * @return {?}
2943
2918
  */
2944
- function (meta, path) {
2945
- this.statePaths[(/** @type {?} */ (meta.name))] = path;
2946
- // TODO: v4 - we plan to get rid of the path property because it is non-deterministic
2947
- // we can do this when we get rid of the incorrectly exposed getStoreMetadata
2948
- // We will need to come up with an alternative in v4 because this is used by many plugins
2949
- meta.path = path;
2950
- };
2951
- /**
2952
- * @description
2953
- * the method checks if the state has already been added to the tree
2954
- * and completed the life cycle
2955
- * @param name
2956
- * @param path
2957
- */
2958
- /**
2959
- * \@description
2960
- * the method checks if the state has already been added to the tree
2961
- * and completed the life cycle
2962
- * @private
2963
- * @param {?} name
2964
- * @param {?} path
2965
- * @return {?}
2966
- */
2967
- StateFactory.prototype.hasBeenMountedAndBootstrapped = /**
2968
- * \@description
2969
- * the method checks if the state has already been added to the tree
2970
- * and completed the life cycle
2971
- * @private
2972
- * @param {?} name
2973
- * @param {?} path
2974
- * @return {?}
2975
- */
2976
- function (name, path) {
2977
- /** @type {?} */
2978
- var valueIsBootstrappedInInitialState = getValue(this._initialState, path) !== undefined;
2979
- return this.statesByName[name] && valueIsBootstrappedInInitialState;
2980
- };
2981
- StateFactory.decorators = [
2982
- { type: Injectable }
2983
- ];
2984
- /** @nocollapse */
2985
- StateFactory.ctorParameters = function () { return [
2986
- { type: Injector },
2987
- { type: NgxsConfig },
2988
- { type: StateFactory, decorators: [{ type: Optional }, { type: SkipSelf }] },
2989
- { type: InternalActions },
2990
- { type: InternalDispatchedActionResults },
2991
- { type: StateContextFactory },
2992
- { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [INITIAL_STATE_TOKEN,] }] }
2993
- ]; };
2994
- return StateFactory;
2995
- }());
2996
- if (false) {
2997
- /**
2998
- * @type {?}
2999
- * @private
3000
- */
3001
- StateFactory.prototype._actionsSubscription;
3002
- /**
3003
- * @type {?}
3004
- * @private
3005
- */
3006
- StateFactory.prototype._states;
3007
- /**
3008
- * @type {?}
3009
- * @private
3010
- */
3011
- StateFactory.prototype._statesByName;
3012
- /**
3013
- * @type {?}
3014
- * @private
3015
- */
3016
- StateFactory.prototype._statePaths;
3017
- /** @type {?} */
3018
- StateFactory.prototype.getRuntimeSelectorContext;
3019
- /**
3020
- * @type {?}
3021
- * @private
3022
- */
3023
- StateFactory.prototype._injector;
3024
- /**
3025
- * @type {?}
3026
- * @private
3027
- */
3028
- StateFactory.prototype._config;
3029
- /**
3030
- * @type {?}
3031
- * @private
3032
- */
3033
- StateFactory.prototype._parentFactory;
3034
- /**
3035
- * @type {?}
3036
- * @private
3037
- */
3038
- StateFactory.prototype._actions;
3039
- /**
3040
- * @type {?}
3041
- * @private
3042
- */
3043
- StateFactory.prototype._actionResults;
3044
- /**
3045
- * @type {?}
3046
- * @private
3047
- */
3048
- StateFactory.prototype._stateContextFactory;
3049
- /**
3050
- * @type {?}
3051
- * @private
3052
- */
3053
- StateFactory.prototype._initialState;
3054
- }
3055
-
3056
- /**
3057
- * @fileoverview added by tsickle
3058
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3059
- */
3060
- var LifecycleStateManager = /** @class */ (function () {
3061
- function LifecycleStateManager(internalStateOperations, stateContextFactory, bootstrapper) {
3062
- this.internalStateOperations = internalStateOperations;
3063
- this.stateContextFactory = stateContextFactory;
3064
- this.bootstrapper = bootstrapper;
3065
- }
3066
- /**
3067
- * @template T
3068
- * @param {?} action
3069
- * @param {?} results
3070
- * @return {?}
3071
- */
3072
- LifecycleStateManager.prototype.ngxsBootstrap = /**
3073
- * @template T
3074
- * @param {?} action
3075
- * @param {?} results
3076
- * @return {?}
3077
- */
3078
- function (action, results) {
3079
- var _this = this;
3080
- this.internalStateOperations
3081
- .getRootStateOperations()
3082
- .dispatch(action)
3083
- .pipe(filter((/**
3084
- * @return {?}
3085
- */
3086
- function () { return !!results; })), tap((/**
3087
- * @return {?}
3088
- */
3089
- function () { return _this.invokeInit((/** @type {?} */ (results)).states); })), mergeMap((/**
3090
- * @return {?}
3091
- */
3092
- function () { return _this.bootstrapper.appBootstrapped$; })), filter((/**
3093
- * @param {?} appBootstrapped
3094
- * @return {?}
3095
- */
3096
- function (appBootstrapped) { return !!appBootstrapped; })))
3097
- .subscribe((/**
3098
- * @return {?}
3099
- */
3100
- function () { return _this.invokeBootstrap((/** @type {?} */ (results)).states); }));
3101
- };
3102
- /**
3103
- * Invoke the init function on the states.
3104
- */
3105
- /**
3106
- * Invoke the init function on the states.
3107
- * @param {?} mappedStores
3108
- * @return {?}
3109
- */
3110
- LifecycleStateManager.prototype.invokeInit = /**
3111
- * Invoke the init function on the states.
3112
- * @param {?} mappedStores
3113
- * @return {?}
3114
- */
3115
- function (mappedStores) {
3116
- var e_1, _a;
3117
- try {
3118
- for (var mappedStores_1 = __values(mappedStores), mappedStores_1_1 = mappedStores_1.next(); !mappedStores_1_1.done; mappedStores_1_1 = mappedStores_1.next()) {
3119
- var mappedStore = mappedStores_1_1.value;
3120
- /** @type {?} */
3121
- var instance = mappedStore.instance;
3122
- if (instance.ngxsOnChanges) {
3123
- /** @type {?} */
3124
- var currentAppState = {};
3125
- /** @type {?} */
3126
- var newAppState = this.internalStateOperations
3127
- .getRootStateOperations()
3128
- .getState();
3129
- /** @type {?} */
3130
- var firstDiffChange = getStateDiffChanges(mappedStore, {
3131
- currentAppState: currentAppState,
3132
- newAppState: newAppState
3133
- });
3134
- instance.ngxsOnChanges(firstDiffChange);
3135
- }
3136
- if (instance.ngxsOnInit) {
3137
- instance.ngxsOnInit(this.getStateContext(mappedStore));
3138
- }
3139
- mappedStore.isInitialised = true;
3140
- }
3141
- }
3142
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
3143
- finally {
3144
- try {
3145
- if (mappedStores_1_1 && !mappedStores_1_1.done && (_a = mappedStores_1.return)) _a.call(mappedStores_1);
3146
- }
3147
- finally { if (e_1) throw e_1.error; }
3148
- }
3149
- };
3150
- /**
3151
- * Invoke the bootstrap function on the states.
3152
- */
3153
- /**
3154
- * Invoke the bootstrap function on the states.
3155
- * @param {?} mappedStores
3156
- * @return {?}
3157
- */
3158
- LifecycleStateManager.prototype.invokeBootstrap = /**
3159
- * Invoke the bootstrap function on the states.
3160
- * @param {?} mappedStores
3161
- * @return {?}
3162
- */
3163
- function (mappedStores) {
3164
- var e_2, _a;
3165
- try {
3166
- for (var mappedStores_2 = __values(mappedStores), mappedStores_2_1 = mappedStores_2.next(); !mappedStores_2_1.done; mappedStores_2_1 = mappedStores_2.next()) {
3167
- var mappedStore = mappedStores_2_1.value;
3168
- /** @type {?} */
3169
- var instance = mappedStore.instance;
3170
- if (instance.ngxsAfterBootstrap) {
3171
- instance.ngxsAfterBootstrap(this.getStateContext(mappedStore));
3172
- }
3173
- }
3174
- }
3175
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
3176
- finally {
3177
- try {
3178
- if (mappedStores_2_1 && !mappedStores_2_1.done && (_a = mappedStores_2.return)) _a.call(mappedStores_2);
3179
- }
3180
- finally { if (e_2) throw e_2.error; }
3181
- }
2919
+ function (meta, path) {
2920
+ this.statePaths[(/** @type {?} */ (meta.name))] = path;
2921
+ // TODO: v4 - we plan to get rid of the path property because it is non-deterministic
2922
+ // we can do this when we get rid of the incorrectly exposed getStoreMetadata
2923
+ // We will need to come up with an alternative in v4 because this is used by many plugins
2924
+ meta.path = path;
3182
2925
  };
3183
2926
  /**
2927
+ * @description
2928
+ * the method checks if the state has already been added to the tree
2929
+ * and completed the life cycle
2930
+ * @param name
2931
+ * @param path
2932
+ */
2933
+ /**
2934
+ * \@description
2935
+ * the method checks if the state has already been added to the tree
2936
+ * and completed the life cycle
3184
2937
  * @private
3185
- * @param {?} mappedStore
2938
+ * @param {?} name
2939
+ * @param {?} path
3186
2940
  * @return {?}
3187
2941
  */
3188
- LifecycleStateManager.prototype.getStateContext = /**
2942
+ StateFactory.prototype.hasBeenMountedAndBootstrapped = /**
2943
+ * \@description
2944
+ * the method checks if the state has already been added to the tree
2945
+ * and completed the life cycle
3189
2946
  * @private
3190
- * @param {?} mappedStore
2947
+ * @param {?} name
2948
+ * @param {?} path
3191
2949
  * @return {?}
3192
2950
  */
3193
- function (mappedStore) {
3194
- return this.stateContextFactory.createStateContext(mappedStore);
2951
+ function (name, path) {
2952
+ /** @type {?} */
2953
+ var valueIsBootstrappedInInitialState = getValue(this._initialState, path) !== undefined;
2954
+ return this.statesByName[name] && valueIsBootstrappedInInitialState;
3195
2955
  };
3196
- LifecycleStateManager.decorators = [
2956
+ StateFactory.decorators = [
3197
2957
  { type: Injectable }
3198
2958
  ];
3199
2959
  /** @nocollapse */
3200
- LifecycleStateManager.ctorParameters = function () { return [
3201
- { type: InternalStateOperations },
2960
+ StateFactory.ctorParameters = function () { return [
2961
+ { type: Injector },
2962
+ { type: NgxsConfig },
2963
+ { type: StateFactory, decorators: [{ type: Optional }, { type: SkipSelf }] },
2964
+ { type: InternalActions },
2965
+ { type: InternalDispatchedActionResults },
3202
2966
  { type: StateContextFactory },
3203
- { type: NgxsBootstrapper }
2967
+ { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [INITIAL_STATE_TOKEN,] }] }
3204
2968
  ]; };
3205
- return LifecycleStateManager;
2969
+ return StateFactory;
3206
2970
  }());
3207
2971
  if (false) {
3208
2972
  /**
3209
2973
  * @type {?}
3210
2974
  * @private
3211
2975
  */
3212
- LifecycleStateManager.prototype.internalStateOperations;
2976
+ StateFactory.prototype._actionsSubscription;
2977
+ /**
2978
+ * @type {?}
2979
+ * @private
2980
+ */
2981
+ StateFactory.prototype._states;
2982
+ /**
2983
+ * @type {?}
2984
+ * @private
2985
+ */
2986
+ StateFactory.prototype._statesByName;
2987
+ /**
2988
+ * @type {?}
2989
+ * @private
2990
+ */
2991
+ StateFactory.prototype._statePaths;
2992
+ /** @type {?} */
2993
+ StateFactory.prototype.getRuntimeSelectorContext;
2994
+ /**
2995
+ * @type {?}
2996
+ * @private
2997
+ */
2998
+ StateFactory.prototype._injector;
2999
+ /**
3000
+ * @type {?}
3001
+ * @private
3002
+ */
3003
+ StateFactory.prototype._config;
3004
+ /**
3005
+ * @type {?}
3006
+ * @private
3007
+ */
3008
+ StateFactory.prototype._parentFactory;
3009
+ /**
3010
+ * @type {?}
3011
+ * @private
3012
+ */
3013
+ StateFactory.prototype._actions;
3014
+ /**
3015
+ * @type {?}
3016
+ * @private
3017
+ */
3018
+ StateFactory.prototype._actionResults;
3213
3019
  /**
3214
3020
  * @type {?}
3215
3021
  * @private
3216
3022
  */
3217
- LifecycleStateManager.prototype.stateContextFactory;
3023
+ StateFactory.prototype._stateContextFactory;
3218
3024
  /**
3219
3025
  * @type {?}
3220
3026
  * @private
3221
3027
  */
3222
- LifecycleStateManager.prototype.bootstrapper;
3028
+ StateFactory.prototype._initialState;
3223
3029
  }
3224
3030
 
3225
3031
  /**
@@ -3676,6 +3482,210 @@ if (false) {
3676
3482
  Store.prototype._stateFactory;
3677
3483
  }
3678
3484
 
3485
+ /**
3486
+ * @fileoverview added by tsickle
3487
+ * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
3488
+ */
3489
+ var LifecycleStateManager = /** @class */ (function () {
3490
+ function LifecycleStateManager(_store, _internalStateOperations, _stateContextFactory, _bootstrapper) {
3491
+ this._store = _store;
3492
+ this._internalStateOperations = _internalStateOperations;
3493
+ this._stateContextFactory = _stateContextFactory;
3494
+ this._bootstrapper = _bootstrapper;
3495
+ this._destroy$ = new Subject();
3496
+ }
3497
+ /**
3498
+ * @return {?}
3499
+ */
3500
+ LifecycleStateManager.prototype.ngOnDestroy = /**
3501
+ * @return {?}
3502
+ */
3503
+ function () {
3504
+ this._destroy$.next();
3505
+ };
3506
+ /**
3507
+ * @template T
3508
+ * @param {?} action
3509
+ * @param {?} results
3510
+ * @return {?}
3511
+ */
3512
+ LifecycleStateManager.prototype.ngxsBootstrap = /**
3513
+ * @template T
3514
+ * @param {?} action
3515
+ * @param {?} results
3516
+ * @return {?}
3517
+ */
3518
+ function (action, results) {
3519
+ var _this = this;
3520
+ this._internalStateOperations
3521
+ .getRootStateOperations()
3522
+ .dispatch(action)
3523
+ .pipe(filter((/**
3524
+ * @return {?}
3525
+ */
3526
+ function () { return !!results; })), tap((/**
3527
+ * @return {?}
3528
+ */
3529
+ function () { return _this._invokeInit((/** @type {?} */ (results)).states); })), mergeMap((/**
3530
+ * @return {?}
3531
+ */
3532
+ function () { return _this._bootstrapper.appBootstrapped$; })), filter((/**
3533
+ * @param {?} appBootstrapped
3534
+ * @return {?}
3535
+ */
3536
+ function (appBootstrapped) { return !!appBootstrapped; })), takeUntil(this._destroy$))
3537
+ .subscribe((/**
3538
+ * @return {?}
3539
+ */
3540
+ function () { return _this._invokeBootstrap((/** @type {?} */ (results)).states); }));
3541
+ };
3542
+ /**
3543
+ * Invoke the init function on the states.
3544
+ */
3545
+ /**
3546
+ * Invoke the init function on the states.
3547
+ * @private
3548
+ * @param {?} mappedStores
3549
+ * @return {?}
3550
+ */
3551
+ LifecycleStateManager.prototype._invokeInit = /**
3552
+ * Invoke the init function on the states.
3553
+ * @private
3554
+ * @param {?} mappedStores
3555
+ * @return {?}
3556
+ */
3557
+ function (mappedStores) {
3558
+ var e_1, _a;
3559
+ var _loop_1 = function (mappedStore) {
3560
+ /** @type {?} */
3561
+ var instance = mappedStore.instance;
3562
+ if (instance.ngxsOnChanges) {
3563
+ this_1._store
3564
+ .select((/**
3565
+ * @param {?} state
3566
+ * @return {?}
3567
+ */
3568
+ function (state) { return getValue(state, mappedStore.path); }))
3569
+ .pipe(startWith(undefined), pairwise(), takeUntil(this_1._destroy$))
3570
+ .subscribe((/**
3571
+ * @param {?} __0
3572
+ * @return {?}
3573
+ */
3574
+ function (_a) {
3575
+ var _b = __read(_a, 2), previousValue = _b[0], currentValue = _b[1];
3576
+ /** @type {?} */
3577
+ var change = new NgxsSimpleChange(previousValue, currentValue, !mappedStore.isInitialised);
3578
+ (/** @type {?} */ (instance.ngxsOnChanges))(change);
3579
+ }));
3580
+ }
3581
+ if (instance.ngxsOnInit) {
3582
+ instance.ngxsOnInit(this_1._getStateContext(mappedStore));
3583
+ }
3584
+ mappedStore.isInitialised = true;
3585
+ };
3586
+ var this_1 = this;
3587
+ try {
3588
+ for (var mappedStores_1 = __values(mappedStores), mappedStores_1_1 = mappedStores_1.next(); !mappedStores_1_1.done; mappedStores_1_1 = mappedStores_1.next()) {
3589
+ var mappedStore = mappedStores_1_1.value;
3590
+ _loop_1(mappedStore);
3591
+ }
3592
+ }
3593
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
3594
+ finally {
3595
+ try {
3596
+ if (mappedStores_1_1 && !mappedStores_1_1.done && (_a = mappedStores_1.return)) _a.call(mappedStores_1);
3597
+ }
3598
+ finally { if (e_1) throw e_1.error; }
3599
+ }
3600
+ };
3601
+ /**
3602
+ * Invoke the bootstrap function on the states.
3603
+ */
3604
+ /**
3605
+ * Invoke the bootstrap function on the states.
3606
+ * @private
3607
+ * @param {?} mappedStores
3608
+ * @return {?}
3609
+ */
3610
+ LifecycleStateManager.prototype._invokeBootstrap = /**
3611
+ * Invoke the bootstrap function on the states.
3612
+ * @private
3613
+ * @param {?} mappedStores
3614
+ * @return {?}
3615
+ */
3616
+ function (mappedStores) {
3617
+ var e_2, _a;
3618
+ try {
3619
+ for (var mappedStores_2 = __values(mappedStores), mappedStores_2_1 = mappedStores_2.next(); !mappedStores_2_1.done; mappedStores_2_1 = mappedStores_2.next()) {
3620
+ var mappedStore = mappedStores_2_1.value;
3621
+ /** @type {?} */
3622
+ var instance = mappedStore.instance;
3623
+ if (instance.ngxsAfterBootstrap) {
3624
+ instance.ngxsAfterBootstrap(this._getStateContext(mappedStore));
3625
+ }
3626
+ }
3627
+ }
3628
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
3629
+ finally {
3630
+ try {
3631
+ if (mappedStores_2_1 && !mappedStores_2_1.done && (_a = mappedStores_2.return)) _a.call(mappedStores_2);
3632
+ }
3633
+ finally { if (e_2) throw e_2.error; }
3634
+ }
3635
+ };
3636
+ /**
3637
+ * @private
3638
+ * @param {?} mappedStore
3639
+ * @return {?}
3640
+ */
3641
+ LifecycleStateManager.prototype._getStateContext = /**
3642
+ * @private
3643
+ * @param {?} mappedStore
3644
+ * @return {?}
3645
+ */
3646
+ function (mappedStore) {
3647
+ return this._stateContextFactory.createStateContext(mappedStore);
3648
+ };
3649
+ LifecycleStateManager.decorators = [
3650
+ { type: Injectable }
3651
+ ];
3652
+ /** @nocollapse */
3653
+ LifecycleStateManager.ctorParameters = function () { return [
3654
+ { type: Store },
3655
+ { type: InternalStateOperations },
3656
+ { type: StateContextFactory },
3657
+ { type: NgxsBootstrapper }
3658
+ ]; };
3659
+ return LifecycleStateManager;
3660
+ }());
3661
+ if (false) {
3662
+ /**
3663
+ * @type {?}
3664
+ * @private
3665
+ */
3666
+ LifecycleStateManager.prototype._destroy$;
3667
+ /**
3668
+ * @type {?}
3669
+ * @private
3670
+ */
3671
+ LifecycleStateManager.prototype._store;
3672
+ /**
3673
+ * @type {?}
3674
+ * @private
3675
+ */
3676
+ LifecycleStateManager.prototype._internalStateOperations;
3677
+ /**
3678
+ * @type {?}
3679
+ * @private
3680
+ */
3681
+ LifecycleStateManager.prototype._stateContextFactory;
3682
+ /**
3683
+ * @type {?}
3684
+ * @private
3685
+ */
3686
+ LifecycleStateManager.prototype._bootstrapper;
3687
+ }
3688
+
3679
3689
  /**
3680
3690
  * @fileoverview added by tsickle
3681
3691
  * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc