@ngxs/store 3.8.0-dev.master-a827bb0 → 3.8.0-dev.master-4f8f372

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,11 +1,103 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { NgZone, PLATFORM_ID, Injectable, Inject, InjectionToken, inject, INJECTOR, ɵglobal, ErrorHandler, Optional, SkipSelf, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
3
3
  import * as i5 from '@ngxs/store/internals';
4
- import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY, InitialState } from '@ngxs/store/internals';
4
+ import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY } from '@ngxs/store/internals';
5
5
  import { isPlatformServer } from '@angular/common';
6
6
  import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable } from 'rxjs';
7
7
  import { filter, map, share, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
8
8
 
9
+ /**
10
+ * Returns the type from an action instance/class.
11
+ * @ignore
12
+ */
13
+ function getActionTypeFromInstance(action) {
14
+ if (action.constructor && action.constructor.type) {
15
+ return action.constructor.type;
16
+ }
17
+ else {
18
+ return action.type;
19
+ }
20
+ }
21
+ /**
22
+ * Matches a action
23
+ * @ignore
24
+ */
25
+ function actionMatcher(action1) {
26
+ const type1 = getActionTypeFromInstance(action1);
27
+ return function (action2) {
28
+ return type1 === getActionTypeFromInstance(action2);
29
+ };
30
+ }
31
+ /**
32
+ * Set a deeply nested value. Example:
33
+ *
34
+ * setValue({ foo: { bar: { eat: false } } },
35
+ * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
36
+ *
37
+ * While it traverses it also creates new objects from top down.
38
+ *
39
+ * @ignore
40
+ */
41
+ const setValue = (obj, prop, val) => {
42
+ obj = Object.assign({}, obj);
43
+ const split = prop.split('.');
44
+ const lastIndex = split.length - 1;
45
+ split.reduce((acc, part, index) => {
46
+ if (index === lastIndex) {
47
+ acc[part] = val;
48
+ }
49
+ else {
50
+ acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
51
+ }
52
+ return acc && acc[part];
53
+ }, obj);
54
+ return obj;
55
+ };
56
+ /**
57
+ * Get a deeply nested value. Example:
58
+ *
59
+ * getValue({ foo: bar: [] }, 'foo.bar') //=> []
60
+ *
61
+ * @ignore
62
+ */
63
+ const getValue = (obj, prop) => prop.split('.').reduce((acc, part) => acc && acc[part], obj);
64
+ /**
65
+ * Simple object check.
66
+ *
67
+ * isObject({a:1}) //=> true
68
+ * isObject(1) //=> false
69
+ *
70
+ * @ignore
71
+ */
72
+ const isObject$1 = (item) => {
73
+ return item && typeof item === 'object' && !Array.isArray(item);
74
+ };
75
+ /**
76
+ * Deep merge two objects.
77
+ *
78
+ * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
79
+ *
80
+ * @param base base object onto which `sources` will be applied
81
+ */
82
+ const mergeDeep = (base, ...sources) => {
83
+ if (!sources.length)
84
+ return base;
85
+ const source = sources.shift();
86
+ if (isObject$1(base) && isObject$1(source)) {
87
+ for (const key in source) {
88
+ if (isObject$1(source[key])) {
89
+ if (!base[key])
90
+ Object.assign(base, { [key]: {} });
91
+ mergeDeep(base[key], source[key]);
92
+ }
93
+ else {
94
+ Object.assign(base, { [key]: source[key] });
95
+ }
96
+ }
97
+ }
98
+ return mergeDeep(base, ...sources);
99
+ };
100
+
9
101
  function throwStateNameError(name) {
10
102
  throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
11
103
  }
@@ -95,6 +187,7 @@ function verifyZoneIsNotNooped(ngZone) {
95
187
  console.warn(getZoneWarningMessage());
96
188
  }
97
189
 
190
+ const ROOT_OPTIONS = new InjectionToken('ROOT_OPTIONS');
98
191
  const ROOT_STATE_TOKEN = new InjectionToken('ROOT_STATE_TOKEN');
99
192
  const FEATURE_STATE_TOKEN = new InjectionToken('FEATURE_STATE_TOKEN');
100
193
  const NGXS_PLUGINS = new InjectionToken('NGXS_PLUGINS');
@@ -127,9 +220,14 @@ class NgxsConfig {
127
220
  }
128
221
  }
129
222
  /** @nocollapse */ NgxsConfig.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
