@ngxs/store 19.0.0-dev.master-5c4900f → 19.0.0-dev.master-81c7a7c

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,5 +1,5 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, inject, NgZone, InjectionToken, INJECTOR, DestroyRef, Injector, runInInjectionContext, ErrorHandler, ɵisPromise as _isPromise, computed, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, NgModule, APP_BOOTSTRAP_LISTENER, ApplicationRef, PendingTasks } from '@angular/core';
2
+ import { inject, Injectable, InjectionToken, DestroyRef, NgZone, Injector, runInInjectionContext, ErrorHandler, ɵisPromise as _isPromise, computed, makeEnvironmentProviders, provideEnvironmentInitializer, NgModule, APP_BOOTSTRAP_LISTENER, ApplicationRef, PendingTasks } from '@angular/core';
3
3
  import { config, Observable, Subject, share, forkJoin, map, throwError, shareReplay, filter, take, mergeMap, EMPTY, defaultIfEmpty, catchError, from, isObservable, takeUntil, finalize, distinctUntilChanged, startWith, skip, buffer, debounceTime } from 'rxjs';
4
4
  import { ɵwrapObserverCalls as _wrapObserverCalls, ɵOrderedSubject as _OrderedSubject, ɵStateStream as _StateStream, ɵof as _of, ɵmemoize as _memoize, ɵgetStoreMetadata as _getStoreMetadata, ɵgetSelectorMetadata as _getSelectorMetadata, ɵMETA_KEY as _META_KEY, ɵINITIAL_STATE_TOKEN as _INITIAL_STATE_TOKEN, ɵNgxsAppBootstrappedState as _NgxsAppBootstrappedState, ɵensureStoreMetadata as _ensureStoreMetadata, ɵMETA_OPTIONS_KEY as _META_OPTIONS_KEY, ɵensureSelectorMetadata as _ensureSelectorMetadata, ɵNGXS_STATE_CONTEXT_FACTORY as _NGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY as _NGXS_STATE_FACTORY } from '@ngxs/store/internals';
5
5
  export { StateToken } from '@ngxs/store/internals';
