@ngxs/store 18.1.5 → 18.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/esm2022/internals/initial-state.mjs +2 -3
  2. package/esm2022/internals/internal-tokens.mjs +3 -4
  3. package/esm2022/plugins/index.mjs +2 -2
  4. package/esm2022/plugins/symbols.mjs +14 -5
  5. package/esm2022/src/actions-stream.mjs +7 -6
  6. package/esm2022/src/dev-features/ngxs-unhandled-actions-logger.mjs +6 -8
  7. package/esm2022/src/dev-features/symbols.mjs +3 -3
  8. package/esm2022/src/execution/dispatch-outside-zone-ngxs-execution-strategy.mjs +9 -12
  9. package/esm2022/src/execution/internal-ngxs-execution-strategy.mjs +6 -9
  10. package/esm2022/src/execution/symbols.mjs +3 -4
  11. package/esm2022/src/internal/dispatcher.mjs +44 -25
  12. package/esm2022/src/internal/internals.mjs +4 -5
  13. package/esm2022/src/internal/lifecycle-state-manager.mjs +10 -15
  14. package/esm2022/src/internal/state-context-factory.mjs +6 -7
  15. package/esm2022/src/internal/state-factory.mjs +41 -61
  16. package/esm2022/src/internal/state-operations.mjs +8 -11
  17. package/esm2022/src/internal/unhandled-rxjs-error-callback.mjs +20 -13
  18. package/esm2022/src/plugin-manager.mjs +4 -3
  19. package/esm2022/src/selectors/selector-utils.mjs +2 -3
  20. package/esm2022/src/standalone-features/feature-providers.mjs +1 -3
  21. package/esm2022/src/standalone-features/initializers.mjs +9 -4
  22. package/esm2022/src/standalone-features/plugin.mjs +10 -4
  23. package/esm2022/src/standalone-features/preboot.mjs +2 -3
  24. package/esm2022/src/standalone-features/root-providers.mjs +1 -5
  25. package/esm2022/src/store.mjs +14 -24
  26. package/esm2022/src/symbols.mjs +4 -5
  27. package/fesm2022/ngxs-store-internals.mjs +3 -5
  28. package/fesm2022/ngxs-store-internals.mjs.map +1 -1
  29. package/fesm2022/ngxs-store-plugins.mjs +14 -5
  30. package/fesm2022/ngxs-store-plugins.mjs.map +1 -1
  31. package/fesm2022/ngxs-store.mjs +187 -212
  32. package/fesm2022/ngxs-store.mjs.map +1 -1
  33. package/index.d.ts +33 -184
  34. package/package.json +7 -7
  35. package/plugins/index.d.ts +12 -5
  36. package/schematics/src/utils/versions.json +1 -1
  37. package/esm2022/src/utils/compose.mjs +0 -26
@@ -1,12 +1,11 @@
1
1
  import * as i0 from '@angular/core';
2
- import { Injectable, NgZone, PLATFORM_ID, Inject, InjectionToken, inject, INJECTOR, ErrorHandler, Injector, ɵisPromise as _isPromise, computed, Optional, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
3
- import { Subject, filter, Observable, share, config, of, forkJoin, throwError, EMPTY, mergeMap, map as map$1, defaultIfEmpty, catchError, from, isObservable, takeUntil, finalize, shareReplay as shareReplay$1, distinctUntilChanged, take as take$1, ReplaySubject } from 'rxjs';
4
- import * as i1 from '@ngxs/store/internals';
5
- import { ɵwrapObserverCalls as _wrapObserverCalls, ɵOrderedSubject as _OrderedSubject, ɵ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';
2
+ import { Injectable, inject, NgZone, PLATFORM_ID, InjectionToken, INJECTOR, Injector, runInInjectionContext, ErrorHandler, ɵisPromise as _isPromise, computed, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core';
3
+ import { Subject, filter, Observable, share, config, of, forkJoin, throwError, mergeMap as mergeMap$1, map as map$1, defaultIfEmpty, catchError, from, isObservable, takeUntil, finalize, shareReplay as shareReplay$1, distinctUntilChanged, take as take$1, ReplaySubject } from 'rxjs';
4
+ import { ɵwrapObserverCalls as _wrapObserverCalls, ɵOrderedSubject as _OrderedSubject, ɵStateStream as _StateStream, ɵ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';
6
5
  export { StateToken } from '@ngxs/store/internals';
7
6
  import { isPlatformServer } from '@angular/common';
8
- import { map, shareReplay, filter as filter$1, take, exhaustMap, tap, mergeMap as mergeMap$1, takeUntil as takeUntil$1, startWith, pairwise } from 'rxjs/operators';
9
- import { NGXS_PLUGINS, getActionTypeFromInstance, InitState, UpdateState, setValue, getValue } from '@ngxs/store/plugins';
7
+ import { map, shareReplay, filter as filter$1, take, mergeMap, tap, takeUntil as takeUntil$1, startWith, pairwise } from 'rxjs/operators';
8
+ import { NGXS_PLUGINS, getActionTypeFromInstance, InitState, UpdateState, setValue, getValue, ɵisPluginClass as _isPluginClass } from '@ngxs/store/plugins';
10
9
  export { InitState, NGXS_PLUGINS, UpdateState, actionMatcher, getActionTypeFromInstance, getValue, setValue } from '@ngxs/store/plugins';
11
10
  import { isStateOperator } from '@ngxs/store/operators';
12
11
 
@@ -74,15 +73,15 @@ function throwPatchingPrimitiveError() {
74
73
  }
75
74
 
76
75
  class DispatchOutsideZoneNgxsExecutionStrategy {
77
- constructor(_ngZone, _platformId) {
78
- this._ngZone = _ngZone;
79
- this._platformId = _platformId;
76
+ constructor() {
77
+ this._ngZone = inject(NgZone);
78
+ this._isServer = isPlatformServer(inject(PLATFORM_ID));
80
79
  if (typeof ngDevMode !== 'undefined' && ngDevMode) {
81
- verifyZoneIsNotNooped(_ngZone);
80
+ verifyZoneIsNotNooped(this._ngZone);
82
81
  }
83
82
  }
84
83
  enter(func) {
85
- if (isPlatformServer(this._platformId)) {
84
+ if (this._isServer) {
86
85
  return this.runInsideAngular(func);
87
86
  }
88
87
  return this.runOutsideAngular(func);
@@ -102,16 +101,13 @@ class DispatchOutsideZoneNgxsExecutionStrategy {
102
101
  }
103
102
  return func();
104
103
  }
105
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, deps: [{ token: i0.NgZone }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable }); }
104
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
106
105
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: 'root' }); }
107
106
  }
108
107
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, decorators: [{
109
108
  type: Injectable,
110
109
  args: [{ providedIn: 'root' }]
111
- }], ctorParameters: () => [{ type: i0.NgZone }, { type: undefined, decorators: [{
112
- type: Inject,
113
- args: [PLATFORM_ID]
114
- }] }] });
110
+ }], ctorParameters: () => [] });
115
111
  // Caretaker note: this should exist as a separate function and not a class method,