130
- /** @nocollapse */ NgxsConfig.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig });
223
+ /** @nocollapse */ NgxsConfig.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: (options) => mergeDeep(new NgxsConfig(), options), deps: [{ token: ROOT_OPTIONS }] });
131
224
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, decorators: [{
132
- type: Injectable
225
+ type: Injectable,
226
+ args: [{
227
+ providedIn: 'root',
228
+ useFactory: (options) => mergeDeep(new NgxsConfig(), options),
229
+ deps: [ROOT_OPTIONS]
230
+ }]
133
231
  }], ctorParameters: function () { return []; } });
134
232
  /**
135
233
  * Represents a basic change from a previous to a new value for a single state instance.
@@ -421,102 +519,10 @@ function topologicalSort(graph) {
421
519
  *
422
520
  * @ignore
423
521
  */
424
- function isObject$1(obj) {
522
+ function isObject(obj) {
425
523
  return (typeof obj === 'object' && obj !== null) || typeof obj === 'function';
426
524
  }
427
525
 
428
- /**
429
- * Returns the type from an action instance/class.
430
- * @ignore
431
- */
432
- function getActionTypeFromInstance(action) {
433
- if (action.constructor && action.constructor.type) {
434
- return action.constructor.type;
435
- }
436
- else {
437
- return action.type;
438
- }
439
- }
440
- /**
441
- * Matches a action
442
- * @ignore
443
- */
444
- function actionMatcher(action1) {
445
- const type1 = getActionTypeFromInstance(action1);
446
- return function (action2) {
447
- return type1 === getActionTypeFromInstance(action2);
448
- };
449
- }
450
- /**
451
- * Set a deeply nested value. Example:
452
- *
453
- * setValue({ foo: { bar: { eat: false } } },
454
- * 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
455
- *
456
- * While it traverses it also creates new objects from top down.
457
- *
458
- * @ignore
459
- */
460
- const setValue = (obj, prop, val) => {
461
- obj = Object.assign({}, obj);
462
- const split = prop.split('.');
463
- const lastIndex = split.length - 1;
464
- split.reduce((acc, part, index) => {
465
- if (index === lastIndex) {
466
- acc[part] = val;
467
- }
468
- else {
469
- acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
470
- }
471
- return acc && acc[part];
472
- }, obj);
473
- return obj;
474
- };
475
- /**
476
- * Get a deeply nested value. Example:
477
- *
478
- * getValue({ foo: bar: [] }, 'foo.bar') //=> []
479
- *
480
- * @ignore
481
- */
482
- const getValue = (obj, prop) => prop.split('.').reduce((acc, part) => acc && acc[part], obj);
483
- /**
484
- * Simple object check.
485
- *
486
- * isObject({a:1}) //=> true
487
- * isObject(1) //=> false
488
- *
489
- * @ignore
490
- */
491
- const isObject = (item) => {
492
- return item && typeof item === 'object' && !Array.isArray(item);
493
- };
494
- /**
495
- * Deep merge two objects.
496
- *
497
- * mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
498
- *
499
- * @param base base object onto which `sources` will be applied
500
- */
501
- const mergeDeep = (base, ...sources) => {
502
- if (!sources.length)
503
- return base;
504
- const source = sources.shift();
505
- if (isObject(base) && isObject(source)) {
506
- for (const key in source) {
507
- if (isObject(source[key])) {
508
- if (!base[key])
509
- Object.assign(base, { [key]: {} });
510
- mergeDeep(base[key], source[key]);
511
- }
512
- else {
513
- Object.assign(base, { [key]: source[key] });
514
- }
515
- }
516
- }
517
- return mergeDeep(base, ...sources);
518
- };
519
-
520
526
  /**
521
527
  * RxJS operator for selecting out specific actions.
522
528
  *
@@ -651,9 +657,10 @@ class InternalNgxsExecutionStrategy {
651
657
  }
652
658
  }
653
659
  /** @nocollapse */ InternalNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [{ token: NGXS_EXECUTION_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
654
- /** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy });
660
+ /** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' });
655
661
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
656
- type: Injectable
662
+ type: Injectable,
663
+ args: [{ providedIn: 'root' }]
657
664
  }], ctorParameters: function () { return [{ type: undefined, decorators: [{
658
665
  type: Inject,
659
666
  args: [NGXS_EXECUTION_STRATEGY]
@@ -759,9 +766,10 @@ class InternalActions extends OrderedSubject {
759
766
  }
760
767
  }
761
768
  /** @nocollapse */ InternalActions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
762
- /** @nocollapse */ InternalActions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions });
769
+ /** @nocollapse */ InternalActions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, providedIn: 'root' });
763
770
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, decorators: [{
764
- type: Injectable
771
+ type: Injectable,
772
+ args: [{ providedIn: 'root' }]
765
773
  }] });
