@ngxs/store 19.0.0-dev.master-ae76ef6 → 19.0.0-dev.master-d3dad28
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.
- package/fesm2022/ngxs-store-internals-testing.mjs +21 -22
- package/fesm2022/ngxs-store-internals-testing.mjs.map +1 -1
- package/fesm2022/ngxs-store-internals.mjs +24 -25
- package/fesm2022/ngxs-store-internals.mjs.map +1 -1
- package/fesm2022/ngxs-store-operators.mjs.map +1 -1
- package/fesm2022/ngxs-store-plugins.mjs +3 -2
- package/fesm2022/ngxs-store-plugins.mjs.map +1 -1
- package/fesm2022/ngxs-store.mjs +344 -322
- package/fesm2022/ngxs-store.mjs.map +1 -1
- package/index.d.ts +10 -2
- package/internals/index.d.ts +1 -1
- package/internals/testing/index.d.ts +1 -1
- package/package.json +6 -6
package/fesm2022/ngxs-store.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
2
|
import { inject, Injectable, DestroyRef, NgZone, Injector, runInInjectionContext, InjectionToken, ErrorHandler, ɵisPromise as _isPromise, computed, makeEnvironmentProviders, provideEnvironmentInitializer, NgModule, APP_BOOTSTRAP_LISTENER, ApplicationRef, PendingTasks, assertInInjectionContext, EnvironmentInjector, createEnvironmentInjector } from '@angular/core';
|
|
3
|
-
import { config, Observable, Subject, of, forkJoin, map, shareReplay, filter, take, mergeMap, EMPTY,
|
|
3
|
+
import { config, Observable, Subject, of, forkJoin, map, shareReplay, filter, take, mergeMap, EMPTY, from, isObservable, defaultIfEmpty, takeUntil, finalize, catchError, distinctUntilChanged, startWith, skip, buffer, debounceTime } from 'rxjs';
|
|
4
4
|
import { ɵwrapObserverCalls as _wrapObserverCalls, ɵOrderedSubject as _OrderedSubject, ɵStateStream as _StateStream, ɵhasOwnProperty as _hasOwnProperty, ɵmemoize as _memoize, ɵgetStoreMetadata as _getStoreMetadata, ɵgetSelectorMetadata as _getSelectorMetadata, ɵMETA_KEY as _META_KEY, ɵINITIAL_STATE_TOKEN as _INITIAL_STATE_TOKEN, ɵNgxsActionRegistry as _NgxsActionRegistry, ɵ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';
|
|
6
6
|
import { NGXS_PLUGINS, getActionTypeFromInstance, InitState, UpdateState, setValue, getValue, ɵisPluginClass as _isPluginClass } from '@ngxs/store/plugins';
|
|
@@ -8,15 +8,15 @@ export { InitState, NGXS_PLUGINS, UpdateState, actionMatcher, getActionTypeFromI
|
|
|
8
8
|
import { isStateOperator } from '@ngxs/store/operators';
|
|
9
9
|
|
|
10
10
|
class PluginManager {
|
|
11
|
+
plugins = [];
|
|
12
|
+
_parentManager = inject(PluginManager, {
|
|
13
|
+
optional: true,
|
|
14
|
+
skipSelf: true
|
|
15
|
+
});
|
|
16
|
+
_pluginHandlers = inject(NGXS_PLUGINS, {
|
|
17
|
+
optional: true
|
|
18
|
+
});
|
|
11
19
|
constructor() {
|
|
12
|
-
this.plugins = [];
|
|
13
|
-
this._parentManager = inject(PluginManager, {
|
|
14
|
-
optional: true,
|
|
15
|
-
skipSelf: true
|
|
16
|
-
});
|
|
17
|
-
this._pluginHandlers = inject(NGXS_PLUGINS, {
|
|
18
|
-
optional: true
|
|
19
|
-
});
|
|
20
20
|
this.registerHandlers();
|
|
21
21
|
}
|
|
22
22
|
get _rootPlugins() {
|
|
@@ -30,10 +30,10 @@ class PluginManager {
|
|
|
30
30
|
const handlers = this._pluginHandlers || [];
|
|
31
31
|
return handlers.map((plugin) => (plugin.handle ? plugin.handle.bind(plugin) : plugin));
|
|
32
32
|
}
|
|
33
|
-
/** @nocollapse */ static
|
|
34
|
-
/** @nocollapse */ static
|
|
33
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: PluginManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
34
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: PluginManager, providedIn: 'root' });
|
|
35
35
|
}
|
|
36
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
36
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: PluginManager, decorators: [{
|
|
37
37
|
type: Injectable,
|
|
38
38
|
args: [{ providedIn: 'root' }]
|
|
39
39
|
}], ctorParameters: () => [] });
|
|
@@ -132,18 +132,16 @@ class InternalDispatchedActionResults extends Subject {
|
|
|
132
132
|
// any actions after the application is destroyed.
|
|
133
133
|
inject(DestroyRef).onDestroy(() => this.complete());
|
|
134
134
|
}
|
|
135
|
-
/** @nocollapse */ static
|
|
136
|
-
/** @nocollapse */ static
|
|
135
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalDispatchedActionResults, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
136
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalDispatchedActionResults, providedIn: 'root' });
|
|
137
137
|
}
|
|
138
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
138
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalDispatchedActionResults, decorators: [{
|
|
139
139
|
type: Injectable,
|
|
140
140
|
args: [{ providedIn: 'root' }]
|
|
141
141
|
}], ctorParameters: () => [] });
|
|
142
142
|
|
|
143
143
|
class InternalNgxsExecutionStrategy {
|
|
144
|
-
|
|
145
|
-
this._ngZone = inject(NgZone);
|
|
146
|
-
}
|
|
144
|
+
_ngZone = inject(NgZone);
|
|
147
145
|
enter(func) {
|
|
148
146
|
if (typeof ngServerMode !== 'undefined' && ngServerMode) {
|
|
149
147
|
return this._runInsideAngular(func);
|
|
@@ -165,10 +163,10 @@ class InternalNgxsExecutionStrategy {
|
|
|
165
163
|
}
|
|
166
164
|
return func();
|
|
167
165
|
}
|
|
168
|
-
/** @nocollapse */ static
|
|
169
|
-
/** @nocollapse */ static
|
|
166
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
167
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' });
|
|
170
168
|
}
|
|
171
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
169
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
|
|
172
170
|
type: Injectable,
|
|
173
171
|
args: [{ providedIn: 'root' }]
|
|
174
172
|
}] });
|
|
@@ -187,11 +185,11 @@ var ActionStatus;
|
|
|
187
185
|
* Internal Action stream that is emitted anytime an action is dispatched.
|
|
188
186
|
*/
|
|
189
187
|
class InternalActions extends _OrderedSubject {
|
|
188
|
+
// This subject will be the first to know about the dispatched action, its purpose is for
|
|
189
|
+
// any logic that must be executed before action handlers are invoked (i.e., cancelation).
|
|
190
|
+
dispatched$ = new Subject();
|
|
190
191
|
constructor() {
|
|
191
192
|
super();
|
|
192
|
-
// This subject will be the first to know about the dispatched action, its purpose is for
|
|
193
|
-
// any logic that must be executed before action handlers are invoked (i.e., cancelation).
|
|
194
|
-
this.dispatched$ = new Subject();
|
|
195
193
|
this.subscribe(ctx => {
|
|
196
194
|
if (ctx.status === ActionStatus.Dispatched) {
|
|
197
195
|
this.dispatched$.next(ctx);
|
|
@@ -206,10 +204,10 @@ class InternalActions extends _OrderedSubject {
|
|
|
206
204
|
this.dispatched$.complete();
|
|
207
205
|
});
|
|
208
206
|
}
|
|
209
|
-
/** @nocollapse */ static
|
|
210
|
-
/** @nocollapse */ static
|
|
207
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalActions, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
208
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalActions, providedIn: 'root' });
|
|
211
209
|
}
|
|
212
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
210
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalActions, decorators: [{
|
|
213
211
|
type: Injectable,
|
|
214
212
|
args: [{ providedIn: 'root' }]
|
|
215
213
|
}], ctorParameters: () => [] });
|
|
@@ -239,24 +237,22 @@ class Actions extends Observable {
|
|
|
239
237
|
observer.add(childSubscription);
|
|
240
238
|
});
|
|
241
239
|
}
|
|
242
|
-
/** @nocollapse */ static
|
|
243
|
-
/** @nocollapse */ static
|
|
240
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: Actions, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
241
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: Actions, providedIn: 'root' });
|
|
244
242
|
}
|
|
245
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
243
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: Actions, decorators: [{
|
|
246
244
|
type: Injectable,
|
|
247
245
|
args: [{ providedIn: 'root' }]
|
|
248
246
|
}], ctorParameters: () => [] });
|
|
249
247
|
|
|
250
248
|
class InternalDispatcher {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
this._injector = inject(Injector);
|
|
259
|
-
}
|
|
249
|
+
_ngZone = inject(NgZone);
|
|
250
|
+
_actions = inject(InternalActions);
|
|
251
|
+
_actionResults = inject(InternalDispatchedActionResults);
|
|
252
|
+
_pluginManager = inject(PluginManager);
|
|
253
|
+
_stateStream = inject(_StateStream);
|
|
254
|
+
_ngxsExecutionStrategy = inject(InternalNgxsExecutionStrategy);
|
|
255
|
+
_injector = inject(Injector);
|
|
260
256
|
/**
|
|
261
257
|
* Dispatches event(s).
|
|
262
258
|
*/
|
|
@@ -316,10 +312,10 @@ class InternalDispatcher {
|
|
|
316
312
|
}
|
|
317
313
|
}), shareReplay());
|
|
318
314
|
}
|
|
319
|
-
/** @nocollapse */ static
|
|
320
|
-
/** @nocollapse */ static
|
|
315
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalDispatcher, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
316
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalDispatcher, providedIn: 'root' });
|
|
321
317
|
}
|
|
322
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
318
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalDispatcher, decorators: [{
|
|
323
319
|
type: Injectable,
|
|
324
320
|
args: [{ providedIn: 'root' }]
|
|
325
321
|
}] });
|
|
@@ -362,20 +358,28 @@ const NGXS_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDe
|
|
|
362
358
|
* The NGXS config settings.
|
|
363
359
|
*/
|
|
364
360
|
class NgxsConfig {
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
/**
|
|
361
|
+
/**
|
|
362
|
+
* Run in development mode. This will add additional debugging features:
|
|
363
|
+
* - Object.freeze on the state and actions to guarantee immutability
|
|
364
|
+
* (default: false)
|
|
365
|
+
*
|
|
366
|
+
* Note: this property will be accounted only in development mode.
|
|
367
|
+
* It makes sense to use it only during development to ensure there're no state mutations.
|
|
368
|
+
* When building for production, the `Object.freeze` will be tree-shaken away.
|
|
369
|
+
*/
|
|
370
|
+
developmentMode;
|
|
371
|
+
compatibility = {
|
|
372
|
+
strictContentSecurityPolicy: false
|
|
373
|
+
};
|
|
374
|
+
/**
|
|
375
|
+
* Defining shared selector options
|
|
376
|
+
*/
|
|
377
|
+
selectorOptions = {
|
|
378
|
+
injectContainerState: false,
|
|
379
|
+
suppressErrors: false
|
|
380
|
+
};
|
|
381
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
382
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: () => {
|
|
379
383
|
const defaultConfig = new NgxsConfig();
|
|
380
384
|
const config = inject(NGXS_OPTIONS);
|
|
381
385
|
return {
|
|
@@ -386,9 +390,9 @@ class NgxsConfig {
|
|
|
386
390
|
...config.selectorOptions
|
|
387
391
|
}
|
|
388
392
|
};
|
|
389
|
-
} });
|
|
393
|
+
} });
|
|
390
394
|
}
|
|
391
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
395
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsConfig, decorators: [{
|
|
392
396
|
type: Injectable,
|
|
393
397
|
args: [{
|
|
394
398
|
providedIn: 'root',
|
|
@@ -411,6 +415,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
|
|
|
411
415
|
* Passed as a value in a NgxsSimpleChanges object to the ngxsOnChanges hook.
|
|
412
416
|
*/
|
|
413
417
|
class NgxsSimpleChange {
|
|
418
|
+
previousValue;
|
|
419
|
+
currentValue;
|
|
420
|
+
firstChange;
|
|
414
421
|
constructor(previousValue, currentValue, firstChange) {
|
|
415
422
|
this.previousValue = previousValue;
|
|
416
423
|
this.currentValue = currentValue;
|
|
@@ -441,11 +448,9 @@ const deepFreeze = (o) => {
|
|
|
441
448
|
* @ignore
|
|
442
449
|
*/
|
|
443
450
|
class InternalStateOperations {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
this._config = inject(NgxsConfig);
|
|
448
|
-
}
|
|
451
|
+
_stateStream = inject(_StateStream);
|
|
452
|
+
_dispatcher = inject(InternalDispatcher);
|
|
453
|
+
_config = inject(NgxsConfig);
|
|
449
454
|
/**
|
|
450
455
|
* Returns the root state operators.
|
|
451
456
|
*/
|
|
@@ -471,10 +476,10 @@ class InternalStateOperations {
|
|
|
471
476
|
// Set the state to the current + new
|
|
472
477
|
stateOperations.setState({ ...currentState, ...results.defaults });
|
|
473
478
|
}
|
|
474
|
-
/** @nocollapse */ static
|
|
475
|
-
/** @nocollapse */ static
|
|
479
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalStateOperations, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
480
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalStateOperations, providedIn: 'root' });
|
|
476
481
|
}
|
|
477
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
482
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalStateOperations, decorators: [{
|
|
478
483
|
type: Injectable,
|
|
479
484
|
args: [{ providedIn: 'root' }]
|
|
480
485
|
}] });
|
|
@@ -856,12 +861,12 @@ const NGXS_DEVELOPMENT_OPTIONS =
|
|
|
856
861
|
});
|
|
857
862
|
|
|
858
863
|
class NgxsUnhandledActionsLogger {
|
|
864
|
+
/**
|
|
865
|
+
* These actions should be ignored by default; the user can increase this
|
|
866
|
+
* list in the future via the `ignoreActions` method.
|
|
867
|
+
*/
|
|
868
|
+
_ignoredActions = new Set([InitState.type, UpdateState.type]);
|
|
859
869
|
constructor() {
|
|
860
|
-
/**
|
|
861
|
-
* These actions should be ignored by default; the user can increase this
|
|
862
|
-
* list in the future via the `ignoreActions` method.
|
|
863
|
-
*/
|
|
864
|
-
this._ignoredActions = new Set([InitState.type, UpdateState.type]);
|
|
865
870
|
const options = inject(NGXS_DEVELOPMENT_OPTIONS);
|
|
866
871
|
if (typeof options.warnOnUnhandledActions === 'object') {
|
|
867
872
|
this.ignoreActions(...options.warnOnUnhandledActions.ignore);
|
|
@@ -887,18 +892,16 @@ class NgxsUnhandledActionsLogger {
|
|
|
887
892
|
: action.type;
|
|
888
893
|
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.`);
|
|
889
894
|
}
|
|
890
|
-
/** @nocollapse */ static
|
|
891
|
-
/** @nocollapse */ static
|
|
895
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsUnhandledActionsLogger, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
896
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsUnhandledActionsLogger });
|
|
892
897
|
}
|
|
893
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
898
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsUnhandledActionsLogger, decorators: [{
|
|
894
899
|
type: Injectable
|
|
895
900
|
}], ctorParameters: () => [] });
|
|
896
901
|
|
|
897
902
|
class NgxsUnhandledErrorHandler {
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
this._errorHandler = inject(ErrorHandler);
|
|
901
|
-
}
|
|
903
|
+
_ngZone = inject(NgZone);
|
|
904
|
+
_errorHandler = inject(ErrorHandler);
|
|
902
905
|
/**
|
|
903
906
|
* The `_unhandledErrorContext` is left unused internally since we do not
|
|
904
907
|
* require it for internal operations. However, developers who wish to provide
|
|
@@ -913,97 +916,14 @@ class NgxsUnhandledErrorHandler {
|
|
|
913
916
|
// `handleError` (see `_callAndReportToErrorHandler`).
|
|
914
917
|
this._ngZone.runOutsideAngular(() => this._errorHandler.handleError(error));
|
|
915
918
|
}
|
|
916
|
-
/** @nocollapse */ static
|
|
917
|
-
/** @nocollapse */ static
|
|
919
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsUnhandledErrorHandler, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
920
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsUnhandledErrorHandler, providedIn: 'root' });
|
|
918
921
|
}
|
|
919
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
922
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsUnhandledErrorHandler, decorators: [{
|
|
920
923
|
type: Injectable,
|
|
921
924
|
args: [{ providedIn: 'root' }]
|
|
922
925
|
}] });
|
|
923
926
|
|
|
924
|
-
function simplePatch(value) {
|
|
925
|
-
return (existingState) => {
|
|
926
|
-
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
927
|
-
if (Array.isArray(value)) {
|
|
928
|
-
throwPatchingArrayError();
|
|
929
|
-
}
|
|
930
|
-
else if (typeof value !== 'object') {
|
|
931
|
-
throwPatchingPrimitiveError();
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
const newState = { ...existingState };
|
|
935
|
-
for (const key in value) {
|
|
936
|
-
// deep clone for patch compatibility
|
|
937
|
-
newState[key] = value[key];
|
|
938
|
-
}
|
|
939
|
-
return newState;
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
|
-
|
|
943
|
-
/**
|
|
944
|
-
* State Context factory class
|
|
945
|
-
* @ignore
|
|
946
|
-
*/
|
|
947
|
-
class StateContextFactory {
|
|
948
|
-
constructor() {
|
|
949
|
-
this._internalStateOperations = inject(InternalStateOperations);
|
|
950
|
-
}
|
|
951
|
-
/**
|
|
952
|
-
* Create the state context
|
|
953
|
-
*/
|
|
954
|
-
createStateContext(path) {
|
|
955
|
-
const root = this._internalStateOperations.getRootStateOperations();
|
|
956
|
-
return {
|
|
957
|
-
getState() {
|
|
958
|
-
const currentAppState = root.getState();
|
|
959
|
-
return getState(currentAppState, path);
|
|
960
|
-
},
|
|
961
|
-
patchState(val) {
|
|
962
|
-
const currentAppState = root.getState();
|
|
963
|
-
const patchOperator = simplePatch(val);
|
|
964
|
-
setStateFromOperator(root, currentAppState, patchOperator, path);
|
|
965
|
-
},
|
|
966
|
-
setState(val) {
|
|
967
|
-
const currentAppState = root.getState();
|
|
968
|
-
if (isStateOperator(val)) {
|
|
969
|
-
setStateFromOperator(root, currentAppState, val, path);
|
|
970
|
-
}
|
|
971
|
-
else {
|
|
972
|
-
setStateValue(root, currentAppState, val, path);
|
|
973
|
-
}
|
|
974
|
-
},
|
|
975
|
-
dispatch(actions) {
|
|
976
|
-
return root.dispatch(actions);
|
|
977
|
-
}
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StateContextFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
981
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StateContextFactory, providedIn: 'root' }); }
|
|
982
|
-
}
|
|
983
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: StateContextFactory, decorators: [{
|
|
984
|
-
type: Injectable,
|
|
985
|
-
args: [{ providedIn: 'root' }]
|
|
986
|
-
}] });
|
|
987
|
-
function setStateValue(root, currentAppState, newValue, path) {
|
|
988
|
-
const newAppState = setValue(currentAppState, path, newValue);
|
|
989
|
-
root.setState(newAppState);
|
|
990
|
-
return newAppState;
|
|
991
|
-
// In doing this refactoring I noticed that there is a 'bug' where the
|
|
992
|
-
// application state is returned instead of this state slice.
|
|
993
|
-
// This has worked this way since the beginning see:
|
|
994
|
-
// https://github.com/ngxs/store/blame/324c667b4b7debd8eb979006c67ca0ae347d88cd/src/state-factory.ts
|
|
995
|
-
// This needs to be fixed, but is a 'breaking' change.
|
|
996
|
-
// I will do this fix in a subsequent PR and we can decide how to handle it.
|
|
997
|
-
}
|
|
998
|
-
function setStateFromOperator(root, currentAppState, stateOperator, path) {
|
|
999
|
-
const local = getState(currentAppState, path);
|
|
1000
|
-
const newValue = stateOperator(local);
|
|
1001
|
-
return setStateValue(root, currentAppState, newValue, path);
|
|
1002
|
-
}
|
|
1003
|
-
function getState(currentAppState, path) {
|
|
1004
|
-
return getValue(currentAppState, path);
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
927
|
/**
|
|
1008
928
|
* RxJS operator for selecting out specific actions.
|
|
1009
929
|
*
|
|
@@ -1106,6 +1026,160 @@ function createAllowedStatusesMap(statuses) {
|
|
|
1106
1026
|
}, {});
|
|
1107
1027
|
}
|
|
1108
1028
|
|
|
1029
|
+
function simplePatch(value) {
|
|
1030
|
+
return (existingState) => {
|
|
1031
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
1032
|
+
if (Array.isArray(value)) {
|
|
1033
|
+
throwPatchingArrayError();
|
|
1034
|
+
}
|
|
1035
|
+
else if (typeof value !== 'object') {
|
|
1036
|
+
throwPatchingPrimitiveError();
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
const newState = { ...existingState };
|
|
1040
|
+
for (const key in value) {
|
|
1041
|
+
// deep clone for patch compatibility
|
|
1042
|
+
newState[key] = value[key];
|
|
1043
|
+
}
|
|
1044
|
+
return newState;
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* State Context factory class
|
|
1050
|
+
* @ignore
|
|
1051
|
+
*/
|
|
1052
|
+
class StateContextFactory {
|
|
1053
|
+
_internalStateOperations = inject(InternalStateOperations);
|
|
1054
|
+
/**
|
|
1055
|
+
* Create the state context
|
|
1056
|
+
*/
|
|
1057
|
+
createStateContext(path) {
|
|
1058
|
+
const root = this._internalStateOperations.getRootStateOperations();
|
|
1059
|
+
return {
|
|
1060
|
+
getState() {
|
|
1061
|
+
const currentAppState = root.getState();
|
|
1062
|
+
return getState(currentAppState, path);
|
|
1063
|
+
},
|
|
1064
|
+
patchState(val) {
|
|
1065
|
+
const currentAppState = root.getState();
|
|
1066
|
+
const patchOperator = simplePatch(val);
|
|
1067
|
+
setStateFromOperator(root, currentAppState, patchOperator, path);
|
|
1068
|
+
},
|
|
1069
|
+
setState(val) {
|
|
1070
|
+
const currentAppState = root.getState();
|
|
1071
|
+
if (isStateOperator(val)) {
|
|
1072
|
+
setStateFromOperator(root, currentAppState, val, path);
|
|
1073
|
+
}
|
|
1074
|
+
else {
|
|
1075
|
+
setStateValue(root, currentAppState, val, path);
|
|
1076
|
+
}
|
|
1077
|
+
},
|
|
1078
|
+
dispatch(actions) {
|
|
1079
|
+
return root.dispatch(actions);
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: StateContextFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1084
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: StateContextFactory, providedIn: 'root' });
|
|
1085
|
+
}
|
|
1086
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: StateContextFactory, decorators: [{
|
|
1087
|
+
type: Injectable,
|
|
1088
|
+
args: [{ providedIn: 'root' }]
|
|
1089
|
+
}] });
|
|
1090
|
+
function setStateValue(root, currentAppState, newValue, path) {
|
|
1091
|
+
const newAppState = setValue(currentAppState, path, newValue);
|
|
1092
|
+
root.setState(newAppState);
|
|
1093
|
+
return newAppState;
|
|
1094
|
+
// In doing this refactoring I noticed that there is a 'bug' where the
|
|
1095
|
+
// application state is returned instead of this state slice.
|
|
1096
|
+
// This has worked this way since the beginning see:
|
|
1097
|
+
// https://github.com/ngxs/store/blame/324c667b4b7debd8eb979006c67ca0ae347d88cd/src/state-factory.ts
|
|
1098
|
+
// This needs to be fixed, but is a 'breaking' change.
|
|
1099
|
+
// I will do this fix in a subsequent PR and we can decide how to handle it.
|
|
1100
|
+
}
|
|
1101
|
+
function setStateFromOperator(root, currentAppState, stateOperator, path) {
|
|
1102
|
+
const local = getState(currentAppState, path);
|
|
1103
|
+
const newValue = stateOperator(local);
|
|
1104
|
+
return setStateValue(root, currentAppState, newValue, path);
|
|
1105
|
+
}
|
|
1106
|
+
function getState(currentAppState, path) {
|
|
1107
|
+
return getValue(currentAppState, path);
|
|
1108
|
+
}
|
|
1109
|
+
|
|
1110
|
+
class InternalActionHandlerFactory {
|
|
1111
|
+
_actions = inject(InternalActions);
|
|
1112
|
+
_stateContextFactory = inject(StateContextFactory);
|
|
1113
|
+
createActionHandler(path, handlerFn, options) {
|
|
1114
|
+
const { dispatched$ } = this._actions;
|
|
1115
|
+
return (action) => {
|
|
1116
|
+
const stateContext = this._stateContextFactory.createStateContext(path);
|
|
1117
|
+
let result = handlerFn(stateContext, action);
|
|
1118
|
+
// We need to use `isPromise` instead of checking whether
|
|
1119
|
+
// `result instanceof Promise`. In zone.js patched environments, `global.Promise`
|
|
1120
|
+
// is the `ZoneAwarePromise`. Some APIs, which are likely not patched by zone.js
|
|
1121
|
+
// for certain reasons, might not work with `instanceof`. For instance, the dynamic
|
|
1122
|
+
// import returns a native promise (not a `ZoneAwarePromise`), causing this check to
|
|
1123
|
+
// be falsy.
|
|
1124
|
+
if (_isPromise(result)) {
|
|
1125
|
+
result = from(result);
|
|
1126
|
+
}
|
|
1127
|
+
if (isObservable(result)) {
|
|
1128
|
+
result = result.pipe(mergeMap(value => (_isPromise(value) || isObservable(value) ? value : of(value))),
|
|
1129
|
+
// If this observable has completed without emitting any values,
|
|
1130
|
+
// we wouldn't want to complete the entire chain of actions.
|
|
1131
|
+
// If any observable completes, then the action will be canceled.
|
|
1132
|
+
// For instance, if any action handler had a statement like
|
|
1133
|
+
// `handler(ctx) { return EMPTY; }`, then the action would be canceled.
|
|
1134
|
+
// See https://github.com/ngxs/store/issues/1568
|
|
1135
|
+
// Note that we actually don't care about the return type; we only care
|
|
1136
|
+
// about emission, and thus `undefined` is applicable by the framework.
|
|
1137
|
+
defaultIfEmpty(undefined));
|
|
1138
|
+
if (options.cancelUncompleted) {
|
|
1139
|
+
const canceled = dispatched$.pipe(ofActionDispatched(action));
|
|
1140
|
+
result = result.pipe(takeUntil(canceled));
|
|
1141
|
+
}
|
|
1142
|
+
result = result.pipe(
|
|
1143
|
+
// Note that we use the `finalize` operator only when the action handler
|
|
1144
|
+
// explicitly returns an observable (or a promise) to wait for. This means
|
|
1145
|
+
// the action handler is written in a "fire & wait" style. If the handler’s
|
|
1146
|
+
// result is unsubscribed (either because the observable has completed or
|
|
1147
|
+
// it was unsubscribed by `takeUntil` due to a new action being dispatched),
|
|
1148
|
+
// we prevent writing to the state context.
|
|
1149
|
+
finalize(() => {
|
|
1150
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
1151
|
+
function noopAndWarn() {
|
|
1152
|
+
console.warn(`"${action}" attempted to change the state, but the change was ignored because state updates are not allowed after the action handler has completed.`);
|
|
1153
|
+
}
|
|
1154
|
+
stateContext.setState = noopAndWarn;
|
|
1155
|
+
stateContext.patchState = noopAndWarn;
|
|
1156
|
+
}
|
|
1157
|
+
else {
|
|
1158
|
+
stateContext.setState = noop;
|
|
1159
|
+
stateContext.patchState = noop;
|
|
1160
|
+
}
|
|
1161
|
+
}));
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
// If the action handler is synchronous and returns nothing (`void`), we
|
|
1165
|
+
// still have to convert the result to a synchronous observable.
|
|
1166
|
+
result = of(undefined);
|
|
1167
|
+
}
|
|
1168
|
+
return result;
|
|
1169
|
+
};
|
|
1170
|
+
}
|
|
1171
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalActionHandlerFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1172
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalActionHandlerFactory, providedIn: 'root' });
|
|
1173
|
+
}
|
|
1174
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: InternalActionHandlerFactory, decorators: [{
|
|
1175
|
+
type: Injectable,
|
|
1176
|
+
args: [{ providedIn: 'root' }]
|
|
1177
|
+
}] });
|
|
1178
|
+
// This is used to replace `setState` and `patchState` once the action
|
|
1179
|
+
// handler has been unsubscribed or completed, to prevent writing
|
|
1180
|
+
// to the state context.
|
|
1181
|
+
function noop() { }
|
|
1182
|
+
|
|
1109
1183
|
function cloneDefaults(defaults) {
|
|
1110
1184
|
let value = defaults === undefined ? {} : defaults;
|
|
1111
1185
|
if (defaults) {
|
|
@@ -1130,54 +1204,54 @@ function cloneDefaults(defaults) {
|
|
|
1130
1204
|
* @ignore
|
|
1131
1205
|
*/
|
|
1132
1206
|
class StateFactory {
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
return getter;
|
|
1162
|
-
}
|
|
1163
|
-
return (...args) => {
|
|
1164
|
-
// Late loaded getter
|
|
1165
|
-
if (!getter) {
|
|
1166
|
-
getter = /*@__INLINE__*/ resolveGetter(key);
|
|
1167
|
-
}
|
|
1168
|
-
return getter ? getter(...args) : undefined;
|
|
1169
|
-
};
|
|
1170
|
-
},
|
|
1171
|
-
getSelectorOptions(localOptions) {
|
|
1172
|
-
const globalSelectorOptions = stateFactory._config.selectorOptions;
|
|
1173
|
-
return {
|
|
1174
|
-
...globalSelectorOptions,
|
|
1175
|
-
...(localOptions || {})
|
|
1176
|
-
};
|
|
1207
|
+
_injector = inject(Injector);
|
|
1208
|
+
_config = inject(NgxsConfig);
|
|
1209
|
+
_actionHandlerFactory = inject(InternalActionHandlerFactory);
|
|
1210
|
+
_actions = inject(InternalActions);
|
|
1211
|
+
_actionResults = inject(InternalDispatchedActionResults);
|
|
1212
|
+
_initialState = inject(_INITIAL_STATE_TOKEN, { optional: true });
|
|
1213
|
+
_actionRegistry = inject(_NgxsActionRegistry);
|
|
1214
|
+
_propGetter = inject(ɵPROP_GETTER);
|
|
1215
|
+
_actionsSubscription = null;
|
|
1216
|
+
_ngxsUnhandledErrorHandler = null;
|
|
1217
|
+
_states = [];
|
|
1218
|
+
_statesByName = {};
|
|
1219
|
+
_statePaths = {};
|
|
1220
|
+
getRuntimeSelectorContext = _memoize(() => {
|
|
1221
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
1222
|
+
const stateFactory = this;
|
|
1223
|
+
const propGetter = stateFactory._propGetter;
|
|
1224
|
+
function resolveGetter(key) {
|
|
1225
|
+
const path = stateFactory._statePaths[key];
|
|
1226
|
+
return path ? propGetter(path.split('.')) : null;
|
|
1227
|
+
}
|
|
1228
|
+
const context = {
|
|
1229
|
+
getStateGetter(key) {
|
|
1230
|
+
// Use `@__INLINE__` annotation to forcely inline `resolveGetter`.
|
|
1231
|
+
// This is a Terser annotation, which will function only in the production mode.
|
|
1232
|
+
let getter = /*@__INLINE__*/ resolveGetter(key);
|
|
1233
|
+
if (getter) {
|
|
1234
|
+
return getter;
|
|
1177
1235
|
}
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1236
|
+
return (...args) => {
|
|
1237
|
+
// Late loaded getter
|
|
1238
|
+
if (!getter) {
|
|
1239
|
+
getter = /*@__INLINE__*/ resolveGetter(key);
|
|
1240
|
+
}
|
|
1241
|
+
return getter ? getter(...args) : undefined;
|
|
1242
|
+
};
|
|
1243
|
+
},
|
|
1244
|
+
getSelectorOptions(localOptions) {
|
|
1245
|
+
const globalSelectorOptions = stateFactory._config.selectorOptions;
|
|
1246
|
+
return {
|
|
1247
|
+
...globalSelectorOptions,
|
|
1248
|
+
...(localOptions || {})
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
};
|
|
1252
|
+
return context;
|
|
1253
|
+
});
|
|
1254
|
+
constructor() {
|
|
1181
1255
|
inject(DestroyRef).onDestroy(() => this._actionsSubscription?.unsubscribe());
|
|
1182
1256
|
}
|
|
1183
1257
|
/**
|
|
@@ -1315,103 +1389,37 @@ class StateFactory {
|
|
|
1315
1389
|
return this._statesByName[name] && valueIsBootstrappedInInitialState;
|
|
1316
1390
|
}
|
|
1317
1391
|
hydrateActionMetasMap({ path, actions, instance }) {
|
|
1318
|
-
const { dispatched$ } = this._actions;
|
|
1319
1392
|
for (const actionType of Object.keys(actions)) {
|
|
1320
1393
|
const actionHandlers = actions[actionType].map(actionMeta => {
|
|
1321
|
-
const
|
|
1322
|
-
return (
|
|
1323
|
-
const stateContext = this._stateContextFactory.createStateContext(path);
|
|
1324
|
-
let result = instance[actionMeta.fn](stateContext, action);
|
|
1325
|
-
// We need to use `isPromise` instead of checking whether
|
|
1326
|
-
// `result instanceof Promise`. In zone.js patched environments, `global.Promise`
|
|
1327
|
-
// is the `ZoneAwarePromise`. Some APIs, which are likely not patched by zone.js
|
|
1328
|
-
// for certain reasons, might not work with `instanceof`. For instance, the dynamic
|
|
1329
|
-
// import returns a native promise (not a `ZoneAwarePromise`), causing this check to
|
|
1330
|
-
// be falsy.
|
|
1331
|
-
if (_isPromise(result)) {
|
|
1332
|
-
result = from(result);
|
|
1333
|
-
}
|
|
1334
|
-
if (isObservable(result)) {
|
|
1335
|
-
result = result.pipe(mergeMap((value) => {
|
|
1336
|
-
if (_isPromise(value) || isObservable(value)) {
|
|
1337
|
-
return value;
|
|
1338
|
-
}
|
|
1339
|
-
else {
|
|
1340
|
-
return of(value);
|
|
1341
|
-
}
|
|
1342
|
-
}),
|
|
1343
|
-
// If this observable has completed without emitting any values,
|
|
1344
|
-
// we wouldn't want to complete the entire chain of actions.
|
|
1345
|
-
// If any observable completes, then the action will be canceled.
|
|
1346
|
-
// For instance, if any action handler had a statement like
|
|
1347
|
-
// `handler(ctx) { return EMPTY; }`, then the action would be canceled.
|
|
1348
|
-
// See https://github.com/ngxs/store/issues/1568
|
|
1349
|
-
// Note that we actually don't care about the return type; we only care
|
|
1350
|
-
// about emission, and thus `undefined` is applicable by the framework.
|
|
1351
|
-
defaultIfEmpty(undefined));
|
|
1352
|
-
if (cancelable) {
|
|
1353
|
-
const canceled = dispatched$.pipe(ofActionDispatched(action));
|
|
1354
|
-
result = result.pipe(takeUntil(canceled));
|
|
1355
|
-
}
|
|
1356
|
-
result = result.pipe(
|
|
1357
|
-
// Note that we use the `finalize` operator only when the action handler
|
|
1358
|
-
// explicitly returns an observable (or a promise) to wait for. This means
|
|
1359
|
-
// the action handler is written in a "fire & wait" style. If the handler’s
|
|
1360
|
-
// result is unsubscribed (either because the observable has completed or
|
|
1361
|
-
// it was unsubscribed by `takeUntil` due to a new action being dispatched),
|
|
1362
|
-
// we prevent writing to the state context.
|
|
1363
|
-
finalize(() => {
|
|
1364
|
-
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
1365
|
-
function noopAndWarn() {
|
|
1366
|
-
console.warn(`"${actionType}" attempted to change the state, but the change was ignored because state updates are not allowed after the action handler has completed.`);
|
|
1367
|
-
}
|
|
1368
|
-
stateContext.setState = noopAndWarn;
|
|
1369
|
-
stateContext.patchState = noopAndWarn;
|
|
1370
|
-
}
|
|
1371
|
-
else {
|
|
1372
|
-
stateContext.setState = noop;
|
|
1373
|
-
stateContext.patchState = noop;
|
|
1374
|
-
}
|
|
1375
|
-
}));
|
|
1376
|
-
}
|
|
1377
|
-
else {
|
|
1378
|
-
// If the action handler is synchronous and returns nothing (`void`), we
|
|
1379
|
-
// still have to convert the result to a synchronous observable.
|
|
1380
|
-
result = of(undefined);
|
|
1381
|
-
}
|
|
1382
|
-
return result;
|
|
1383
|
-
};
|
|
1394
|
+
const handlerFn = (ctx, action) => instance[actionMeta.fn](ctx, action);
|
|
1395
|
+
return this._actionHandlerFactory.createActionHandler(path, handlerFn, actionMeta.options);
|
|
1384
1396
|
});
|
|
1385
1397
|
for (const actionHandler of actionHandlers) {
|
|
1386
1398
|
this._actionRegistry.register(actionType, actionHandler);
|
|
1387
1399
|
}
|
|
1388
1400
|
}
|
|
1389
1401
|
}
|
|
1390
|
-
/** @nocollapse */ static
|
|
1391
|
-
/** @nocollapse */ static
|
|
1402
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: StateFactory, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1403
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: StateFactory, providedIn: 'root' });
|
|
1392
1404
|
}
|
|
1393
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1405
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: StateFactory, decorators: [{
|
|
1394
1406
|
type: Injectable,
|
|
1395
1407
|
args: [{ providedIn: 'root' }]
|
|
1396
1408
|
}], ctorParameters: () => [] });
|
|
1397
|
-
// This is used to replace `setState` and `patchState` once the action
|
|
1398
|
-
// handler has been unsubscribed or completed, to prevent writing
|
|
1399
|
-
// to the state context.
|
|
1400
|
-
function noop() { }
|
|
1401
1409
|
|
|
1402
1410
|
class Store {
|
|
1411
|
+
_stateStream = inject(_StateStream);
|
|
1412
|
+
_internalStateOperations = inject(InternalStateOperations);
|
|
1413
|
+
_config = inject(NgxsConfig);
|
|
1414
|
+
_internalExecutionStrategy = inject(InternalNgxsExecutionStrategy);
|
|
1415
|
+
_stateFactory = inject(StateFactory);
|
|
1416
|
+
/**
|
|
1417
|
+
* This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
|
|
1418
|
+
* because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
|
|
1419
|
+
* All selects would use this stream, and it would call leave only once for any state change across all active selectors.
|
|
1420
|
+
*/
|
|
1421
|
+
_selectableStateStream = this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy), shareReplay({ bufferSize: 1, refCount: true }));
|
|
1403
1422
|
constructor() {
|
|
1404
|
-
this._stateStream = inject(_StateStream);
|
|
1405
|
-
this._internalStateOperations = inject(InternalStateOperations);
|
|
1406
|
-
this._config = inject(NgxsConfig);
|
|
1407
|
-
this._internalExecutionStrategy = inject(InternalNgxsExecutionStrategy);
|
|
1408
|
-
this._stateFactory = inject(StateFactory);
|
|
1409
|
-
/**
|
|
1410
|
-
* This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
|
|
1411
|
-
* because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
|
|
1412
|
-
* All selects would use this stream, and it would call leave only once for any state change across all active selectors.
|
|
1413
|
-
*/
|
|
1414
|
-
this._selectableStateStream = this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy), shareReplay({ bufferSize: 1, refCount: true }));
|
|
1415
1423
|
this.initStateStream();
|
|
1416
1424
|
}
|
|
1417
1425
|
/**
|
|
@@ -1498,10 +1506,10 @@ class Store {
|
|
|
1498
1506
|
this._stateStream.next(initialStateValue);
|
|
1499
1507
|
}
|
|
1500
1508
|
}
|
|
1501
|
-
/** @nocollapse */ static
|
|
1502
|
-
/** @nocollapse */ static
|
|
1509
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: Store, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1510
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: Store, providedIn: 'root' });
|
|
1503
1511
|
}
|
|
1504
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1512
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: Store, decorators: [{
|
|
1505
1513
|
type: Injectable,
|
|
1506
1514
|
args: [{ providedIn: 'root' }]
|
|
1507
1515
|
}], ctorParameters: () => [] });
|
|
@@ -1549,12 +1557,11 @@ function assertRootStoreNotInitialized() {
|
|
|
1549
1557
|
}
|
|
1550
1558
|
|
|
1551
1559
|
class LifecycleStateManager {
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
}
|
|
1560
|
+
_store = inject(Store);
|
|
1561
|
+
_internalStateOperations = inject(InternalStateOperations);
|
|
1562
|
+
_stateContextFactory = inject(StateContextFactory);
|
|
1563
|
+
_appBootstrappedState = inject(_NgxsAppBootstrappedState);
|
|
1564
|
+
_initStateHasBeenDispatched;
|
|
1558
1565
|
ngxsBootstrap(action, results) {
|
|
1559
1566
|
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
1560
1567
|
if (action instanceof InitState) {
|
|
@@ -1630,10 +1637,10 @@ class LifecycleStateManager {
|
|
|
1630
1637
|
_getStateContext(mappedStore) {
|
|
1631
1638
|
return this._stateContextFactory.createStateContext(mappedStore.path);
|
|
1632
1639
|
}
|
|
1633
|
-
/** @nocollapse */ static
|
|
1634
|
-
/** @nocollapse */ static
|
|
1640
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: LifecycleStateManager, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1641
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: LifecycleStateManager, providedIn: 'root' });
|
|
1635
1642
|
}
|
|
1636
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1643
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: LifecycleStateManager, decorators: [{
|
|
1637
1644
|
type: Injectable,
|
|
1638
1645
|
args: [{ providedIn: 'root' }]
|
|
1639
1646
|
}] });
|
|
@@ -1719,11 +1726,11 @@ class NgxsRootModule {
|
|
|
1719
1726
|
constructor() {
|
|
1720
1727
|
rootStoreInitializer();
|
|
1721
1728
|
}
|
|
1722
|
-
/** @nocollapse */ static
|
|
1723
|
-
/** @nocollapse */ static
|
|
1724
|
-
/** @nocollapse */ static
|
|
1729
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsRootModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1730
|
+
/** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.3", ngImport: i0, type: NgxsRootModule });
|
|
1731
|
+
/** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsRootModule });
|
|
1725
1732
|
}
|
|
1726
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1733
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsRootModule, decorators: [{
|
|
1727
1734
|
type: NgModule
|
|
1728
1735
|
}], ctorParameters: () => [] });
|
|
1729
1736
|
|
|
@@ -1734,11 +1741,11 @@ class NgxsFeatureModule {
|
|
|
1734
1741
|
constructor() {
|
|
1735
1742
|
featureStatesInitializer();
|
|
1736
1743
|
}
|
|
1737
|
-
/** @nocollapse */ static
|
|
1738
|
-
/** @nocollapse */ static
|
|
1739
|
-
/** @nocollapse */ static
|
|
1744
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsFeatureModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1745
|
+
/** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.3", ngImport: i0, type: NgxsFeatureModule });
|
|
1746
|
+
/** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsFeatureModule });
|
|
1740
1747
|
}
|
|
1741
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1748
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsFeatureModule, decorators: [{
|
|
1742
1749
|
type: NgModule
|
|
1743
1750
|
}], ctorParameters: () => [] });
|
|
1744
1751
|
|
|
@@ -1797,11 +1804,11 @@ class NgxsModule {
|
|
|
1797
1804
|
providers: getFeatureProviders(states)
|
|
1798
1805
|
};
|
|
1799
1806
|
}
|
|
1800
|
-
/** @nocollapse */ static
|
|
1801
|
-
/** @nocollapse */ static
|
|
1802
|
-
/** @nocollapse */ static
|
|
1807
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1808
|
+
/** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.3", ngImport: i0, type: NgxsModule });
|
|
1809
|
+
/** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsModule });
|
|
1803
1810
|
}
|
|
1804
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1811
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsModule, decorators: [{
|
|
1805
1812
|
type: NgModule
|
|
1806
1813
|
}] });
|
|
1807
1814
|
|
|
@@ -1952,6 +1959,21 @@ function Selector(selectors) {
|
|
|
1952
1959
|
};
|
|
1953
1960
|
}
|
|
1954
1961
|
|
|
1962
|
+
class ActionDirector {
|
|
1963
|
+
_registry = inject(_NgxsActionRegistry);
|
|
1964
|
+
_actionHandlerFactory = inject(InternalActionHandlerFactory);
|
|
1965
|
+
attachAction(stateToken, Action, handlerFn, options = {}) {
|
|
1966
|
+
const actionHandler = this._actionHandlerFactory.createActionHandler(stateToken.getName(), handlerFn, options);
|
|
1967
|
+
this._registry.register(Action.type, actionHandler);
|
|
1968
|
+
}
|
|
1969
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: ActionDirector, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1970
|
+
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: ActionDirector, providedIn: 'root' });
|
|
1971
|
+
}
|
|
1972
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: ActionDirector, decorators: [{
|
|
1973
|
+
type: Injectable,
|
|
1974
|
+
args: [{ providedIn: 'root' }]
|
|
1975
|
+
}] });
|
|
1976
|
+
|
|
1955
1977
|
class NgxsDevelopmentModule {
|
|
1956
1978
|
static forRoot(options) {
|
|
1957
1979
|
return {
|
|
@@ -1962,11 +1984,11 @@ class NgxsDevelopmentModule {
|
|
|
1962
1984
|
]
|
|
1963
1985
|
};
|
|
1964
1986
|
}
|
|
1965
|
-
/** @nocollapse */ static
|
|
1966
|
-
/** @nocollapse */ static
|
|
1967
|
-
/** @nocollapse */ static
|
|
1987
|
+
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsDevelopmentModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1988
|
+
/** @nocollapse */ static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "20.0.3", ngImport: i0, type: NgxsDevelopmentModule });
|
|
1989
|
+
/** @nocollapse */ static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsDevelopmentModule });
|
|
1968
1990
|
}
|
|
1969
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1991
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.3", ngImport: i0, type: NgxsDevelopmentModule, decorators: [{
|
|
1970
1992
|
type: NgModule
|
|
1971
1993
|
}] });
|
|
1972
1994
|
function withNgxsDevelopmentOptions(options) {
|
|
@@ -2344,5 +2366,5 @@ function ɵprovideNgxsInternalStateTokens() {
|
|
|
2344
2366
|
* Generated bundle index. Do not edit.
|
|
2345
2367
|
*/
|
|
2346
2368
|
|
|
2347
|
-
export { Action, ActionStatus, Actions, NgxsConfig, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NgxsUnhandledErrorHandler, Selector, SelectorOptions, State, Store, createDispatchMap, createModelSelector, createPickSelector, createPropertySelectors, createSelectMap, createSelector, dispatch, lazyProvider, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, select, withNgxsDevelopmentOptions, withNgxsPendingTasks, withNgxsPlugin, withNgxsPreboot, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule, ɵprovideNgxsInternalStateTokens };
|
|
2369
|
+
export { Action, ActionDirector, ActionStatus, Actions, NgxsConfig, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NgxsUnhandledErrorHandler, Selector, SelectorOptions, State, Store, createDispatchMap, createModelSelector, createPickSelector, createPropertySelectors, createSelectMap, createSelector, dispatch, lazyProvider, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, select, withNgxsDevelopmentOptions, withNgxsPendingTasks, withNgxsPlugin, withNgxsPreboot, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule, ɵprovideNgxsInternalStateTokens };
|
|
2348
2370
|
//# sourceMappingURL=ngxs-store.mjs.map
|