116
112
  // since class methods are not tree-shakable.
117
113
  function verifyZoneIsNotNooped(ngZone) {
@@ -124,18 +120,17 @@ function verifyZoneIsNotNooped(ngZone) {
124
120
  console.warn(getZoneWarningMessage());
125
121
  }
126
122
 
127
- const NG_DEV_MODE$9 = typeof ngDevMode !== 'undefined' && ngDevMode;
128
123
  /**
129
124
  * Consumers have the option to utilize the execution strategy provided by
130
125
  * `NgxsModule.forRoot({executionStrategy})` or `provideStore([], {executionStrategy})`.
131
126
  */
132
- const CUSTOM_NGXS_EXECUTION_STRATEGY = new InjectionToken(NG_DEV_MODE$9 ? 'CUSTOM_NGXS_EXECUTION_STRATEGY' : '');
127
+ const CUSTOM_NGXS_EXECUTION_STRATEGY = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'CUSTOM_NGXS_EXECUTION_STRATEGY' : '');
133
128
  /**
134
129
  * The injection token is used internally to resolve an instance of the execution
135
130
  * strategy. It checks whether consumers have provided their own `executionStrategy`
136
131
  * and also verifies if we are operating in a zone-aware environment.
137
132
  */
138
- const NGXS_EXECUTION_STRATEGY = new InjectionToken(NG_DEV_MODE$9 ? 'NGXS_EXECUTION_STRATEGY' : '', {
133
+ const NGXS_EXECUTION_STRATEGY = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_EXECUTION_STRATEGY' : '', {
139
134
  providedIn: 'root',
140
135
  factory: () => {
141
136
  const ngZone = inject(NgZone);
@@ -151,8 +146,8 @@ const NGXS_EXECUTION_STRATEGY = new InjectionToken(NG_DEV_MODE$9 ? 'NGXS_EXECUTI
151
146
  });
152
147
 
153
148
  class InternalNgxsExecutionStrategy {
154
- constructor(_executionStrategy) {
155
- this._executionStrategy = _executionStrategy;
149
+ constructor() {
150
+ this._executionStrategy = inject(NGXS_EXECUTION_STRATEGY);
156
151
  }
157
152
  enter(func) {
158
153
  return this._executionStrategy.enter(func);
@@ -160,42 +155,13 @@ class InternalNgxsExecutionStrategy {
160
155
  leave(func) {
161
156
  return this._executionStrategy.leave(func);
162
157
  }
163
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [{ token: NGXS_EXECUTION_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable }); }
158
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
164
159
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' }); }
165
160
  }
166
161
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
167
162
  type: Injectable,
168
163
  args: [{ providedIn: 'root' }]
169
- }], ctorParameters: () => [{ type: undefined, decorators: [{
170
- type: Inject,
171
- args: [NGXS_EXECUTION_STRATEGY]
172
- }] }] });
173
-
174
- /**
175
- * Composes a array of functions from left to right. Example:
176
- *
177
- * compose([fn, final])(state, action);
178
- *
179
- * then the funcs have a signature like:
180
- *
181
- * function fn (state, action, next) {
182
- * console.log('here', state, action, next);
183
- * return next(state, action);
184
- * }
185
- *
186
- * function final (state, action) {
187
- * console.log('here', state, action);
188
- * return state;
189
- * }
190
- *
191
- * the last function should not call `next`.
192
- *
193
- * @ignore
194
- */
195
- const compose = (funcs) => (...args) => {
196
- const curr = funcs.shift();
197
- return curr(...args, (...nextArgs) => compose(funcs)(...nextArgs));
198
- };
164
+ }] });
199
165
 
200
166
  /**
201
167
  * Returns operator that will run
@@ -234,7 +200,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImpor
234
200
  * You can listen to this in services to react without stores.
235
201
  */
236
202
  class Actions extends Observable {
237
- constructor(internalActions$, internalExecutionStrategy) {
203
+ constructor() {
204
+ const internalActions$ = inject(InternalActions);
205
+ const internalExecutionStrategy = inject(InternalNgxsExecutionStrategy);
238
206
  const sharedInternalActions$ = internalActions$.pipe(leaveNgxs(internalExecutionStrategy),
239
207
  // The `InternalActions` subject emits outside of the Angular zone.
240
208
  // We have to re-enter the Angular zone for any incoming consumer.
@@ -250,13 +218,13 @@ class Actions extends Observable {
250
218
  observer.add(childSubscription);
251
219
  });
252
220
  }
253
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: Actions, deps: [{ token: InternalActions }, { token: InternalNgxsExecutionStrategy }], target: i0.ɵɵFactoryTarget.Injectable }); }
221
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: Actions, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
254
222
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: Actions, providedIn: 'root' }); }
255
223
  }
256
224
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: Actions, decorators: [{
257
225
  type: Injectable,
258
226
  args: [{ providedIn: 'root' }]
259
- }], ctorParameters: () => [{ type: InternalActions }, { type: InternalNgxsExecutionStrategy }] });
227
+ }], ctorParameters: () => [] });
260
228
 
261
229
  class PluginManager {
262
230
  constructor() {
@@ -282,26 +250,34 @@ class PluginManager {
282
250
  return handlers.map((plugin) => (plugin.handle ? plugin.handle.bind(plugin) : plugin));
283
251
  }
284
252
  /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: PluginManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
285
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: PluginManager }); }
253
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: PluginManager, providedIn: 'root' }); }
286
254
  }
287
255
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: PluginManager, decorators: [{
288
- type: Injectable
256
+ type: Injectable,
257
+ args: [{ providedIn: 'root' }]
289
258
  }], ctorParameters: () => [] });
290
259
 
291
260
  const ɵɵunhandledRxjsErrorCallbacks = new WeakMap();
