@ngxs/store 19.0.0-dev.master-2b2355c → 19.0.0-dev.master-235f969
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 +2 -4
- package/fesm2022/ngxs-store-internals-testing.mjs.map +1 -1
- package/fesm2022/ngxs-store.mjs +262 -216
- package/fesm2022/ngxs-store.mjs.map +1 -1
- package/index.d.ts +5 -17
- package/package.json +1 -5
- package/schematics/src/actions/actions.factory.js +3 -3
- package/schematics/src/actions/actions.factory.js.map +1 -1
- package/schematics/src/ng-add/add-declaration.js +1 -1
- package/schematics/src/ng-add/add-declaration.js.map +1 -1
- package/schematics/src/ng-add/ng-add.factory.js +4 -4
- package/schematics/src/ng-add/ng-add.factory.js.map +1 -1
- package/schematics/src/starter-kit/starter-kit.factory.js +3 -3
- package/schematics/src/starter-kit/starter-kit.factory.js.map +1 -1
- package/schematics/src/state/state.factory.js +4 -4
- package/schematics/src/state/state.factory.js.map +1 -1
- package/schematics/src/store/store.factory.js +4 -4
- package/schematics/src/store/store.factory.js.map +1 -1
- package/schematics/src/utils/common/lib.config.js.map +1 -0
- package/schematics/src/utils/common/project-files.config.js +7 -0
- package/schematics/src/utils/common/project-files.config.js.map +1 -0
- package/schematics/src/utils/common/properties.js.map +1 -0
- package/schematics/src/utils/config.js.map +1 -0
- package/schematics/src/utils/generate-utils.js.map +1 -0
- package/schematics/src/utils/interfaces/package.interface.js +3 -0
- package/schematics/src/utils/interfaces/package.interface.js.map +1 -0
- package/schematics/src/utils/normalize-options.js.map +1 -0
- package/schematics/src/utils/project.js.map +1 -0
- package/schematics/src/utils/versions.json +3 -0
- package/migrations/migrations.json +0 -11
- package/migrations/src/19_1_0/__snapshots__/index.spec.ts.snap +0 -151
- package/migrations/src/19_1_0/index.js +0 -213
- package/migrations/src/19_1_0/index.js.map +0 -1
- package/migrations/src/19_1_0/index.spec.js +0 -220
- package/migrations/src/19_1_0/index.spec.js.map +0 -1
- package/schematics-utils/_testing/index.js +0 -18
- package/schematics-utils/_testing/index.js.map +0 -1
- package/schematics-utils/_testing/schematics.js +0 -70
- package/schematics-utils/_testing/schematics.js.map +0 -1
- package/schematics-utils/src/common/lib.config.js.map +0 -1
- package/schematics-utils/src/common/properties.js.map +0 -1
- package/schematics-utils/src/config.js.map +0 -1
- package/schematics-utils/src/file-utils.js +0 -26
- package/schematics-utils/src/file-utils.js.map +0 -1
- package/schematics-utils/src/generate-utils.js.map +0 -1
- package/schematics-utils/src/normalize-options.js.map +0 -1
- package/schematics-utils/src/project.js.map +0 -1
- /package/{schematics-utils/src → schematics/src/utils}/common/lib.config.js +0 -0
- /package/{schematics-utils/src → schematics/src/utils}/common/properties.js +0 -0
- /package/{schematics-utils/src → schematics/src/utils}/config.js +0 -0
- /package/{schematics-utils/src → schematics/src/utils}/generate-utils.js +0 -0
- /package/{schematics-utils/src → schematics/src/utils}/normalize-options.js +0 -0
- /package/{schematics-utils/src → schematics/src/utils}/project.js +0 -0
package/fesm2022/ngxs-store.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject,
|
|
2
|
+
import { Injectable, inject, NgZone, InjectionToken, INJECTOR, DestroyRef, Injector, runInInjectionContext, ErrorHandler, ɵisPromise as _isPromise, computed, makeEnvironmentProviders, provideEnvironmentInitializer, NgModule, APP_BOOTSTRAP_LISTENER, ApplicationRef, PendingTasks } from '@angular/core';
|
|
3
3
|
import { config, Observable, Subject, share, forkJoin, map, throwError, shareReplay, filter, take, mergeMap, EMPTY, defaultIfEmpty, catchError, from, isObservable, takeUntil, finalize, distinctUntilChanged, startWith, skip, buffer, debounceTime } from 'rxjs';
|
|
4
4
|
import { ɵwrapObserverCalls as _wrapObserverCalls, ɵOrderedSubject as _OrderedSubject, ɵStateStream as _StateStream, ɵof as _of, ɵhasOwnProperty as _hasOwnProperty, ɵ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, ɵdefineProperty as _defineProperty, ɵNGXS_STATE_CONTEXT_FACTORY as _NGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY as _NGXS_STATE_FACTORY } from '@ngxs/store/internals';
|
|
5
5
|
export { StateToken } from '@ngxs/store/internals';
|
|
@@ -7,6 +7,159 @@ import { NGXS_PLUGINS, getActionTypeFromInstance, InitState, UpdateState, setVal
|
|
|
7
7
|
export { InitState, NGXS_PLUGINS, UpdateState, actionMatcher, getActionTypeFromInstance, getValue, setValue } from '@ngxs/store/plugins';
|
|
8
8
|
import { isStateOperator } from '@ngxs/store/operators';
|
|
9
9
|
|
|
10
|
+
class NoopNgxsExecutionStrategy {
|
|
11
|
+
enter(func) {
|
|
12
|
+
return func();
|
|
13
|
+
}
|
|
14
|
+
leave(func) {
|
|
15
|
+
return func();
|
|
16
|
+
}
|
|
17
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
18
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, providedIn: 'root' }); }
|
|
19
|
+
}
|
|
20
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, decorators: [{
|
|
21
|
+
type: Injectable,
|
|
22
|
+
args: [{ providedIn: 'root' }]
|
|
23
|
+
}] });
|
|
24
|
+
|
|
25
|
+
function throwStateNameError(name) {
|
|
26
|
+
throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
|
|
27
|
+
}
|
|
28
|
+
function throwStateNamePropertyError() {
|
|
29
|
+
throw new Error(`States must register a 'name' property.`);
|
|
30
|
+
}
|
|
31
|
+
function throwStateUniqueError(current, newName, oldName) {
|
|
32
|
+
throw new Error(`State name '${current}' from ${newName} already exists in ${oldName}.`);
|
|
33
|
+
}
|
|
34
|
+
function throwStateDecoratorError(name) {
|
|
35
|
+
throw new Error(`States must be decorated with @State() decorator, but "${name}" isn't.`);
|
|
36
|
+
}
|
|
37
|
+
function throwActionDecoratorError() {
|
|
38
|
+
throw new Error('@Action() decorator cannot be used with static methods.');
|
|
39
|
+
}
|
|
40
|
+
function throwSelectorDecoratorError() {
|
|
41
|
+
throw new Error('Selectors only work on methods.');
|
|
42
|
+
}
|
|
43
|
+
function getZoneWarningMessage() {
|
|
44
|
+
return ('Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
|
|
45
|
+
'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
|
|
46
|
+
'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })');
|
|
47
|
+
}
|
|
48
|
+
function getUndecoratedStateWithInjectableWarningMessage(name) {
|
|
49
|
+
return `'${name}' class should be decorated with @Injectable() right after the @State() decorator`;
|
|
50
|
+
}
|
|
51
|
+
function getInvalidInitializationOrderMessage(addedStates) {
|
|
52
|
+
let message = 'You have an invalid state initialization order. This typically occurs when `NgxsModule.forFeature`\n' +
|
|
53
|
+
'or `provideStates` is called before `NgxsModule.forRoot` or `provideStore`.\n' +
|
|
54
|
+
'One example is when `NgxsRouterPluginModule.forRoot` is called before `NgxsModule.forRoot`.';
|
|
55
|
+
if (addedStates) {
|
|
56
|
+
const stateNames = Object.keys(addedStates).map(stateName => `"${stateName}"`);
|
|
57
|
+
message +=
|
|
58
|
+
'\nFeature states added before the store initialization is complete: ' +
|
|
59
|
+
`${stateNames.join(', ')}.`;
|
|
60
|
+
}
|
|
61
|
+
return message;
|
|
62
|
+
}
|
|
63
|
+
function throwSelectFactoryNotConnectedError() {
|
|
64
|
+
throw new Error('You have forgotten to import the NGXS module!');
|
|
65
|
+
}
|
|
66
|
+
function throwPatchingArrayError() {
|
|
67
|
+
throw new Error('Patching arrays is not supported.');
|
|
68
|
+
}
|
|
69
|
+
function throwPatchingPrimitiveError() {
|
|
70
|
+
throw new Error('Patching primitives is not supported.');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
class DispatchOutsideZoneNgxsExecutionStrategy {
|
|
74
|
+
constructor() {
|
|
75
|
+
this._ngZone = inject(NgZone);
|
|
76
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
77
|
+
verifyZoneIsNotNooped(this._ngZone);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
enter(func) {
|
|
81
|
+
if (typeof ngServerMode !== 'undefined' && ngServerMode) {
|
|
82
|
+
return this.runInsideAngular(func);
|
|
83
|
+
}
|
|
84
|
+
return this.runOutsideAngular(func);
|
|
85
|
+
}
|
|
86
|
+
leave(func) {
|
|
87
|
+
return this.runInsideAngular(func);
|
|
88
|
+
}
|
|
89
|
+
runInsideAngular(func) {
|
|
90
|
+
if (NgZone.isInAngularZone()) {
|
|
91
|
+
return func();
|
|
92
|
+
}
|
|
93
|
+
return this._ngZone.run(func);
|
|
94
|
+
}
|
|
95
|
+
runOutsideAngular(func) {
|
|
96
|
+
if (NgZone.isInAngularZone()) {
|
|
97
|
+
return this._ngZone.runOutsideAngular(func);
|
|
98
|
+
}
|
|
99
|
+
return func();
|
|
100
|
+
}
|
|
101
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
102
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: 'root' }); }
|
|
103
|
+
}
|
|
104
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, decorators: [{
|
|
105
|
+
type: Injectable,
|
|
106
|
+
args: [{ providedIn: 'root' }]
|
|
107
|
+
}], ctorParameters: () => [] });
|
|
108
|
+
// Caretaker note: this should exist as a separate function and not a class method,
|
|
109
|
+
// since class methods are not tree-shakable.
|
|
110
|
+
function verifyZoneIsNotNooped(ngZone) {
|
|
111
|
+
// `NoopNgZone` is not exposed publicly as it doesn't expect
|
|
112
|
+
// to be used outside of the core Angular code, thus we just have
|
|
113
|
+
// to check if the zone doesn't extend or instanceof `NgZone`.
|
|
114
|
+
if (ngZone instanceof NgZone) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
console.warn(getZoneWarningMessage());
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Consumers have the option to utilize the execution strategy provided by
|
|
122
|
+
* `NgxsModule.forRoot({executionStrategy})` or `provideStore([], {executionStrategy})`.
|
|
123
|
+
*/
|
|
124
|
+
const CUSTOM_NGXS_EXECUTION_STRATEGY = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'CUSTOM_NGXS_EXECUTION_STRATEGY' : '');
|
|
125
|
+
/**
|
|
126
|
+
* The injection token is used internally to resolve an instance of the execution
|
|
127
|
+
* strategy. It checks whether consumers have provided their own `executionStrategy`
|
|
128
|
+
* and also verifies if we are operating in a zone-aware environment.
|
|
129
|
+
*/
|
|
130
|
+
const NGXS_EXECUTION_STRATEGY = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_EXECUTION_STRATEGY' : '', {
|
|
131
|
+
providedIn: 'root',
|
|
132
|
+
factory: () => {
|
|
133
|
+
const ngZone = inject(NgZone);
|
|
134
|
+
const injector = inject(INJECTOR);
|
|
135
|
+
const executionStrategy = injector.get(CUSTOM_NGXS_EXECUTION_STRATEGY);
|
|
136
|
+
const isNgZoneEnabled = ngZone instanceof NgZone;
|
|
137
|
+
return executionStrategy
|
|
138
|
+
? injector.get(executionStrategy)
|
|
139
|
+
: injector.get(isNgZoneEnabled
|
|
140
|
+
? DispatchOutsideZoneNgxsExecutionStrategy
|
|
141
|
+
: NoopNgxsExecutionStrategy);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
class InternalNgxsExecutionStrategy {
|
|
146
|
+
constructor() {
|
|
147
|
+
this._executionStrategy = inject(NGXS_EXECUTION_STRATEGY);
|
|
148
|
+
}
|
|
149
|
+
enter(func) {
|
|
150
|
+
return this._executionStrategy.enter(func);
|
|
151
|
+
}
|
|
152
|
+
leave(func) {
|
|
153
|
+
return this._executionStrategy.leave(func);
|
|
154
|
+
}
|
|
155
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
156
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' }); }
|
|
157
|
+
}
|
|
158
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
|
|
159
|
+
type: Injectable,
|
|
160
|
+
args: [{ providedIn: 'root' }]
|
|
161
|
+
}] });
|
|
162
|
+
|
|
10
163
|
class PluginManager {
|
|
11
164
|
constructor() {
|
|
12
165
|
this.plugins = [];
|
|
@@ -118,88 +271,6 @@ function fallbackSubscriber(ngZone) {
|
|
|
118
271
|
};
|
|
119
272
|
}
|
|
120
273
|
|
|
121
|
-
// The injection token is used to resolve a list of states provided at
|
|
122
|
-
// the root level through either `NgxsModule.forRoot` or `provideStore`.
|
|
123
|
-
const ROOT_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'ROOT_STATE_TOKEN' : '');
|
|
124
|
-
// The injection token is used to resolve a list of states provided at
|
|
125
|
-
// the feature level through either `NgxsModule.forFeature` or `provideStates`.
|
|
126
|
-
// The Array<Array> is used to overload the resolved value of the token because
|
|
127
|
-
// it is a multi-provider token.
|
|
128
|
-
const FEATURE_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'FEATURE_STATE_TOKEN' : '');
|
|
129
|
-
// The injection token is used to resolve to options provided at the root
|
|
130
|
-
// level through either `NgxsModule.forRoot` or `provideStore`.
|
|
131
|
-
const NGXS_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_OPTIONS' : '');
|
|
132
|
-
/**
|
|
133
|
-
* The NGXS config settings.
|
|
134
|
-
*/
|
|
135
|
-
class NgxsConfig {
|
|
136
|
-
constructor() {
|
|
137
|
-
this.compatibility = {
|
|
138
|
-
strictContentSecurityPolicy: false
|
|
139
|
-
};
|
|
140
|
-
/**
|
|
141
|
-
* Defining shared selector options
|
|
142
|
-
*/
|
|
143
|
-
this.selectorOptions = {
|
|
144
|
-
injectContainerState: false,
|
|
145
|
-
suppressErrors: false
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
149
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: () => {
|
|
150
|
-
const defaultConfig = new NgxsConfig();
|
|
151
|
-
const config = inject(NGXS_OPTIONS);
|
|
152
|
-
return {
|
|
153
|
-
...defaultConfig,
|
|
154
|
-
...config,
|
|
155
|
-
selectorOptions: {
|
|
156
|
-
...defaultConfig.selectorOptions,
|
|
157
|
-
...config.selectorOptions
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
} }); }
|
|
161
|
-
}
|
|
162
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, decorators: [{
|
|
163
|
-
type: Injectable,
|
|
164
|
-
args: [{
|
|
165
|
-
providedIn: 'root',
|
|
166
|
-
useFactory: () => {
|
|
167
|
-
const defaultConfig = new NgxsConfig();
|
|
168
|
-
const config = inject(NGXS_OPTIONS);
|
|
169
|
-
return {
|
|
170
|
-
...defaultConfig,
|
|
171
|
-
...config,
|
|
172
|
-
selectorOptions: {
|
|
173
|
-
...defaultConfig.selectorOptions,
|
|
174
|
-
...config.selectorOptions
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}]
|
|
179
|
-
}] });
|
|
180
|
-
/**
|
|
181
|
-
* Represents a basic change from a previous to a new value for a single state instance.
|
|
182
|
-
* Passed as a value in a NgxsSimpleChanges object to the ngxsOnChanges hook.
|
|
183
|
-
*/
|
|
184
|
-
class NgxsSimpleChange {
|
|
185
|
-
constructor(previousValue, currentValue, firstChange) {
|
|
186
|
-
this.previousValue = previousValue;
|
|
187
|
-
this.currentValue = currentValue;
|
|
188
|
-
this.firstChange = firstChange;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* The injection token is used internally to resolve an instance of the execution strategy.
|
|
194
|
-
*/
|
|
195
|
-
const NGXS_EXECUTION_STRATEGY = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_EXECUTION_STRATEGY' : '', {
|
|
196
|
-
providedIn: 'root',
|
|
197
|
-
// Since `executionStrategy` is a `Type<...>`, we should inject it to retrieve an
|
|
198
|
-
// instance. This injection token essentially holds an instance of the
|
|
199
|
-
// execution strategy class.
|
|
200
|
-
factory: () => inject(inject(NGXS_OPTIONS).executionStrategy)
|
|
201
|
-
});
|
|
202
|
-
|
|
203
274
|
/**
|
|
204
275
|
* Internal Action result stream that is emitted when an action is completed.
|
|
205
276
|
* This is used as a method of returning the action result to the dispatcher
|
|
@@ -260,7 +331,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
|
|
|
260
331
|
class Actions extends Observable {
|
|
261
332
|
constructor() {
|
|
262
333
|
const internalActions$ = inject(InternalActions);
|
|
263
|
-
const internalExecutionStrategy = inject(
|
|
334
|
+
const internalExecutionStrategy = inject(InternalNgxsExecutionStrategy);
|
|
264
335
|
const sharedInternalActions$ = internalActions$.pipe(leaveNgxs(internalExecutionStrategy),
|
|
265
336
|
// The `InternalActions` subject emits outside of the Angular zone.
|
|
266
337
|
// We have to re-enter the Angular zone for any incoming consumer.
|
|
@@ -291,7 +362,7 @@ class InternalDispatcher {
|
|
|
291
362
|
this._actionResults = inject(InternalDispatchedActionResults);
|
|
292
363
|
this._pluginManager = inject(PluginManager);
|
|
293
364
|
this._stateStream = inject(_StateStream);
|
|
294
|
-
this._ngxsExecutionStrategy = inject(
|
|
365
|
+
this._ngxsExecutionStrategy = inject(InternalNgxsExecutionStrategy);
|
|
295
366
|
this._injector = inject(Injector);
|
|
296
367
|
}
|
|
297
368
|
/**
|
|
@@ -384,6 +455,89 @@ const compose = (injector, funcs) => (...args) => {
|
|
|
384
455
|
return runInInjectionContext(injector, () => curr(...args, (...nextArgs) => compose(injector, funcs)(...nextArgs)));
|
|
385
456
|
};
|
|
386
457
|
|
|
458
|
+
// The injection token is used to resolve a list of states provided at
|
|
459
|
+
// the root level through either `NgxsModule.forRoot` or `provideStore`.
|
|
460
|
+
const ROOT_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'ROOT_STATE_TOKEN' : '');
|
|
461
|
+
// The injection token is used to resolve a list of states provided at
|
|
462
|
+
// the feature level through either `NgxsModule.forFeature` or `provideStates`.
|
|
463
|
+
// The Array<Array> is used to overload the resolved value of the token because
|
|
464
|
+
// it is a multi-provider token.
|
|
465
|
+
const FEATURE_STATE_TOKEN = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'FEATURE_STATE_TOKEN' : '');
|
|
466
|
+
// The injection token is used to resolve to options provided at the root
|
|
467
|
+
// level through either `NgxsModule.forRoot` or `provideStore`.
|
|
468
|
+
const NGXS_OPTIONS = new InjectionToken(typeof ngDevMode !== 'undefined' && ngDevMode ? 'NGXS_OPTIONS' : '');
|
|
469
|
+
/**
|
|
470
|
+
* The NGXS config settings.
|
|
471
|
+
*/
|
|
472
|
+
class NgxsConfig {
|
|
473
|
+
constructor() {
|
|
474
|
+
this.compatibility = {
|
|
475
|
+
strictContentSecurityPolicy: false
|
|
476
|
+
};
|
|
477
|
+
/**
|
|
478
|
+
* Determines the execution context to perform async operations inside. An implementation can be
|
|
479
|
+
* provided to override the default behaviour where the async operations are run
|
|
480
|
+
* outside Angular's zone but all observable behaviours of NGXS are run back inside Angular's zone.
|
|
481
|
+
* These observable behaviours are from:
|
|
482
|
+
* `store.selectSignal(...)`, `store.select(...)`, `actions.subscribe(...)` or `store.dispatch(...).subscribe(...)`
|
|
483
|
+
* Every `zone.run` causes Angular to run change detection on the whole tree (`app.tick()`) so of your
|
|
484
|
+
* application doesn't rely on zone.js running change detection then you can switch to the
|
|
485
|
+
* `NoopNgxsExecutionStrategy` that doesn't interact with zones.
|
|
486
|
+
* (default: null)
|
|
487
|
+
*/
|
|
488
|
+
this.executionStrategy = DispatchOutsideZoneNgxsExecutionStrategy;
|
|
489
|
+
/**
|
|
490
|
+
* Defining shared selector options
|
|
491
|
+
*/
|
|
492
|
+
this.selectorOptions = {
|
|
493
|
+
injectContainerState: false,
|
|
494
|
+
suppressErrors: false
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
498
|
+
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: () => {
|
|
499
|
+
const defaultConfig = new NgxsConfig();
|
|
500
|
+
const config = inject(NGXS_OPTIONS);
|
|
501
|
+
return {
|
|
502
|
+
...defaultConfig,
|
|
503
|
+
...config,
|
|
504
|
+
selectorOptions: {
|
|
505
|
+
...defaultConfig.selectorOptions,
|
|
506
|
+
...config.selectorOptions
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
} }); }
|
|
510
|
+
}
|
|
511
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NgxsConfig, decorators: [{
|
|
512
|
+
type: Injectable,
|
|
513
|
+
args: [{
|
|
514
|
+
providedIn: 'root',
|
|
515
|
+
useFactory: () => {
|
|
516
|
+
const defaultConfig = new NgxsConfig();
|
|
517
|
+
const config = inject(NGXS_OPTIONS);
|
|
518
|
+
return {
|
|
519
|
+
...defaultConfig,
|
|
520
|
+
...config,
|
|
521
|
+
selectorOptions: {
|
|
522
|
+
...defaultConfig.selectorOptions,
|
|
523
|
+
...config.selectorOptions
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
}]
|
|
528
|
+
}] });
|
|
529
|
+
/**
|
|
530
|
+
* Represents a basic change from a previous to a new value for a single state instance.
|
|
531
|
+
* Passed as a value in a NgxsSimpleChanges object to the ngxsOnChanges hook.
|
|
532
|
+
*/
|
|
533
|
+
class NgxsSimpleChange {
|
|
534
|
+
constructor(previousValue, currentValue, firstChange) {
|
|
535
|
+
this.previousValue = previousValue;
|
|
536
|
+
this.currentValue = currentValue;
|
|
537
|
+
this.firstChange = firstChange;
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
|
|
387
541
|
/**
|
|
388
542
|
* Object freeze code
|
|
389
543
|
* https://github.com/jsdf/deep-freeze
|
|
@@ -783,54 +937,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImpor
|
|
|
783
937
|
args: [{ providedIn: 'root' }]
|
|
784
938
|
}], ctorParameters: () => [] });
|
|
785
939
|
|
|
786
|
-
function throwStateNameError(name) {
|
|
787
|
-
throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
|
|
788
|
-
}
|
|
789
|
-
function throwStateNamePropertyError() {
|
|
790
|
-
throw new Error(`States must register a 'name' property.`);
|
|
791
|
-
}
|
|
792
|
-
function throwStateUniqueError(current, newName, oldName) {
|
|
793
|
-
throw new Error(`State name '${current}' from ${newName} already exists in ${oldName}.`);
|
|
794
|
-
}
|
|
795
|
-
function throwStateDecoratorError(name) {
|
|
796
|
-
throw new Error(`States must be decorated with @State() decorator, but "${name}" isn't.`);
|
|
797
|
-
}
|
|
798
|
-
function throwActionDecoratorError() {
|
|
799
|
-
throw new Error('@Action() decorator cannot be used with static methods.');
|
|
800
|
-
}
|
|
801
|
-
function throwSelectorDecoratorError() {
|
|
802
|
-
throw new Error('Selectors only work on methods.');
|
|
803
|
-
}
|
|
804
|
-
function getZoneWarningMessage() {
|
|
805
|
-
return ('Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
|
|
806
|
-
'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
|
|
807
|
-
'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })');
|
|
808
|
-
}
|
|
809
|
-
function getUndecoratedStateWithInjectableWarningMessage(name) {
|
|
810
|
-
return `'${name}' class should be decorated with @Injectable() right after the @State() decorator`;
|
|
811
|
-
}
|
|
812
|
-
function getInvalidInitializationOrderMessage(addedStates) {
|
|
813
|
-
let message = 'You have an invalid state initialization order. This typically occurs when `NgxsModule.forFeature`\n' +
|
|
814
|
-
'or `provideStates` is called before `NgxsModule.forRoot` or `provideStore`.\n' +
|
|
815
|
-
'One example is when `NgxsRouterPluginModule.forRoot` is called before `NgxsModule.forRoot`.';
|
|
816
|
-
if (addedStates) {
|
|
817
|
-
const stateNames = Object.keys(addedStates).map(stateName => `"${stateName}"`);
|
|
818
|
-
message +=
|
|
819
|
-
'\nFeature states added before the store initialization is complete: ' +
|
|
820
|
-
`${stateNames.join(', ')}.`;
|
|
821
|
-
}
|
|
822
|
-
return message;
|
|
823
|
-
}
|
|
824
|
-
function throwSelectFactoryNotConnectedError() {
|
|
825
|
-
throw new Error('You have forgotten to import the NGXS module!');
|
|
826
|
-
}
|
|
827
|
-
function throwPatchingArrayError() {
|
|
828
|
-
throw new Error('Patching arrays is not supported.');
|
|
829
|
-
}
|
|
830
|
-
function throwPatchingPrimitiveError() {
|
|
831
|
-
throw new Error('Patching primitives is not supported.');
|
|
832
|
-
}
|
|
833
|
-
|
|
834
940
|
const stateNameRegex = /* @__PURE__ */ new RegExp('^[a-zA-Z0-9_]+$');
|
|
835
941
|
function ensureStateNameIsValid(name) {
|
|
836
942
|
if (!name) {
|
|
@@ -1424,7 +1530,7 @@ class Store {
|
|
|
1424
1530
|
this._stateStream = inject(_StateStream);
|
|
1425
1531
|
this._internalStateOperations = inject(InternalStateOperations);
|
|
1426
1532
|
this._config = inject(NgxsConfig);
|
|
1427
|
-
this._internalExecutionStrategy = inject(
|
|
1533
|
+
this._internalExecutionStrategy = inject(InternalNgxsExecutionStrategy);
|
|
1428
1534
|
this._stateFactory = inject(StateFactory);
|
|
1429
1535
|
/**
|
|
1430
1536
|
* This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
|
|
@@ -1808,6 +1914,10 @@ function getRootProviders(states, options) {
|
|
|
1808
1914
|
{
|
|
1809
1915
|
provide: NGXS_OPTIONS,
|
|
1810
1916
|
useValue: options
|
|
1917
|
+
},
|
|
1918
|
+
{
|
|
1919
|
+
provide: CUSTOM_NGXS_EXECUTION_STRATEGY,
|
|
1920
|
+
useValue: options.executionStrategy
|
|
1811
1921
|
}
|
|
1812
1922
|
];
|
|
1813
1923
|
}
|
|
@@ -1829,7 +1939,7 @@ function getFeatureProviders(states) {
|
|
|
1829
1939
|
}
|
|
1830
1940
|
|
|
1831
1941
|
class NgxsModule {
|
|
1832
|
-
static forRoot(states = [], options) {
|
|
1942
|
+
static forRoot(states = [], options = {}) {
|
|
1833
1943
|
return {
|
|
1834
1944
|
ngModule: NgxsRootModule,
|
|
1835
1945
|
providers: getRootProviders(states, options)
|
|
@@ -2050,68 +2160,6 @@ function Selector(selectors) {
|
|
|
2050
2160
|
};
|
|
2051
2161
|
}
|
|
2052
2162
|
|
|
2053
|
-
class DispatchOutsideZoneNgxsExecutionStrategy {
|
|
2054
|
-
constructor() {
|
|
2055
|
-
this._ngZone = inject(NgZone);
|
|
2056
|
-
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
2057
|
-
verifyZoneIsNotNooped(this._ngZone);
|
|
2058
|
-
}
|
|
2059
|
-
}
|
|
2060
|
-
enter(func) {
|
|
2061
|
-
if (typeof ngServerMode !== 'undefined' && ngServerMode) {
|
|
2062
|
-
return this.runInsideAngular(func);
|
|
2063
|
-
}
|
|
2064
|
-
return this.runOutsideAngular(func);
|
|
2065
|
-
}
|
|
2066
|
-
leave(func) {
|
|
2067
|
-
return this.runInsideAngular(func);
|
|
2068
|
-
}
|
|
2069
|
-
runInsideAngular(func) {
|
|
2070
|
-
if (NgZone.isInAngularZone()) {
|
|
2071
|
-
return func();
|
|
2072
|
-
}
|
|
2073
|
-
return this._ngZone.run(func);
|
|
2074
|
-
}
|
|
2075
|
-
runOutsideAngular(func) {
|
|
2076
|
-
if (NgZone.isInAngularZone()) {
|
|
2077
|
-
return this._ngZone.runOutsideAngular(func);
|
|
2078
|
-
}
|
|
2079
|
-
return func();
|
|
2080
|
-
}
|
|
2081
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2082
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: 'root' }); }
|
|
2083
|
-
}
|
|
2084
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, decorators: [{
|
|
2085
|
-
type: Injectable,
|
|
2086
|
-
args: [{ providedIn: 'root' }]
|
|
2087
|
-
}], ctorParameters: () => [] });
|
|
2088
|
-
// Caretaker note: this should exist as a separate function and not a class method,
|
|
2089
|
-
// since class methods are not tree-shakable.
|
|
2090
|
-
function verifyZoneIsNotNooped(ngZone) {
|
|
2091
|
-
// `NoopNgZone` is not exposed publicly as it doesn't expect
|
|
2092
|
-
// to be used outside of the core Angular code, thus we just have
|
|
2093
|
-
// to check if the zone doesn't extend or instanceof `NgZone`.
|
|
2094
|
-
if (ngZone instanceof NgZone) {
|
|
2095
|
-
return;
|
|
2096
|
-
}
|
|
2097
|
-
console.warn(getZoneWarningMessage());
|
|
2098
|
-
}
|
|
2099
|
-
|
|
2100
|
-
class NoopNgxsExecutionStrategy {
|
|
2101
|
-
enter(func) {
|
|
2102
|
-
return func();
|
|
2103
|
-
}
|
|
2104
|
-
leave(func) {
|
|
2105
|
-
return func();
|
|
2106
|
-
}
|
|
2107
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
2108
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, providedIn: 'root' }); }
|
|
2109
|
-
}
|
|
2110
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.0.0", ngImport: i0, type: NoopNgxsExecutionStrategy, decorators: [{
|
|
2111
|
-
type: Injectable,
|
|
2112
|
-
args: [{ providedIn: 'root' }]
|
|
2113
|
-
}] });
|
|
2114
|
-
|
|
2115
2163
|
class NgxsDevelopmentModule {
|
|
2116
2164
|
static forRoot(options) {
|
|
2117
2165
|
return {
|
|
@@ -2307,30 +2355,28 @@ function withNgxsPendingTasks() {
|
|
|
2307
2355
|
});
|
|
2308
2356
|
}
|
|
2309
2357
|
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
* developmentMode: !environment.production
|
|
2324
|
-
* });
|
|
2325
|
-
* ```
|
|
2326
|
-
*/
|
|
2327
|
-
function provideStore(states = [], options, ...features) {
|
|
2358
|
+
function provideStore(states = [], ...optionsAndFeatures) {
|
|
2359
|
+
const features = [];
|
|
2360
|
+
// Options are empty by default (see `forRoot`).
|
|
2361
|
+
let options = {};
|
|
2362
|
+
if (optionsAndFeatures.length > 0) {
|
|
2363
|
+
if (isEnvironmentProvider(optionsAndFeatures[0])) {
|
|
2364
|
+
features.push(...optionsAndFeatures);
|
|
2365
|
+
}
|
|
2366
|
+
else {
|
|
2367
|
+
options = optionsAndFeatures[0];
|
|
2368
|
+
features.push(...optionsAndFeatures.slice(1));
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2328
2371
|
return makeEnvironmentProviders([
|
|
2329
2372
|
...getRootProviders(states, options),
|
|
2330
2373
|
NGXS_ROOT_ENVIRONMENT_INITIALIZER,
|
|
2331
2374
|
features
|
|
2332
2375
|
]);
|
|
2333
2376
|
}
|
|
2377
|
+
function isEnvironmentProvider(target) {
|
|
2378
|
+
return !!target.ɵproviders;
|
|
2379
|
+
}
|
|
2334
2380
|
|
|
2335
2381
|
/**
|
|
2336
2382
|
* This version serves as a standalone alternative to `NgxsModule.forFeature`.
|
|
@@ -2448,5 +2494,5 @@ function ɵprovideNgxsInternalStateTokens() {
|
|
|
2448
2494
|
* Generated bundle index. Do not edit.
|
|
2449
2495
|
*/
|
|
2450
2496
|
|
|
2451
|
-
export { Action, Actions,
|
|
2497
|
+
export { Action, Actions, NgxsConfig, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NgxsUnhandledErrorHandler, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, Store, createDispatchMap, createModelSelector, createPickSelector, createPropertySelectors, createSelectMap, createSelector, dispatch, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, select, withNgxsDevelopmentOptions, withNgxsPendingTasks, withNgxsPlugin, withNgxsPreboot, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule, ɵprovideNgxsInternalStateTokens };
|
|
2452
2498
|
//# sourceMappingURL=ngxs-store.mjs.map
|