766
774
  /**
767
775
  * Action stream that is emitted anytime an action is dispatched.
@@ -787,9 +795,10 @@ class Actions extends Observable {
787
795
  }
788
796
  }
789
797
  /** @nocollapse */ Actions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, deps: [{ token: InternalActions }, { token: InternalNgxsExecutionStrategy }], target: i0.ɵɵFactoryTarget.Injectable });
790
- /** @nocollapse */ Actions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions });
798
+ /** @nocollapse */ Actions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, providedIn: 'root' });
791
799
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, decorators: [{
792
- type: Injectable
800
+ type: Injectable,
801
+ args: [{ providedIn: 'root' }]
793
802
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalNgxsExecutionStrategy }]; } });
794
803
 
795
804
  /**
@@ -894,9 +903,10 @@ class StateStream extends OrderedBehaviorSubject {
894
903
  }
895
904
  }
896
905
  /** @nocollapse */ StateStream.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
897
- /** @nocollapse */ StateStream.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream });
906
+ /** @nocollapse */ StateStream.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, providedIn: 'root' });
898
907
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, decorators: [{
899
- type: Injectable
908
+ type: Injectable,
909
+ args: [{ providedIn: 'root' }]
900
910
  }], ctorParameters: function () { return []; } });
901
911
 
902
912
  class PluginManager {
@@ -942,9 +952,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
942
952
  class InternalDispatchedActionResults extends Subject {
943
953
  }
944
954
  /** @nocollapse */ InternalDispatchedActionResults.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
945
- /** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults });
955
+ /** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults, providedIn: 'root' });
946
956
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatchedActionResults, decorators: [{
947
- type: Injectable
957
+ type: Injectable,
958
+ args: [{ providedIn: 'root' }]
948
959
  }] });
949
960
  class InternalDispatcher {
950
961
  constructor(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
@@ -1014,9 +1025,10 @@ class InternalDispatcher {
1014
1025
  }
1015
1026
  }
1016
1027
  /** @nocollapse */ InternalDispatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher, deps: [{ token: InternalActions }, { token: InternalDispatchedActionResults }, { token: PluginManager }, { token: StateStream }, { token: InternalNgxsExecutionStrategy }, { token: InternalErrorReporter }], target: i0.ɵɵFactoryTarget.Injectable });
1017
- /** @nocollapse */ InternalDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher });
1028
+ /** @nocollapse */ InternalDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher, providedIn: 'root' });
1018
1029
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalDispatcher, decorators: [{
1019
- type: Injectable
1030
+ type: Injectable,
1031
+ args: [{ providedIn: 'root' }]
1020
1032
  }], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalDispatchedActionResults }, { type: PluginManager }, { type: StateStream }, { type: InternalNgxsExecutionStrategy }, { type: InternalErrorReporter }]; } });
1021
1033
 
1022
1034
  /**
@@ -1040,7 +1052,6 @@ const deepFreeze = (o) => {
1040
1052
  };
1041
1053
 
1042
1054
  /**
1043
- * State Context factory class
1044
1055
  * @ignore
1045
1056
  */
1046
1057
  class InternalStateOperations {
@@ -1076,9 +1087,10 @@ class InternalStateOperations {
1076
1087
  }
1077
1088
  }
1078
1089
  /** @nocollapse */ InternalStateOperations.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations, deps: [{ token: StateStream }, { token: InternalDispatcher }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
1079
- /** @nocollapse */ InternalStateOperations.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations });
1090
+ /** @nocollapse */ InternalStateOperations.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations, providedIn: 'root' });
1080
1091
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalStateOperations, decorators: [{
1081
- type: Injectable
1092
+ type: Injectable,
1093
+ args: [{ providedIn: 'root' }]
1082
1094
  }], ctorParameters: function () { return [{ type: StateStream }, { type: InternalDispatcher }, { type: NgxsConfig }]; } });
1083
1095
  function ensureStateAndActionsAreImmutable(root) {
1084
1096
  return {
@@ -1170,9 +1182,10 @@ class StateContextFactory {
1170
1182
  }
1171
1183
  }
1172
1184
  /** @nocollapse */ StateContextFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory, deps: [{ token: InternalStateOperations }], target: i0.ɵɵFactoryTarget.Injectable });