@@ -7,159 +7,6 @@ import { NGXS_PLUGINS, getActionTypeFromInstance, InitState, UpdateState, setVal
7
7
  export { InitState, NGXS_PLUGINS, UpdateState, actionMatcher, getActionTypeFromInstance, getValue, setValue } from '@ngxs/store/plugins';
8
8
  import { isStateOperator } from '@ngxs/store/operators';
9
9
 
10
- class NoopNgxsExecutionStrategy {
11
- enter(func) {
12
- return func();
13
- }
14
- leave(func) {
15
- return func();
16
- }
17
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
18
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, providedIn: 'root' }); }
19
- }
20
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, decorators: [{
21
- type: Injectable,
22
- args: [{ providedIn: 'root' }]
23
- }] });
24
-
25
- function throwStateNameError(name) {
26
- throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
27
- }
28
- function throwStateNamePropertyError() {
29
- throw new Error(`States must register a 'name' property.`);
30
- }
31
- function throwStateUniqueError(current, newName, oldName) {
32
- throw new Error(`State name '${current}' from ${newName} already exists in ${oldName}.`);
33
- }
34
- function throwStateDecoratorError(name) {
35
- throw new Error(`States must be decorated with @State() decorator, but "${name}" isn't.`);
36
- }
37
- function throwActionDecoratorError() {
38
- throw new Error('@Action() decorator cannot be used with static methods.');
39
- }
40
- function throwSelectorDecoratorError() {
41
- throw new Error('Selectors only work on methods.');
42
- }
43
- function getZoneWarningMessage() {
44
- return ('Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
45
- 'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
46
- 'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })');
47
- }
48
- function getUndecoratedStateWithInjectableWarningMessage(name) {
49
- return `'${name}' class should be decorated with @Injectable() right after the @State() decorator`;
50
- }
51
- function getInvalidInitializationOrderMessage(addedStates) {
52
- let message = 'You have an invalid state initialization order. This typically occurs when `NgxsModule.forFeature`\n' +
53
- 'or `provideStates` is called before `NgxsModule.forRoot` or `provideStore`.\n' +
54
- 'One example is when `NgxsRouterPluginModule.forRoot` is called before `NgxsModule.forRoot`.';
55
- if (addedStates) {
56
- const stateNames = Object.keys(addedStates).map(stateName => `"${stateName}"`);
57
- message +=
58
- '\nFeature states added before the store initialization is complete: ' +
59
- `${stateNames.join(', ')}.`;
60
- }
61
- return message;
62
- }
63
- function throwSelectFactoryNotConnectedError() {
64
- throw new Error('You have forgotten to import the NGXS module!');
65
- }
66
- function throwPatchingArrayError() {
67
- throw new Error('Patching arrays is not supported.');
68
- }
69
- function throwPatchingPrimitiveError() {
70
- throw new Error('Patching primitives is not supported.');
71
- }
72
-
73
- class DispatchOutsideZoneNgxsExecutionStrategy {
74
- constructor() {
75
- this._ngZone = inject(NgZone);
76
- if (typeof ngDevMode !== 'undefined' && ngDevMode) {
77
- verifyZoneIsNotNooped(this._ngZone);
78
- }
79
- }
80
- enter(func) {
81
- if (typeof ngServerMode !== 'undefined' && ngServerMode) {
82
- return this.runInsideAngular(func);
83
- }
84
- return this.runOutsideAngular(func);
85
- }
86
- leave(func) {
87
- return this.runInsideAngular(func);
88
- }
89
- runInsideAngular(func) {
90
- if (NgZone.isInAngularZone()) {
91
- return func();
92
- }
93
- return this._ngZone.run(func);
94
- }
95
- runOutsideAngular(func) {
96
- if (NgZone.isInAngularZone()) {
97
- return this._ngZone.runOutsideAngular(func);
98
- }
99
- return func();
100
- }
101
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
102
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: 'root' }); }
103
- }
104
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, decorators: [{
105
- type: Injectable,
106
- args: [{ providedIn: 'root' }]
107
- }], ctorParameters: () => [] });
108
- // Caretaker note: this should exist as a separate function and not a class method,
109
- // since class methods are not tree-shakable.
110
- function verifyZoneIsNotNooped(ngZone) {
111
- // `NoopNgZone` is not exposed publicly as it doesn't expect
112
- // to be used outside of the core Angular code, thus we just have
113
- // to check if the zone doesn't extend or instanceof `NgZone`.
114
- if (ngZone instanceof NgZone) {
115
- return;
116
- }
117
- console.warn(getZoneWarningMessage());
118
- }
119
-
120
- /**
121
- * Consumers have the option to utilize the execution strategy provided by
122
- * `NgxsModule.forRoot({executionStrategy})` or `provideStore([], {executionStrategy})`.
123
- */
124
- const CUSTOM_NGXS_EXECUTION_STRATEGY = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'CUSTOM_NGXS_EXECUTION_STRATEGY' : '');
125
- /**
126
- * The injection token is used internally to resolve an instance of the execution
127
- * strategy. It checks whether consumers have provided their own `executionStrategy`
128
- * and also verifies if we are operating in a zone-aware environment.
129
- */
130
- const NGXS_EXECUTION_STRATEGY = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_EXECUTION_STRATEGY' : '', {
131
- providedIn: 'root',
132
- factory: () => {
133
- const ngZone = inject(NgZone);
134
- const injector = inject(INJECTOR);
135
- const executionStrategy = injector.get(CUSTOM_NGXS_EXECUTION_STRATEGY);
136
- const isNgZoneEnabled = ngZone instanceof NgZone;
137
- return executionStrategy
138
- ? injector.get(executionStrategy)
139
- : injector.get(isNgZoneEnabled
140
- ? DispatchOutsideZoneNgxsExecutionStrategy
141
- : NoopNgxsExecutionStrategy);
142
- }
143
- });
144
-
145
- class InternalNgxsExecutionStrategy {
146
- constructor() {
147
- this._executionStrategy = inject(NGXS_EXECUTION_STRATEGY);
148
- }
149
- enter(func) {
150
- return this._executionStrategy.enter(func);
151
- }
152
- leave(func) {
153
- return this._executionStrategy.leave(func);
154
- }
155
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
156
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' }); }
157
- }
158
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
159
- type: Injectable,
160
- args: [{ providedIn: 'root' }]
161
- }] });
162
-
163
10
  class PluginManager {
164
11
  constructor() {
165
12
  this.plugins = [];
@@ -271,6 +118,90 @@ function fallbackSubscriber(ngZone) {
271
118
  };
272
119
  }
273
120
 
121
+ // The injection token is used to resolve a list of states provided at
122
+ // the root level through either `NgxsModule.forRoot` or `provideStore`.
123
+ const ROOT_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'ROOT_STATE_TOKEN' : '');
124
+ // The injection token is used to resolve a list of states provided at
125
+ // the feature level through either `NgxsModule.forFeature` or `provideStates`.
126
+ // The Array<Array> is used to overload the resolved value of the token because
127
+ // it is a multi-provider token.
128
+ const FEATURE_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'FEATURE_STATE_TOKEN' : '');
129
+ // The injection token is used to resolve to options provided at the root
130
+ // level through either `NgxsModule.forRoot` or `provideStore`.
131
+ const NGXS_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_OPTIONS' : '');
132
+ /**
133
+ * The NGXS config settings.
134
+ */
135
+ class NgxsConfig {
136
+ constructor() {
137
+ this.compatibility = {
138
+ strictContentSecurityPolicy: false
139
+ };
140
+ /**
141
+ * Defining shared selector options
142
+ */
143
+ this.selectorOptions = {
144
+ injectContainerState: false,
145
+ suppressErrors: false
146
+ };
147
+ }
148
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
149
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: () => {
150
+ const defaultConfig = new NgxsConfig();
151
+ const config = inject(NGXS_OPTIONS);
152
+ return {
153
+ ...defaultConfig,
154
+ ...config,
155
+ selectorOptions: {
156
+ ...defaultConfig.selectorOptions,
157
+ ...config.selectorOptions
158
+ }
159
+ };
160
+ } }); }
161
+ }
162
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, decorators: [{
163
+ type: Injectable,
164
+ args: [{
165
+ providedIn: 'root',
166
+ useFactory: () => {
167
+ const defaultConfig = new NgxsConfig();
168
+ const config = inject(NGXS_OPTIONS);
169
+ return {
170
+ ...defaultConfig,
171
+ ...config,
172
+ selectorOptions: {
173
+ ...defaultConfig.selectorOptions,
174
+ ...config.selectorOptions
175
+ }
176
+ };
177
+ }
178
+ }]
179
+ }] });
180
+ /**
181
+ * Represents a basic change from a previous to a new value for a single state instance.
182
+ * Passed as a value in a NgxsSimpleChanges object to the ngxsOnChanges hook.
183
+ */
184
+ class NgxsSimpleChange {
185
+ constructor(previousValue, currentValue, firstChange) {
186
+ this.previousValue = previousValue;
187
+ this.currentValue = currentValue;
188
+ this.firstChange = firstChange;
189
+ }
190
+ }
191
+
192
+ /**
193
+ * The injection token is used internally to resolve an instance of the execution
194
+ * strategy. It checks whether consumers have provided their own `executionStrategy`
195
+ * and also verifies if we are operating in a zone-aware environment.
196
+ */
197
+ const NGXS_EXECUTION_STRATEGY = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_EXECUTION_STRATEGY' : '', {
198
+ providedIn: 'root',
199
+ factory: () => {
200
+ const options = inject(NGXS_OPTIONS);
201
+ return inject(options.executionStrategy);
202
+ }
203
+ });
204
+
274
205
  /**
275
206
  * Internal Action result stream that is emitted when an action is completed.
276
207
  * This is used as a method of returning the action result to the dispatcher
@@ -331,7 +262,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
331
262
  class Actions extends Observable {
332
263
  constructor() {
333
264
  const internalActions$ = inject(InternalActions);
334
- const internalExecutionStrategy = inject(InternalNgxsExecutionStrategy);
265
+ const internalExecutionStrategy = inject(NGXS_EXECUTION_STRATEGY);
335
266
  const sharedInternalActions$ = internalActions$.pipe(leaveNgxs(internalExecutionStrategy),
336
267
  // The `InternalActions` subject emits outside of the Angular zone.
337
268
  // We have to re-enter the Angular zone for any incoming consumer.
@@ -362,7 +293,7 @@ class InternalDispatcher {
362
293
  this._actionResults = inject(InternalDispatchedActionResults);
363
294
  this._pluginManager = inject(PluginManager);
364
295
  this._stateStream = inject(_StateStream);
365
- this._ngxsExecutionStrategy = inject(InternalNgxsExecutionStrategy);
296
+ this._ngxsExecutionStrategy = inject(NGXS_EXECUTION_STRATEGY);
366
297
  this._injector = inject(Injector);
367
298
  }
368
299
  /**
@@ -455,89 +386,6 @@ const compose = (injector, funcs) => (...args) => {
455
386
  return runInInjectionContext(injector, () => curr(...args, (...nextArgs) => compose(injector, funcs)(...nextArgs)));
456
387
  };
457
388
 
458
- // The injection token is used to resolve a list of states provided at
459
- // the root level through either `NgxsModule.forRoot` or `provideStore`.
460
- const ROOT_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'ROOT_STATE_TOKEN' : '');
461
- // The injection token is used to resolve a list of states provided at
462
- // the feature level through either `NgxsModule.forFeature` or `provideStates`.
463
- // The Array<Array> is used to overload the resolved value of the token because
464
- // it is a multi-provider token.
465
- const FEATURE_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'FEATURE_STATE_TOKEN' : '');
466
- // The injection token is used to resolve to options provided at the root
467
- // level through either `NgxsModule.forRoot` or `provideStore`.
468
- const NGXS_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_OPTIONS' : '');
469
- /**
470
- * The NGXS config settings.
471
- */
472
- class NgxsConfig {
473
- constructor() {
474
- this.compatibility = {
475
- strictContentSecurityPolicy: false
476
- };
477
- /**
478
- * Determines the execution context to perform async operations inside. An implementation can be
479
- * provided to override the default behaviour where the async operations are run
480
- * outside Angular's zone but all observable behaviours of NGXS are run back inside Angular's zone.
481
- * These observable behaviours are from:
482
- * `store.selectSignal(...)`, `store.select(...)`, `actions.subscribe(...)` or `store.dispatch(...).subscribe(...)`
483
- * Every `zone.run` causes Angular to run change detection on the whole tree (`app.tick()`) so of your
484
- * application doesn't rely on zone.js running change detection then you can switch to the
485
- * `NoopNgxsExecutionStrategy` that doesn't interact with zones.
486
- * (default: null)
487
- */
488
- this.executionStrategy = DispatchOutsideZoneNgxsExecutionStrategy;
489
- /**
490
- * Defining shared selector options
491
- */
492
- this.selectorOptions = {
493
- injectContainerState: false,
494
- suppressErrors: false
495
- };
496
- }
497
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
498
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: () => {
499
- const defaultConfig = new NgxsConfig();
500
- const config = inject(NGXS_OPTIONS);
501
- return {
502
- ...defaultConfig,
503
- ...config,
504
- selectorOptions: {
505
- ...defaultConfig.selectorOptions,
506
- ...config.selectorOptions
507
- }
508
- };
509
- } }); }
510
- }
511
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, decorators: [{
512
- type: Injectable,
513
- args: [{
514
- providedIn: 'root',
515
- useFactory: () => {
516
- const defaultConfig = new NgxsConfig();
517
- const config = inject(NGXS_OPTIONS);
518
- return {
519
- ...defaultConfig,
520
- ...config,
521
- selectorOptions: {
522
- ...defaultConfig.selectorOptions,
523
- ...config.selectorOptions
524
- }
525
- };
526
- }
527
- }]
528
- }] });
529
- /**
530
- * Represents a basic change from a previous to a new value for a single state instance.
531
- * Passed as a value in a NgxsSimpleChanges object to the ngxsOnChanges hook.
532
- */
533
- class NgxsSimpleChange {
534
- constructor(previousValue, currentValue, firstChange) {
535
- this.previousValue = previousValue;
536
- this.currentValue = currentValue;
537
- this.firstChange = firstChange;
538
- }
539
- }
540
-
541
389
  /**
542
390
  * Object freeze code
543
391
  * https://github.com/jsdf/deep-freeze
@@ -938,6 +786,54 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
938
786
  args: [{ providedIn: 'root' }]
939
787
  }], ctorParameters: () => [] });
940
788
 
789
+ function throwStateNameError(name) {
790
+ throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
791
+ }
792
+ function throwStateNamePropertyError() {
793
+ throw new Error(`States must register a 'name' property.`);
794
+ }
795
+ function throwStateUniqueError(current, newName, oldName) {
796
+ throw new Error(`State name '${current}' from ${newName} already exists in ${oldName}.`);
797
+ }
798
+ function throwStateDecoratorError(name) {
799
+ throw new Error(`States must be decorated with @State() decorator, but "${name}" isn't.`);
800
+ }
801
+ function throwActionDecoratorError() {
802
+ throw new Error('@Action() decorator cannot be used with static methods.');
803
+ }
804
+ function throwSelectorDecoratorError() {
805
+ throw new Error('Selectors only work on methods.');
806
+ }
807
+ function getZoneWarningMessage() {
808
+ return ('Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
809
+ 'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
810
+ 'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })');
811
+ }
812
+ function getUndecoratedStateWithInjectableWarningMessage(name) {
813
+ return `'${name}' class should be decorated with @Injectable() right after the @State() decorator`;
814
+ }
815
+ function getInvalidInitializationOrderMessage(addedStates) {
816
+ let message = 'You have an invalid state initialization order. This typically occurs when `NgxsModule.forFeature`\n' +
817
+ 'or `provideStates` is called before `NgxsModule.forRoot` or `provideStore`.\n' +
818
+ 'One example is when `NgxsRouterPluginModule.forRoot` is called before `NgxsModule.forRoot`.';
819
+ if (addedStates) {
820
+ const stateNames = Object.keys(addedStates).map(stateName => `"${stateName}"`);
821
+ message +=
822
+ '\nFeature states added before the store initialization is complete: ' +
823
+ `${stateNames.join(', ')}.`;
824
+ }
825
+ return message;
826
+ }
827
+ function throwSelectFactoryNotConnectedError() {
828
+ throw new Error('You have forgotten to import the NGXS module!');
829
+ }
830
+ function throwPatchingArrayError() {
831
+ throw new Error('Patching arrays is not supported.');
832
+ }
833
+ function throwPatchingPrimitiveError() {
834
+ throw new Error('Patching primitives is not supported.');
835
+ }
836
+
941
837
  const stateNameRegex = /* @__PURE__ */ new RegExp('^[a-zA-Z0-9_]+$');