292
- const existingHandler = config.onUnhandledError;
293
- config.onUnhandledError = function (error) {
294
- const unhandledErrorCallback = ɵɵunhandledRxjsErrorCallbacks.get(error);
295
- if (unhandledErrorCallback) {
296
- unhandledErrorCallback();
297
- }
298
- else if (existingHandler) {
299
- existingHandler.call(this, error);
300
- }
301
- else {
302
- throw error;
261
+ let installed = false;
262
+ function installOnUnhandhedErrorHandler() {
263
+ if (installed) {
264
+ return;
303
265
  }
304
- };
266
+ const existingHandler = config.onUnhandledError;
267
+ config.onUnhandledError = function (error) {
268
+ const unhandledErrorCallback = ɵɵunhandledRxjsErrorCallbacks.get(error);
269
+ if (unhandledErrorCallback) {
270
+ unhandledErrorCallback();
271
+ }
272
+ else if (existingHandler) {
273
+ existingHandler.call(this, error);
274
+ }
275
+ else {
276
+ throw error;
277
+ }
278
+ };
279
+ installed = true;
280
+ }
305
281
  function executeUnhandledCallback(error) {
306
282
  const unhandledErrorCallback = ɵɵunhandledRxjsErrorCallbacks.get(error);
307
283
  if (unhandledErrorCallback) {
@@ -368,13 +344,14 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImpor
368
344
  args: [{ providedIn: 'root' }]
369
345
  }] });
370
346
  class InternalDispatcher {
371
- constructor(_ngZone, _actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy) {
372
- this._ngZone = _ngZone;
373
- this._actions = _actions;
374
- this._actionResults = _actionResults;
375
- this._pluginManager = _pluginManager;
376
- this._stateStream = _stateStream;
377
- this._ngxsExecutionStrategy = _ngxsExecutionStrategy;
347
+ constructor() {
348
+ this._ngZone = inject(NgZone);
349
+ this._actions = inject(InternalActions);
350
+ this._actionResults = inject(InternalDispatchedActionResults);
351
+ this._pluginManager = inject(PluginManager);
352
+ this._stateStream = inject(_StateStream);
353
+ this._ngxsExecutionStrategy = inject(InternalNgxsExecutionStrategy);
354
+ this._injector = inject(Injector);
378
355
  }
379
356
  /**
380
357
  * Dispatches event(s).
@@ -403,7 +380,7 @@ class InternalDispatcher {
403
380
  }
404
381
  const prevState = this._stateStream.getValue();
405
382
  const plugins = this._pluginManager.plugins;
406
- return compose([
383
+ return compose(this._injector, [
407
384
  ...plugins,
408
385
  (nextState, nextAction) => {
409
386
  if (nextState !== prevState) {
@@ -420,41 +397,63 @@ class InternalDispatcher {
420
397
  return this._actionResults.pipe(filter$1((ctx) => ctx.action === action && ctx.status !== "DISPATCHED" /* ActionStatus.Dispatched */), take(1), shareReplay());
421
398
  }
422
399
  createDispatchObservable(actionResult$) {
423
- return actionResult$
424
- .pipe(exhaustMap((ctx) => {
400
+ return actionResult$.pipe(mergeMap((ctx) => {
425
401
  switch (ctx.status) {
426
402
  case "SUCCESSFUL" /* ActionStatus.Successful */:
427
403
  // The `createDispatchObservable` function should return the
428
- // state, as its result is utilized by plugins.
404
+ // state, as its result is used by plugins.
429
405
  return of(this._stateStream.getValue());
430
406
  case "ERRORED" /* ActionStatus.Errored */:
431
407
  return throwError(() => ctx.error);
432
408
  default:
433
- return EMPTY;
409
+ // Once dispatched or canceled, we complete it immediately because
410
+ // `dispatch()` should emit (or error, or complete) as soon as it succeeds or fails.
411
+ return of();
434
412
  }
435
- }))
436
- .pipe(shareReplay());
413
+ }), shareReplay());
437
414
  }
438
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalDispatcher, deps: [{ token: i0.NgZone }, { token: InternalActions }, { token: InternalDispatchedActionResults }, { token: PluginManager }, { token: i1.ɵStateStream }, { token: InternalNgxsExecutionStrategy }], target: i0.ɵɵFactoryTarget.Injectable }); }
415
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalDispatcher, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
439
416
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalDispatcher, providedIn: 'root' }); }
440
417
  }
441
418
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalDispatcher, decorators: [{
442
419
  type: Injectable,
443
420
  args: [{ providedIn: 'root' }]
444
- }], ctorParameters: () => [{ type: i0.NgZone }, { type: InternalActions }, { type: InternalDispatchedActionResults }, { type: PluginManager }, { type: i1.ɵStateStream }, { type: InternalNgxsExecutionStrategy }] });
421
+ }] });
422
+ /**
423
+ * Composes a array of functions from left to right. Example:
424
+ *
425
+ * compose([fn, final])(state, action);
426
+ *
427
+ * then the funcs have a signature like:
428
+ *
429
+ * function fn (state, action, next) {
430
+ * console.log('here', state, action, next);
431
+ * return next(state, action);
432
+ * }
433
+ *
434
+ * function final (state, action) {
435
+ * console.log('here', state, action);
436
+ * return state;
437
+ * }
438
+ *
439
+ * the last function should not call `next`.
440
+ */
441
+ const compose = (injector, funcs) => (...args) => {
442
+ const curr = funcs.shift();
443
+ return runInInjectionContext(injector, () => curr(...args, (...nextArgs) => compose(injector, funcs)(...nextArgs)));
444
+ };
445
445
 
446
- const NG_DEV_MODE$8 = typeof ngDevMode !== 'undefined' && ngDevMode;
447
446
  // The injection token is used to resolve a list of states provided at
448
447
  // the root level through either `NgxsModule.forRoot` or `provideStore`.
449
- const ROOT_STATE_TOKEN = new InjectionToken(NG_DEV_MODE$8 ? 'ROOT_STATE_TOKEN' : '');
448
+ const ROOT_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'ROOT_STATE_TOKEN' : '');
450
449
  // The injection token is used to resolve a list of states provided at
451
450
  // the feature level through either `NgxsModule.forFeature` or `provideStates`.
452
451
  // The Array<Array> is used to overload the resolved value of the token because
453
452
  // it is a multi-provider token.
454
- const FEATURE_STATE_TOKEN = new InjectionToken(NG_DEV_MODE$8 ? 'FEATURE_STATE_TOKEN' : '');
453
+ const FEATURE_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'FEATURE_STATE_TOKEN' : '');
455
454
  // The injection token is used to resolve to options provided at the root