1173
- /** @nocollapse */ StateContextFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory });
1185
+ /** @nocollapse */ StateContextFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory, providedIn: 'root' });
1174
1186
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateContextFactory, decorators: [{
1175
- type: Injectable
1187
+ type: Injectable,
1188
+ args: [{ providedIn: 'root' }]
1176
1189
  }], ctorParameters: function () { return [{ type: InternalStateOperations }]; } });
1177
1190
 
1178
1191
  class StoreValidators {
@@ -1292,8 +1305,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
1292
1305
  args: [NGXS_DEVELOPMENT_OPTIONS]
1293
1306
  }] }]; } });
1294
1307
 
1308
+ const NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
1295
1309
  /**
1296
- * State factory class
1310
+ * The `StateFactory` class adds root and feature states to the graph.
1311
+ * This extracts state names from state classes, checks if they already
1312
+ * exist in the global graph, throws errors if their names are invalid, etc.
1313
+ * See its constructor, state factories inject state factories that are
1314
+ * parent-level providers. This is required to get feature states from the
1315
+ * injector on the same level.
1316
+ *
1317
+ * The `NgxsModule.forFeature(...)` returns `providers: [StateFactory, ...states]`.
1318
+ * The `StateFactory` is initialized on the feature level and goes through `...states`
1319
+ * to get them from the injector through `injector.get(state)`.
1297
1320
  * @ignore
1298
1321
  */