942
838
  function ensureStateNameIsValid(name) {
943
839
  if (!name) {
@@ -1535,7 +1431,7 @@ class Store {
1535
1431
  this._stateStream = inject(_StateStream);
1536
1432
  this._internalStateOperations = inject(InternalStateOperations);
1537
1433
  this._config = inject(NgxsConfig);
1538
- this._internalExecutionStrategy = inject(InternalNgxsExecutionStrategy);
1434
+ this._internalExecutionStrategy = inject(NGXS_EXECUTION_STRATEGY);
1539
1435
  this._stateFactory = inject(StateFactory);
1540
1436
  /**
1541
1437
  * This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
@@ -1854,13 +1750,7 @@ const NGXS_ROOT_STORE_INITIALIZER = new InjectionToken(typeof ngDevMode !== 'und
1854
1750
  const NGXS_FEATURE_STORE_INITIALIZER = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_FEATURE_STORE_INITIALIZER' : '');
1855
1751
  const NGXS_ROOT_ENVIRONMENT_INITIALIZER = [
1856
1752
  { provide: NGXS_ROOT_STORE_INITIALIZER, useFactory: rootStoreInitializer },
1857
- {
1858
- provide: ENVIRONMENT_INITIALIZER,
1859
- multi: true,
1860
- useFactory() {
1861
- return () => inject(NGXS_ROOT_STORE_INITIALIZER);
1862
- }
1863
- }
1753
+ provideEnvironmentInitializer(() => inject(NGXS_ROOT_STORE_INITIALIZER))
1864
1754
  ];
1865
1755
  /**
1866
1756
  * The `NGXS_FEATURE_ENVIRONMENT_INITIALIZER` functions as an environment initializer
@@ -1870,13 +1760,7 @@ const NGXS_ROOT_ENVIRONMENT_INITIALIZER = [
1870
1760
  */
1871
1761
  const NGXS_FEATURE_ENVIRONMENT_INITIALIZER = [
1872
1762
  { provide: NGXS_FEATURE_STORE_INITIALIZER, useFactory: featureStatesInitializer },
1873
- {
1874
- provide: ENVIRONMENT_INITIALIZER,
1875
- multi: true,
1876
- useFactory() {
1877
- return () => inject(NGXS_FEATURE_STORE_INITIALIZER);
1878
- }
1879
- }
1763
+ provideEnvironmentInitializer(() => inject(NGXS_FEATURE_STORE_INITIALIZER))
1880
1764
  ];
1881
1765
 
1882
1766
  /**
@@ -1931,10 +1815,6 @@ function getRootProviders(states, options) {
1931
1815
  {
1932
1816
  provide: NGXS_OPTIONS,
1933
1817
  useValue: options
1934
- },
1935
- {
1936
- provide: CUSTOM_NGXS_EXECUTION_STRATEGY,
1937
- useValue: options.executionStrategy
1938
1818
  }
1939
1819
  ];
1940
1820
  }
@@ -1956,7 +1836,7 @@ function getFeatureProviders(states) {
1956
1836
  }
1957
1837
 
1958
1838
  class NgxsModule {
1959
- static forRoot(states = [], options = {}) {
1839
+ static forRoot(states = [], options) {
1960
1840
  return {
1961
1841
  ngModule: NgxsRootModule,
1962
1842
  providers: getRootProviders(states, options)
@@ -2180,6 +2060,68 @@ function Selector(selectors) {
2180
2060
  };
2181
2061
  }
2182
2062
 
2063
+ class DispatchOutsideZoneNgxsExecutionStrategy {
2064
+ constructor() {
2065
+ this._ngZone = inject(NgZone);
2066
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
2067
+ verifyZoneIsNotNooped(this._ngZone);
2068
+ }
2069
+ }
2070
+ enter(func) {
2071
+ if (typeof ngServerMode !== 'undefined' && ngServerMode) {
2072
+ return this.runInsideAngular(func);
2073
+ }
2074
+ return this.runOutsideAngular(func);
2075
+ }
2076
+ leave(func) {
2077
+ return this.runInsideAngular(func);
2078
+ }
2079
+ runInsideAngular(func) {
2080
+ if (NgZone.isInAngularZone()) {
2081
+ return func();
2082
+ }
2083
+ return this._ngZone.run(func);
2084
+ }
2085
+ runOutsideAngular(func) {
2086
+ if (NgZone.isInAngularZone()) {
2087
+ return this._ngZone.runOutsideAngular(func);
2088
+ }
2089
+ return func();
2090
+ }
2091
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
2092
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: 'root' }); }
2093
+ }
2094
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, decorators: [{
2095
+ type: Injectable,
2096
+ args: [{ providedIn: 'root' }]
2097
+ }], ctorParameters: () => [] });
2098
+ // Caretaker note: this should exist as a separate function and not a class method,
2099
+ // since class methods are not tree-shakable.
2100
+ function verifyZoneIsNotNooped(ngZone) {
2101
+ // `NoopNgZone` is not exposed publicly as it doesn't expect
2102
+ // to be used outside of the core Angular code, thus we just have
2103
+ // to check if the zone doesn't extend or instanceof `NgZone`.
2104
+ if (ngZone instanceof NgZone) {
2105
+ return;
2106
+ }
2107
+ console.warn(getZoneWarningMessage());
2108
+ }
2109
+
2110
+ class NoopNgxsExecutionStrategy {
2111
+ enter(func) {
2112
+ return func();
2113
+ }
2114
+ leave(func) {
2115
+ return func();
2116
+ }
2117
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
2118
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, providedIn: 'root' }); }
2119
+ }
2120
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, decorators: [{
2121
+ type: Injectable,
2122
+ args: [{ providedIn: 'root' }]
2123
+ }] });
2124
+
2183
2125
  class NgxsDevelopmentModule {
2184
2126
  static forRoot(options) {
2185
2127
  return {
@@ -2375,28 +2317,30 @@ function withNgxsPendingTasks() {
2375
2317
  });
2376
2318
  }
2377
2319
 
2378
- function provideStore(states = [], ...optionsAndFeatures) {
2379
- const features = [];
2380
- // Options are empty by default (see `forRoot`).
2381
- let options = {};
2382
- if (optionsAndFeatures.length > 0) {
2383
- if (isEnvironmentProvider(optionsAndFeatures[0])) {
2384
- features.push(...optionsAndFeatures);
2385
- }
2386
- else {
2387
- options = optionsAndFeatures[0];
2388
- features.push(...optionsAndFeatures.slice(1));
2389
- }
2390
- }
2320
+ /**
2321
+ * This function provides global store providers and initializes the store.
2322
+ *
2323
+ * ```ts
2324
+ * bootstrapApplication(AppComponent, {
2325
+ * providers: [provideStore([CountriesState])]
2326
+ * });
2327
+ * ```
2328
+ *
2329
+ * The `provideStore` may be optionally called with a config before the list of features:
2330
+ *
2331
+ * ```ts
2332
+ * provideStore([CountriesState], {
2333
+ * developmentMode: !environment.production
2334
+ * });
2335
+ * ```
2336
+ */
2337
+ function provideStore(states = [], options, ...features) {
2391
2338
  return makeEnvironmentProviders([
2392
2339
  ...getRootProviders(states, options),
2393
2340
  NGXS_ROOT_ENVIRONMENT_INITIALIZER,
2394
2341
  features
2395
2342
  ]);
2396
2343
  }
2397
- function isEnvironmentProvider(target) {
2398
- return !!target.ɵproviders;
2399
- }
2400
2344
 
2401
2345
  /**
2402
2346
  * This version serves as a standalone alternative to `NgxsModule.forFeature`.
@@ -2443,11 +2387,7 @@ function withNgxsPlugin(plugin) {
2443
2387
  // We should inject the `PluginManager` to retrieve `NGXS_PLUGINS` and
2444
2388
  // register those plugins. The plugin can be added from inside the child
2445
2389
  // route, so the plugin manager should be re-injected.
2446
- {
2447
- provide: ENVIRONMENT_INITIALIZER,
2448
- useValue: () => inject(PluginManager),
2449
- multi: true
2450
- }
2390
+ provideEnvironmentInitializer(() => inject(PluginManager))
2451
2391
  ]);
2452
2392
  }
2453
2393
 
@@ -2518,5 +2458,5 @@ function ɵprovideNgxsInternalStateTokens() {
2518
2458
  * Generated bundle index. Do not edit.
2519
2459
  */
2520
2460
 
2521
- export { Action, Actions, NgxsConfig, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NgxsUnhandledErrorHandler, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, Store, createDispatchMap, createModelSelector, createPickSelector, createPropertySelectors, createSelectMap, createSelector, dispatch, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, select, withNgxsDevelopmentOptions, withNgxsPendingTasks, withNgxsPlugin, withNgxsPreboot, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule, ɵprovideNgxsInternalStateTokens };
2461
+ export { Action, Actions, DispatchOutsideZoneNgxsExecutionStrategy, NgxsConfig, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NgxsUnhandledErrorHandler, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, Store, createDispatchMap, createModelSelector, createPickSelector, createPropertySelectors, createSelectMap, createSelector, dispatch, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, select, withNgxsDevelopmentOptions, withNgxsPendingTasks, withNgxsPlugin, withNgxsPreboot, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule, ɵprovideNgxsInternalStateTokens };
2522
2462
  //# sourceMappingURL=ngxs-store.mjs.map