456
455
  // level through either `NgxsModule.forRoot` or `provideStore`.
457
- const NGXS_OPTIONS = new InjectionToken(NG_DEV_MODE$8 ? 'NGXS_OPTIONS' : '');
456
+ const NGXS_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_OPTIONS' : '');
458
457
  /**
459
458
  * The NGXS config settings.
460
459
  */
@@ -551,10 +550,10 @@ const deepFreeze = (o) => {
551
550
  * @ignore
552
551
  */
553
552
  class InternalStateOperations {
554
- constructor(_stateStream, _dispatcher, _config) {
555
- this._stateStream = _stateStream;
556
- this._dispatcher = _dispatcher;
557
- this._config = _config;
553
+ constructor() {
554
+ this._stateStream = inject(_StateStream);
555
+ this._dispatcher = inject(InternalDispatcher);
556
+ this._config = inject(NgxsConfig);
558
557
  }
559
558
  /**
560
559
  * Returns the root state operators.
@@ -581,13 +580,13 @@ class InternalStateOperations {
581
580
  // Set the state to the current + new
582
581
  stateOperations.setState({ ...currentState, ...results.defaults });
583
582
  }
584
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalStateOperations, deps: [{ token: i1.ɵStateStream }, { token: InternalDispatcher }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable }); }
583
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalStateOperations, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
585
584
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalStateOperations, providedIn: 'root' }); }
586
585
  }
587
586
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: InternalStateOperations, decorators: [{
588
587
  type: Injectable,
589
588
  args: [{ providedIn: 'root' }]
590
- }], ctorParameters: () => [{ type: i1.ɵStateStream }, { type: InternalDispatcher }, { type: NgxsConfig }] });
589
+ }] });
591
590
  function ensureStateAndActionsAreImmutable(root) {
592
591
  return {
593
592
  getState: () => root.getState(),
@@ -601,7 +600,6 @@ function ensureStateAndActionsAreImmutable(root) {
601
600
  };
602
601
  }
603
602
 
604
- const NG_DEV_MODE$7 = typeof ngDevMode !== 'undefined' && ngDevMode;
605
603
  function createRootSelectorFactory(selectorMetaData, selectors, memoizedSelectorFn) {
606
604
  return (context) => {
607
605
  const { argumentSelectorFunctions, selectorOptions } = getRuntimeSelectorInfo(context, selectorMetaData, selectors);
@@ -622,7 +620,7 @@ function createRootSelectorFactory(selectorMetaData, selectors, memoizedSelector
622
620
  // We're logging an error in this function because it may be used by `select`,
623
621
  // `selectSignal`, and `selectSnapshot`. Therefore, there's no need to catch
624
622
  // exceptions there to log errors.
625
- if (NG_DEV_MODE$7) {
623
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
626
624
  const message = 'The selector below has thrown an error upon invocation. ' +
627
625
  'Please check for any unsafe property access that may result in null ' +
628
626
  'or undefined values.';
@@ -696,7 +694,6 @@ function getRootSelectorFactory(selector) {
696
694
  return (metadata && metadata.makeRootSelector) || (() => selector);
697
695
  }
698
696
 
699
- const NG_DEV_MODE$6 = typeof ngDevMode !== 'undefined' && ngDevMode;
700
697
  /**
701
698
  * Get a deeply nested value. Example:
702
699
  *
@@ -761,7 +758,7 @@ function propGetter(paths, config) {
761
758
  // `createSelectorFn`, which, in turn, is solely used by the `Select` decorator.
762
759
  // We've been trying to deprecate the `Select` decorator because it's unstable with
763
760
  // server-side rendering and micro-frontend applications.
764
- const ɵPROP_GETTER = new InjectionToken(NG_DEV_MODE$6 ? 'PROP_GETTER' : '', {
761
+ const ɵPROP_GETTER = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'PROP_GETTER' : '', {
765
762
  providedIn: 'root',
766
763
  factory: () => inject(NgxsConfig).compatibility?.strictContentSecurityPolicy
767
764
  ? compliantPropGetter
@@ -788,7 +785,7 @@ const ɵPROP_GETTER = new InjectionToken(NG_DEV_MODE$6 ? 'PROP_GETTER' : '', {
788
785
  function buildGraph(stateClasses) {
789
786
  const findName = (stateClass) => {
790
787
  const meta = stateClasses.find(g => g === stateClass);
791
- if (NG_DEV_MODE$6 && !meta) {
788
+ if (typeof ngDevMode !== 'undefined' && ngDevMode && !meta) {
792
789
  throw new Error(`Child state not found: ${stateClass}. \r\nYou may have forgotten to add states to module`);
793
790
  }
794
791
  return meta[_META_KEY].name;
@@ -883,7 +880,7 @@ function topologicalSort(graph) {
883
880
  ancestors.push(name);
884
881
  visited[name] = true;
885
882
  graph[name].forEach((dep) => {
886
- if (NG_DEV_MODE$6 && ancestors.indexOf(dep) >= 0) {
883
+ if (typeof ngDevMode !== 'undefined' && ngDevMode && ancestors.indexOf(dep) >= 0) {
887
884
  throw new Error(`Circular dependency '${dep}' is required by '${name}': ${ancestors.join(' -> ')}`);
888
885
  }
889
886
  if (visited[dep]) {
@@ -978,19 +975,20 @@ function jit_hasInjectableAnnotation(stateClass) {
978
975
  return annotations.some((annotation) => annotation?.ngMetadataName === 'Injectable');
979
976
  }
980
977
 
981
- const NG_DEV_MODE$5 = typeof ngDevMode !== 'undefined' && ngDevMode;
982
- const NGXS_DEVELOPMENT_OPTIONS = new InjectionToken(NG_DEV_MODE$5 ? 'NGXS_DEVELOPMENT_OPTIONS' : '', {
978
+ const NGXS_DEVELOPMENT_OPTIONS =
979
+ /* @__PURE__ */ new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_DEVELOPMENT_OPTIONS' : '', {
983
980
  providedIn: 'root',
984
981
  factory: () => ({ warnOnUnhandledActions: true })
985
982
  });
986
983
 
987
984
  class NgxsUnhandledActionsLogger {
988
- constructor(options) {
985
+ constructor() {
989
986
  /**
990
987
  * These actions should be ignored by default; the user can increase this
991
988
  * list in the future via the `ignoreActions` method.
992
989
  */
993
990
  this._ignoredActions = new Set([InitState.type, UpdateState.type]);
991
+ const options = inject(NGXS_DEVELOPMENT_OPTIONS);
994
992
  if (typeof options.warnOnUnhandledActions === 'object') {
995
993
  this.ignoreActions(...options.warnOnUnhandledActions.ignore);
996
994
  }
@@ -1015,15 +1013,12 @@ class NgxsUnhandledActionsLogger {
1015
1013
  : action.type;
1016
1014
  console.warn(`The ${action} action has been dispatched but hasn't been handled. This may happen if the state with an action handler for this action is not registered.`);
1017
1015
  }
1018
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: NgxsUnhandledActionsLogger, deps: [{ token: NGXS_DEVELOPMENT_OPTIONS }], target: i0.ɵɵFactoryTarget.Injectable }); }
1016
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: NgxsUnhandledActionsLogger, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1019
1017
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: NgxsUnhandledActionsLogger }); }
1020
1018
  }
1021
1019
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: NgxsUnhandledActionsLogger, decorators: [{
1022
1020
  type: Injectable
1023
- }], ctorParameters: () => [{ type: undefined, decorators: [{
1024
- type: Inject,
1025
- args: [NGXS_DEVELOPMENT_OPTIONS]
1026
- }] }] });
1021
+ }], ctorParameters: () => [] });
1027
1022
 
1028
1023
  class NgxsUnhandledErrorHandler {
1029
1024
  constructor() {
@@ -1076,8 +1071,8 @@ function simplePatch(value) {
1076
1071
  * @ignore
1077
1072
  */
1078
1073
  class StateContextFactory {
1079
- constructor(_internalStateOperations) {
1080
- this._internalStateOperations = _internalStateOperations;
1074
+ constructor() {
1075
+ this._internalStateOperations = inject(InternalStateOperations);
1081
1076
  }
1082
1077
  /**
1083
1078
  * Create the state context
@@ -1108,13 +1103,13 @@ class StateContextFactory {
1108
1103
  }
1109
1104
  };
1110
1105
  }
1111
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: StateContextFactory, deps: [{ token: InternalStateOperations }], target: i0.ɵɵFactoryTarget.Injectable }); }
1106
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: StateContextFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1112
1107
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: StateContextFactory, providedIn: 'root' }); }
1113
1108
  }
1114
1109
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: StateContextFactory, decorators: [{
1115
1110
  type: Injectable,
1116
1111
  args: [{ providedIn: 'root' }]
1117
- }], ctorParameters: () => [{ type: InternalStateOperations }] });
1112
+ }] });
1118
1113
  function setStateValue(root, currentAppState, newValue, path) {
1119
1114
  const newAppState = setValue(currentAppState, path, newValue);
1120
1115
  root.setState(newAppState);
@@ -1237,7 +1232,6 @@ function createAllowedStatusesMap(statuses) {
1237
1232
  }, {});
1238
1233
  }
1239
1234
 
1240
- const NG_DEV_MODE$4 = typeof ngDevMode !== 'undefined' && ngDevMode;
1241
1235
  function cloneDefaults(defaults) {
1242
1236
  let value = defaults === undefined ? {} : defaults;
1243
1237
  if (defaults) {
@@ -1254,20 +1248,17 @@ function cloneDefaults(defaults) {
1254
1248
  * The `StateFactory` class adds root and feature states to the graph.
1255
1249
  * This extracts state names from state classes, checks if they already
1256
1250
  * exist in the global graph, throws errors if their names are invalid, etc.
1257
- * See its constructor, state factories inject state factories that are
1258
- * parent-level providers. This is required to get feature states from the
1259
- * injector on the same level.
1260
1251
  *
1261
- * The `NgxsModule.forFeature(...)` returns `providers: [StateFactory, ...states]`.
1262
- * The `StateFactory` is initialized on the feature level and goes through `...states`
1263
- * to get them from the injector through `injector.get(state)`.
1252
+ * Root and feature initializers call `addAndReturnDefaults()` to add those states
1253
+ * to the global graph. Since `addAndReturnDefaults` runs within the injection
1254
+ * context (which might be the root injector or a feature injector), we can
1255
+ * retrieve an instance of the state class using `inject(StateClass)`.
1264
1256
  * @ignore
1265
1257
  */
1266
1258
  class StateFactory {
1267
1259
  constructor() {
1268
1260
  this._injector = inject(Injector);
1269
1261
  this._config = inject(NgxsConfig);
1270
- this._parentFactory = inject(StateFactory, { optional: true, skipSelf: true });
1271
1262
  this._stateContextFactory = inject(StateContextFactory);
1272
1263
  this._actions = inject(InternalActions);
1273
1264
  this._actionResults = inject(InternalDispatchedActionResults);
@@ -1284,47 +1275,36 @@ class StateFactory {
1284
1275
  const stateFactory = this;
1285
1276
  const propGetter = stateFactory._propGetter;
1286
1277
  function resolveGetter(key) {
1287
- const path = stateFactory.statePaths[key];
1278
+ const path = stateFactory._statePaths[key];
1288
1279
  return path ? propGetter(path.split('.')) : null;
1289
1280
  }
1290
- const context = this._parentFactory
1291
- ? this._parentFactory.getRuntimeSelectorContext()
1292
- : {
1293
- getStateGetter(key) {
1294
- // Use `@__INLINE__` annotation to forcely inline `resolveGetter`.
1295
- // This is a Terser annotation, which will function only in the production mode.
1296
- let getter = /*@__INLINE__*/ resolveGetter(key);
1297
- if (getter) {
1298
- return getter;
1299
- }
1300
- return (...args) => {
1301
- // Late loaded getter
1302
- if (!getter) {
1303
- getter = /*@__INLINE__*/ resolveGetter(key);
1304
- }
1305
- return getter ? getter(...args) : undefined;
1306
- };
1307
- },
1308
- getSelectorOptions(localOptions) {
1309
- const globalSelectorOptions = stateFactory._config.selectorOptions;
1310
- return {
1311
- ...globalSelectorOptions,
1312
- ...(localOptions || {})
1313
- };
1281
+ const context = {
1282
+ getStateGetter(key) {
1283
+ // Use `@__INLINE__` annotation to forcely inline `resolveGetter`.
1284
+ // This is a Terser annotation, which will function only in the production mode.
1285
+ let getter = /*@__INLINE__*/ resolveGetter(key);
1286
+ if (getter) {
1287
+ return getter;
1314
1288
  }
1315
- };
1289
+ return (...args) => {
1290
+ // Late loaded getter
1291
+ if (!getter) {
1292
+ getter = /*@__INLINE__*/ resolveGetter(key);
1293
+ }
1294
+ return getter ? getter(...args) : undefined;
1295
+ };
1296
+ },
1297
+ getSelectorOptions(localOptions) {
1298
+ const globalSelectorOptions = stateFactory._config.selectorOptions;
1299
+ return {
1300
+ ...globalSelectorOptions,
1301
+ ...(localOptions || {})
1302
+ };
1303
+ }
1304
+ };
1316
1305
  return context;
1317
1306
  });
1318
1307
  }
1319
- get states() {
1320
- return this._parentFactory ? this._parentFactory.states : this._states;
1321
- }
1322
- get statesByName() {
1323
- return this._parentFactory ? this._parentFactory.statesByName : this._statesByName;
1324
- }
1325
- get statePaths() {
1326
- return this._parentFactory ? this._parentFactory.statePaths : this._statePaths;
1327
- }
1328
1308
  ngOnDestroy() {
1329
1309
  this._actionsSubscription?.unsubscribe();
1330
1310
  }
@@ -1332,7 +1312,7 @@ class StateFactory {
1332
1312
  * Add a new state to the global defs.
1333
1313
  */
1334
1314
  add(stateClasses) {
1335
- if (NG_DEV_MODE$4) {
1315
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
1336
1316
  ensureStatesAreDecorated(stateClasses);
1337
1317
  }
1338
1318
  const { newStates } = this.addToStatesMap(stateClasses);
@@ -1352,7 +1332,7 @@ class StateFactory {
1352
1332
  // `State` decorator. This check is moved here because the `ɵprov` property
1353
1333
  // will not exist on the class in JIT mode (because it's set asynchronously
1354
1334
  // during JIT compilation through `Object.defineProperty`).
1355
- if (NG_DEV_MODE$4) {
1335
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
1356
1336
  ensureStateClassIsInjectable(stateClass);
1357
1337
  }
1358
1338
  const stateMap = {
@@ -1360,7 +1340,7 @@ class StateFactory {
1360
1340
  path,
1361
1341
  isInitialised: false,
1362
1342
  actions: meta.actions,
1363
- instance: this._injector.get(stateClass),
1343
+ instance: inject(stateClass),
1364
1344
  defaults: cloneDefaults(meta.defaults)
1365
1345
  };
1366
1346
  // ensure our store hasn't already been added
@@ -1369,7 +1349,7 @@ class StateFactory {
1369
1349
  if (!this.hasBeenMountedAndBootstrapped(name, path)) {
1370
1350
  bootstrappedStores.push(stateMap);
1371
1351
  }
1372
- this.states.push(stateMap);
1352
+ this._states.push(stateMap);
1373
1353
  this.hydrateActionMetasMap(stateMap);
1374
1354
  }
1375
1355
  return bootstrappedStores;
@@ -1384,14 +1364,8 @@ class StateFactory {
1384
1364
  return { defaults, states: mappedStores };
1385
1365
  }
1386
1366
  connectActionHandlers() {
1387
- // Note: We have to connect actions only once when the `StateFactory`
1388
- // is being created for the first time. This checks if we're in
1389
- // a child state factory and the parent state factory already exists.
1390
- if (this._parentFactory || this._actionsSubscription !== null) {
1391
- return;
1392
- }
1393
1367
  this._actionsSubscription = this._actions
1394
- .pipe(filter((ctx) => ctx.status === "DISPATCHED" /* ActionStatus.Dispatched */), mergeMap(ctx => {
1368
+ .pipe(filter((ctx) => ctx.status === "DISPATCHED" /* ActionStatus.Dispatched */), mergeMap$1(ctx => {
1395
1369
  const action = ctx.action;
1396
1370
  return this.invokeActions(action).pipe(map$1(() => ({ action, status: "SUCCESSFUL" /* ActionStatus.Successful */ })), defaultIfEmpty({ action, status: "CANCELED" /* ActionStatus.Canceled */ }), catchError(error => {
1397
1371
  const ngxsUnhandledErrorHandler = (this._ngxsUnhandledErrorHandler ||=
@@ -1431,7 +1405,7 @@ class StateFactory {
1431
1405
  }
1432
1406
  // The `NgxsUnhandledActionsLogger` is a tree-shakable class which functions
1433
1407
  // only during development.
1434
- if (NG_DEV_MODE$4 && !actionHasBeenHandled) {
1408
+ if (typeof ngDevMode !== 'undefined' && ngDevMode && !actionHasBeenHandled) {
1435
1409
  const unhandledActionsLogger = this._injector.get(NgxsUnhandledActionsLogger, null);
1436
1410
  // The `NgxsUnhandledActionsLogger` will not be resolved by the injector if the
1437
1411
  // `NgxsDevelopmentModule` is not provided. It's enough to check whether the `injector.get`
@@ -1445,10 +1419,10 @@ class StateFactory {
1445
1419
  }
1446
1420
  addToStatesMap(stateClasses) {
1447
1421
  const newStates = [];
1448
- const statesMap = this.statesByName;
1422
+ const statesMap = this._statesByName;
1449
1423
  for (const stateClass of stateClasses) {
1450
1424
  const stateName = _getStoreMetadata(stateClass).name;
1451
- if (NG_DEV_MODE$4) {
1425
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
1452
1426
  ensureStateNameIsUnique(stateName, stateClass, statesMap);
1453
1427
  }
1454
1428
  const unmountedState = !statesMap[stateName];
@@ -1460,7 +1434,7 @@ class StateFactory {
1460
1434
  return { newStates };
1461
1435
  }
1462
1436
  addRuntimeInfoToMeta(meta, path) {
1463
- this.statePaths[meta.name] = path;
1437
+ this._statePaths[meta.name] = path;
1464
1438
  // TODO: versions after v3 - we plan to get rid of the `path` property because it is non-deterministic
1465
1439
  // we can do this when we get rid of the incorrectly exposed getStoreMetadata
1466
1440
  // We will need to come up with an alternative to what was exposed in v3 because this is used by many plugins
@@ -1470,7 +1444,7 @@ class StateFactory {
1470
1444
  const valueIsBootstrappedInInitialState = getValue(this._initialState, path) !== undefined;
1471
1445
  // This checks whether a state has been already added to the global graph and
1472
1446
  // its lifecycle is in 'bootstrapped' state.
1473
- return this.statesByName[name] && valueIsBootstrappedInInitialState;
1447
+ return this._statesByName[name] && valueIsBootstrappedInInitialState;
1474
1448
  }
1475
1449
  hydrateActionMetasMap({ path, actions, instance }) {
1476
1450
  const { dispatched$ } = this._actions;
@@ -1490,7 +1464,7 @@ class StateFactory {
1490
1464
  result = from(result);
1491
1465
  }
1492
1466
  if (isObservable(result)) {
1493
- result = result.pipe(mergeMap((value) => {
1467
+ result = result.pipe(mergeMap$1((value) => {
1494
1468
  if (_isPromise(value)) {
1495
1469
  return from(value);
1496
1470
  }
@@ -1541,37 +1515,37 @@ class StateFactory {
1541
1515
  }
1542
1516
  }
1543
1517
  /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: StateFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1544
- /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: StateFactory }); }
1518
+ /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: StateFactory, providedIn: 'root' }); }
1545
1519
  }
1546
1520
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: StateFactory, decorators: [{
1547
- type: Injectable
1521
+ type: Injectable,
1522
+ args: [{ providedIn: 'root' }]
1548
1523
  }] });
1549
1524
  // This is used to replace `setState` and `patchState` once the action
1550
1525
  // handler has been unsubscribed or completed, to prevent writing
1551
1526
  // to the state context.
1552
1527
  function noop() { }
1553
1528
 
1554
- const NG_DEV_MODE$3 = typeof ngDevMode !== 'undefined' && ngDevMode;
1555
1529
  class Store {
1556
- constructor(_stateStream, _internalStateOperations, _config, _internalExecutionStrategy, _stateFactory, initialStateValue) {
1557
- this._stateStream = _stateStream;
1558
- this._internalStateOperations = _internalStateOperations;
1559
- this._config = _config;
1560
- this._internalExecutionStrategy = _internalExecutionStrategy;
1561
- this._stateFactory = _stateFactory;
1530
+ constructor() {
1531
+ this._stateStream = inject(_StateStream);
1532
+ this._internalStateOperations = inject(InternalStateOperations);
1533
+ this._config = inject(NgxsConfig);
1534
+ this._internalExecutionStrategy = inject(InternalNgxsExecutionStrategy);
1535
+ this._stateFactory = inject(StateFactory);
1562
1536
  /**
1563
1537
  * This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
1564
1538
  * because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
1565
1539
  * All selects would use this stream, and it would call leave only once for any state change across all active selectors.
1566
1540
  */
1567
1541
  this._selectableStateStream = this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy), shareReplay$1({ bufferSize: 1, refCount: true }));
1568
- this.initStateStream(initialStateValue);
1542
+ this.initStateStream();
1569
1543
  }
1570
1544
  /**
1571
1545
  * Dispatches action(s).
1572
1546
  */
1573
1547
  dispatch(actionOrActions) {
1574
- if (NG_DEV_MODE$3) {
1548
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
1575
1549
  if (
1576
1550
  // If a single action is dispatched and it's nullable.
1577
1551
  actionOrActions == null ||
@@ -1643,31 +1617,26 @@ class Store {
1643
1617
  const runtimeContext = this._stateFactory.getRuntimeSelectorContext();
1644
1618
  return makeSelectorFn(runtimeContext);
1645
1619
  }
1646
- initStateStream(initialStateValue) {
1620
+ initStateStream() {
1621
+ const initialStateValue = inject(_INITIAL_STATE_TOKEN);
1647
1622
  const value = this._stateStream.value;
1648
1623
  const storeIsEmpty = !value || Object.keys(value).length === 0;
1649
1624
  if (storeIsEmpty) {
1650
1625
  this._stateStream.next(initialStateValue);
1651
1626
  }
1652
1627
  }
1653
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: Store, deps: [{ token: i1.ɵStateStream }, { token: InternalStateOperations }, { token: NgxsConfig }, { token: InternalNgxsExecutionStrategy }, { token: StateFactory }, { token: _INITIAL_STATE_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
1628
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: Store, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1654
1629
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: Store, providedIn: 'root' }); }
1655
1630
  }
1656
1631
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: Store, decorators: [{
1657
1632
  type: Injectable,
1658
1633
  args: [{ providedIn: 'root' }]
1659
- }], ctorParameters: () => [{ type: i1.ɵStateStream }, { type: InternalStateOperations }, { type: NgxsConfig }, { type: InternalNgxsExecutionStrategy }, { type: StateFactory }, { type: undefined, decorators: [{
1660
- type: Optional
1661
- }, {
1662
- type: Inject,
1663
- args: [_INITIAL_STATE_TOKEN]
1664
- }] }] });
1634
+ }], ctorParameters: () => [] });
1665
1635
 
1666
- const NG_DEV_MODE$2 = typeof ngDevMode !== 'undefined' && ngDevMode;
1667
1636
  /**
1668
1637
  * InjectionToken that registers preboot functions (called before the root initializer).
1669
1638
  */
1670
- const NGXS_PREBOOT_FNS = new InjectionToken(NG_DEV_MODE$2 ? 'NGXS_PREBOOT_FNS' : '');
1639
+ const NGXS_PREBOOT_FNS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_PREBOOT_FNS' : '');
1671
1640
  /**
1672
1641
  * This function registers a preboot function which will be called before the root
1673
1642
  * store initializer is run, but after all of the NGXS features are provided and
@@ -1717,20 +1686,19 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImpor
1717
1686
  args: [{ providedIn: 'root' }]
1718
1687
  }], ctorParameters: () => [{ type: Store }, { type: NgxsConfig }] });
1719
1688
 
1720
- const NG_DEV_MODE$1 = typeof ngDevMode !== 'undefined' && ngDevMode;
1721
1689
  class LifecycleStateManager {
1722
- constructor(_store, _internalStateOperations, _stateContextFactory, _appBootstrappedState) {
1723
- this._store = _store;
1724
- this._internalStateOperations = _internalStateOperations;
1725
- this._stateContextFactory = _stateContextFactory;
1726
- this._appBootstrappedState = _appBootstrappedState;
1690
+ constructor() {
1691
+ this._store = inject(Store);
1692
+ this._internalStateOperations = inject(InternalStateOperations);
1693
+ this._stateContextFactory = inject(StateContextFactory);
1694
+ this._appBootstrappedState = inject(_NgxsAppBootstrappedState);
1727
1695
  this._destroy$ = new ReplaySubject(1);
1728
1696
  }
1729
1697
  ngOnDestroy() {
1730
1698
  this._destroy$.next();
1731
1699
  }
1732
1700
  ngxsBootstrap(action, results) {
1733
- if (NG_DEV_MODE$1) {
1701
+ if (typeof ngDevMode !== 'undefined' && ngDevMode) {
1734
1702
  if (action instanceof InitState) {
1735
1703
  this._initStateHasBeenDispatched = true;
1736
1704
  }
@@ -1748,7 +1716,7 @@ class LifecycleStateManager {
1748
1716
  this._internalStateOperations
1749
1717
  .getRootStateOperations()
1750
1718
  .dispatch(action)
1751
- .pipe(filter$1(() => !!results), tap(() => this._invokeInitOnStates(results.states)), mergeMap$1(() => this._appBootstrappedState), filter$1(appBootstrapped => !!appBootstrapped), takeUntil$1(this._destroy$))
1719
+ .pipe(filter$1(() => !!results), tap(() => this._invokeInitOnStates(results.states)), mergeMap(() => this._appBootstrappedState), filter$1(appBootstrapped => !!appBootstrapped), takeUntil$1(this._destroy$))
1752
1720
  .subscribe(() => this._invokeBootstrapOnStates(results.states));
1753
1721
  }
1754
1722
  _invokeInitOnStates(mappedStores) {
@@ -1780,21 +1748,25 @@ class LifecycleStateManager {
1780
1748
  _getStateContext(mappedStore) {
1781
1749
  return this._stateContextFactory.createStateContext(mappedStore.path);
1782
1750
  }
1783
- /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: LifecycleStateManager, deps: [{ token: Store }, { token: InternalStateOperations }, { token: StateContextFactory }, { token: i1.ɵNgxsAppBootstrappedState }], target: i0.ɵɵFactoryTarget.Injectable }); }
1751
+ /** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: LifecycleStateManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
1784
1752
  /** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: LifecycleStateManager, providedIn: 'root' }); }
1785
1753
  }
1786
1754
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImport: i0, type: LifecycleStateManager, decorators: [{
1787
1755
  type: Injectable,
1788
1756
  args: [{ providedIn: 'root' }]
1789
- }], ctorParameters: () => [{ type: Store }, { type: InternalStateOperations }, { type: StateContextFactory }, { type: i1.ɵNgxsAppBootstrappedState }] });
1757
+ }] });
1790
1758
 
1791
- const NG_DEV_MODE = typeof ngDevMode !== 'undefined' && ngDevMode;
1792
1759
  /**
1793
1760
  * This function is shared by both NgModule and standalone features.
1794
1761
  * When using `NgxsModule.forRoot` and `provideStore`, we can depend on the
1795
1762
  * same initialization functionality.
1796
1763
  */
1797
1764
  function rootStoreInitializer() {
1765
+ // Override the RxJS `config.onUnhandledError` within the root store initializer,
1766
+ // but only after other code has already executed.
1767
+ // If users have a custom `config.onUnhandledError`, we might overwrite it too
1768
+ // early and capture the original `config.onUnhandledError` before it is properly set.
1769
+ installOnUnhandhedErrorHandler();
1798
1770
  const prebootFns = inject(NGXS_PREBOOT_FNS, { optional: true }) || [];
1799
1771
  prebootFns.forEach(prebootFn => prebootFn());
1800
1772
  const factory = inject(StateFactory);
@@ -1836,11 +1808,11 @@ function featureStatesInitializer() {
1836
1808
  /**
1837
1809
  * InjectionToken that registers the global Store.
1838
1810
  */
1839
- const NGXS_ROOT_STORE_INITIALIZER = new InjectionToken(NG_DEV_MODE ? 'NGXS_ROOT_STORE_INITIALIZER' : '');
1811
+ const NGXS_ROOT_STORE_INITIALIZER = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_ROOT_STORE_INITIALIZER' : '');
1840
1812
  /**
1841
1813
  * InjectionToken that registers feature states.
1842
1814
  */
1843
- const NGXS_FEATURE_STORE_INITIALIZER = new InjectionToken(NG_DEV_MODE ? 'NGXS_FEATURE_STORE_INITIALIZER' : '');
1815
+ const NGXS_FEATURE_STORE_INITIALIZER = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_FEATURE_STORE_INITIALIZER' : '');
1844
1816
  const NGXS_ROOT_ENVIRONMENT_INITIALIZER = [
1845
1817
  { provide: NGXS_ROOT_STORE_INITIALIZER, useFactory: rootStoreInitializer },
1846
1818
  {
@@ -1904,8 +1876,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.6", ngImpor
1904
1876
  */
1905
1877
  function getRootProviders(states, options) {
1906
1878
  return [
1907
- StateFactory,
1908
- PluginManager,
1909
1879
  ...states,
1910
1880
  {
1911
1881
  provide: ROOT_STATE_TOKEN,
@@ -1936,7 +1906,6 @@ function getRootProviders(states, options) {
1936
1906
  */
1937
1907
  function getFeatureProviders(states) {
1938
1908
  return [
1939
- StateFactory,
1940
1909
  PluginManager,
1941
1910
  ...states,
1942
1911
  {
@@ -2359,11 +2328,17 @@ function provideStates(states, ...features) {
2359
2328
  */
2360
2329
  function withNgxsPlugin(plugin) {
2361
2330
  return makeEnvironmentProviders([
2362
- { provide: NGXS_PLUGINS, useClass: plugin, multi: true },
2331
+ _isPluginClass(plugin)
2332
+ ? { provide: NGXS_PLUGINS, useClass: plugin, multi: true }
2333
+ : { provide: NGXS_PLUGINS, useValue: plugin, multi: true },
2363
2334
  // We should inject the `PluginManager` to retrieve `NGXS_PLUGINS` and
2364
2335
  // register those plugins. The plugin can be added from inside the child
2365
2336
  // route, so the plugin manager should be re-injected.
2366
- { provide: ENVIRONMENT_INITIALIZER, useValue: () => inject(PluginManager), multi: true }
2337
+ {
2338
+ provide: ENVIRONMENT_INITIALIZER,
2339
+ useValue: () => inject(PluginManager),
2340
+ multi: true
2341
+ }
2367
2342
  ]);
2368
2343
  }
2369
2344