1299
1322
  class StateFactory {
@@ -1354,7 +1377,7 @@ class StateFactory {
1354
1377
  if (Array.isArray(defaults)) {
1355
1378
  value = defaults.slice();
1356
1379
  }
1357
- else if (isObject$1(defaults)) {
1380
+ else if (isObject(defaults)) {
1358
1381
  value = Object.assign({}, defaults);
1359
1382
  }
1360
1383
  else if (defaults === undefined) {
@@ -1366,17 +1389,14 @@ class StateFactory {
1366
1389
  return value;
1367
1390
  }
1368
1391
  ngOnDestroy() {
1369
- // This is being non-null asserted since `_actionsSubscrition` is
1370
- // initialized within the constructor.
1371
- this._actionsSubscription.unsubscribe();
1392
+ var _a;
1393
+ (_a = this._actionsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
1372
1394
  }
1373
1395
  /**
1374
1396
  * Add a new state to the global defs.
1375
1397
  */
1376
1398
  add(stateClasses) {
1377
- // Caretaker note: we have still left the `typeof` condition in order to avoid
1378
- // creating a breaking change for projects that still use the View Engine.
1379
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
1399
+ if (NG_DEV_MODE) {
1380
1400
  StoreValidators.checkThatStateClassesHaveBeenDecorated(stateClasses);
1381
1401
  }
1382
1402
  const { newStates } = this.addToStatesMap(stateClasses);
@@ -1426,12 +1446,13 @@ class StateFactory {
1426
1446
  const defaults = mappedStores.reduce((result, mappedStore) => setValue(result, mappedStore.path, mappedStore.defaults), {});
1427
1447
  return { defaults, states: mappedStores };
1428
1448
  }
1429
- /**
1430
- * Bind the actions to the handlers
1431
- */
1432
1449
  connectActionHandlers() {
1433
- if (this._actionsSubscription !== null)
1450
+ // Note: We have to connect actions only once when the `StateFactory`
1451
+ // is being created for the first time. This checks if we're in
1452
+ // a child state factory and the parent state factory already exists.
1453
+ if (this._parentFactory || this._actionsSubscription !== null) {
1434
1454
  return;
1455
+ }
1435
1456
  const dispatched$ = new Subject();
1436
1457
  this._actionsSubscription = this._actions
1437
1458
  .pipe(filter((ctx) => ctx.status === "DISPATCHED" /* Dispatched */), mergeMap(ctx => {
@@ -1497,7 +1518,7 @@ class StateFactory {
1497
1518
  }
1498
1519
  // The `NgxsUnhandledActionsLogger` is a tree-shakable class which functions
1499
1520
  // only during development.
1500
- if ((typeof ngDevMode === 'undefined' || ngDevMode) && !actionHasBeenHandled) {
1521
+ if (NG_DEV_MODE && !actionHasBeenHandled) {
1501
1522
  const unhandledActionsLogger = this._injector.get(NgxsUnhandledActionsLogger, null);
1502
1523
  // The `NgxsUnhandledActionsLogger` will not be resolved by the injector if the
1503
1524
  // `NgxsDevelopmentModule` is not provided. It's enough to check whether the `injector.get`
@@ -1516,9 +1537,7 @@ class StateFactory {
1516
1537
  const statesMap = this.statesByName;
1517
1538
  for (const stateClass of stateClasses) {
1518
1539
  const stateName = getStoreMetadata$1(stateClass).name;
1519
- // Caretaker note: we have still left the `typeof` condition in order to avoid
1520
- // creating a breaking change for projects that still use the View Engine.
1521
- if (typeof ngDevMode === 'undefined' || ngDevMode) {
1540
+ if (NG_DEV_MODE) {
1522
1541
  StoreValidators.checkThatStateNameIsUnique(stateName, stateClass, statesMap);
1523
1542
  }
1524
1543
  const unmountedState = !statesMap[stateName];
@@ -1536,15 +1555,10 @@ class StateFactory {
1536
1555
  // We will need to come up with an alternative in v4 because this is used by many plugins
1537
1556
  meta.path = path;
1538
1557
  }
1539
- /**
1540
- * @description
1541
- * the method checks if the state has already been added to the tree
1542
- * and completed the life cycle
1543
- * @param name
1544
- * @param path
1545
- */
1546
1558
  hasBeenMountedAndBootstrapped(name, path) {
1547
1559
  const valueIsBootstrappedInInitialState = getValue(this._initialState, path) !== undefined;
1560
+ // This checks whether a state has been already added to the global graph and
1561
+ // its lifecycle is in 'bootstrapped' state.
1548
1562
  return this.statesByName[name] && valueIsBootstrappedInInitialState;
1549
1563
  }
1550
1564
  }
@@ -1714,9 +1728,10 @@ class Store {
1714
1728
  }
1715
1729
  }
1716
1730
  /** @nocollapse */ Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store, deps: [{ token: StateStream }, { token: InternalStateOperations }, { token: NgxsConfig }, { token: InternalNgxsExecutionStrategy }, { token: StateFactory }, { token: INITIAL_STATE_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
1717
- /** @nocollapse */ Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store });
1731
+ /** @nocollapse */ Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store, providedIn: 'root' });
1718
1732
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Store, decorators: [{
1719
- type: Injectable
1733
+ type: Injectable,
1734
+ args: [{ providedIn: 'root' }]
1720
1735
  }], ctorParameters: function () { return [{ type: StateStream }, { type: InternalStateOperations }, { type: NgxsConfig }, { type: InternalNgxsExecutionStrategy }, { type: StateFactory }, { type: undefined, decorators: [{
1721
1736
  type: Optional
1722
1737
  }, {
@@ -1724,6 +1739,29 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
1724
1739
  args: [INITIAL_STATE_TOKEN]
1725
1740
  }] }]; } });
1726
1741
 
1742
+ /**
1743
+ * Allows the select decorator to get access to the DI store, this is used internally
1744
+ * in `@Select` decorator.
1745
+ */
1746
+ class SelectFactory {
1747
+ constructor(store, config) {
1748
+ SelectFactory.store = store;
1749
+ SelectFactory.config = config;
1750
+ }
1751
+ ngOnDestroy() {
1752
+ SelectFactory.store = null;
1753
+ SelectFactory.config = null;
1754
+ }
1755
+ }
1756
+ SelectFactory.store = null;
1757
+ SelectFactory.config = null;
1758
+ /** @nocollapse */ SelectFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, deps: [{ token: Store }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
1759
+ /** @nocollapse */ SelectFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, providedIn: 'root' });
1760
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, decorators: [{
1761
+ type: Injectable,
1762
+ args: [{ providedIn: 'root' }]
1763
+ }], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
1764
+
1727
1765
  class LifecycleStateManager {
1728
1766
  constructor(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
1729
1767
  this._store = _store;
@@ -1781,33 +1819,12 @@ class LifecycleStateManager {
1781
1819
  }
1782
1820
  }
1783
1821
  /** @nocollapse */ LifecycleStateManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager, deps: [{ token: Store }, { token: InternalErrorReporter }, { token: InternalStateOperations }, { token: StateContextFactory }, { token: i5.NgxsBootstrapper }], target: i0.ɵɵFactoryTarget.Injectable });
1784
- /** @nocollapse */ LifecycleStateManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager });
1822
+ /** @nocollapse */ LifecycleStateManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager, providedIn: 'root' });
1785
1823
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: LifecycleStateManager, decorators: [{
1786
- type: Injectable
1824
+ type: Injectable,
1825
+ args: [{ providedIn: 'root' }]
1787
1826
  }], ctorParameters: function () { return [{ type: Store }, { type: InternalErrorReporter }, { type: InternalStateOperations }, { type: StateContextFactory }, { type: i5.NgxsBootstrapper }]; } });
1788
1827
 
1789
- /**
1790
- * Allows the select decorator to get access to the DI store, this is used internally
1791
- * in `@Select` decorator.
1792
- */
1793
- class SelectFactory {
1794
- constructor(store, config) {
1795
- SelectFactory.store = store;
1796
- SelectFactory.config = config;
1797
- }
1798
- ngOnDestroy() {
1799
- SelectFactory.store = null;
1800
- SelectFactory.config = null;
1801
- }
1802
- }
1803
- SelectFactory.store = null;
1804
- SelectFactory.config = null;
1805
- /** @nocollapse */ SelectFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, deps: [{ token: Store }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
1806
- /** @nocollapse */ SelectFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory });
1807
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: SelectFactory, decorators: [{
1808
- type: Injectable
1809
- }], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
1810
-
1811
1828
  /**
1812
1829
  * Root module
1813
1830
  * @ignore
@@ -1880,18 +1897,6 @@ class NgxsModule {
1880
1897
  ngModule: NgxsRootModule,
1881
1898
  providers: [
1882
1899
  StateFactory,
1883
- StateContextFactory,
1884
- Actions,
1885
- InternalActions,
1886
- NgxsBootstrapper,
1887
- LifecycleStateManager,
1888
- InternalDispatcher,
1889
- InternalDispatchedActionResults,
1890
- InternalStateOperations,
1891
- InternalNgxsExecutionStrategy,
1892
- Store,
1893
- StateStream,
1894
- SelectFactory,
1895
1900
  PluginManager,
1896
1901
  ...states,
1897
1902
  ...NgxsModule.ngxsTokenProviders(states, options)
@@ -1905,6 +1910,7 @@ class NgxsModule {
1905
1910
  return {
1906
1911
  ngModule: NgxsFeatureModule,
1907
1912
  providers: [
1913
+ // This is required on the feature level, see comments in `state-factory.ts`.
1908
1914
  StateFactory,
1909
1915
  PluginManager,
1910
1916
  ...states,
@@ -1927,24 +1933,15 @@ class NgxsModule {
1927
1933
  useValue: states
1928
1934
  },
1929
1935
  {
1930
- provide: NgxsModule.ROOT_OPTIONS,
1936
+ provide: ROOT_OPTIONS,
1931
1937
  useValue: options
1932
1938
  },
1933
- {
1934
- provide: NgxsConfig,
1935
- useFactory: NgxsModule.ngxsConfigFactory,
1936
- deps: [NgxsModule.ROOT_OPTIONS]
1937
- },
1938
1939
  {
1939
1940
  provide: APP_BOOTSTRAP_LISTENER,
1940
1941
  useFactory: NgxsModule.appBootstrapListenerFactory,
1941
1942
  multi: true,
1942
1943
  deps: [NgxsBootstrapper]
1943
1944
  },
1944
- {
1945
- provide: INITIAL_STATE_TOKEN,
1946
- useFactory: NgxsModule.getInitialState
1947
- },
1948
1945
  {
1949
1946
  provide: ɵNGXS_STATE_CONTEXT_FACTORY,
1950
1947
  useExisting: StateContextFactory
@@ -1955,17 +1952,10 @@ class NgxsModule {
1955
1952
  }
1956
1953
  ];
1957
1954
  }
1958
- static ngxsConfigFactory(options) {
1959
- return mergeDeep(new NgxsConfig(), options);
1960
- }
1961
1955
  static appBootstrapListenerFactory(bootstrapper) {
1962
1956
  return () => bootstrapper.bootstrap();
1963
1957
  }
1964
- static getInitialState() {
1965
- return InitialState.pop();
1966
- }
1967
1958
  }
1968
- NgxsModule.ROOT_OPTIONS = new InjectionToken('ROOT_OPTIONS');
1969
1959
  /** @nocollapse */ NgxsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1970
1960
  /** @nocollapse */ NgxsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule });
1971
1961
  /** @nocollapse */ NgxsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsModule });