@ngxs/store 3.8.1-dev.master-22b962e → 3.8.1-dev.master-66dd672
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/esm2020/internals/initial-state.mjs +18 -0
- package/esm2020/internals/internal-tokens.mjs +6 -0
- package/{esm2015/internals/ngxs-bootstrapper.js → esm2020/internals/ngxs-bootstrapper.mjs} +4 -4
- package/esm2020/internals/testing/fresh-platform.mjs +72 -0
- package/{esm2015/internals/testing/helpers/ngxs-test.component.js → esm2020/internals/testing/helpers/ngxs-test.component.mjs} +4 -4
- package/esm2020/internals/testing/helpers/ngxs-test.module.mjs +20 -0
- package/{esm2015/internals/testing/ngxs.setup.js → esm2020/internals/testing/ngxs.setup.mjs} +4 -2
- package/esm2020/operators/patch.mjs +21 -0
- package/{esm2015/src/actions-stream.js → esm2020/src/actions-stream.mjs} +7 -7
- package/{esm2015/src/decorators/select/select-factory.js → esm2020/src/decorators/select/select-factory.mjs} +4 -4
- package/esm2020/src/decorators/selector/selector.mjs +32 -0
- package/esm2020/src/decorators/state.mjs +36 -0
- package/{esm2015/src/dev-features/ngxs-development.module.js → esm2020/src/dev-features/ngxs-development.module.mjs} +5 -5
- package/{esm2015/src/dev-features/ngxs-unhandled-actions-logger.js → esm2020/src/dev-features/ngxs-unhandled-actions-logger.mjs} +4 -4
- package/{esm2015/src/execution/dispatch-outside-zone-ngxs-execution-strategy.js → esm2020/src/execution/dispatch-outside-zone-ngxs-execution-strategy.mjs} +4 -4
- package/{esm2015/src/execution/internal-ngxs-execution-strategy.js → esm2020/src/execution/internal-ngxs-execution-strategy.mjs} +4 -4
- package/{esm2015/src/execution/noop-ngxs-execution-strategy.js → esm2020/src/execution/noop-ngxs-execution-strategy.mjs} +4 -4
- package/esm2020/src/execution/symbols.mjs +27 -0
- package/{esm2015/src/internal/dispatcher.js → esm2020/src/internal/dispatcher.mjs} +11 -11
- package/{esm2015/src/internal/error-handler.js → esm2020/src/internal/error-handler.mjs} +5 -5
- package/{esm2015/src/internal/lifecycle-state-manager.js → esm2020/src/internal/lifecycle-state-manager.mjs} +4 -4
- package/{esm2015/src/internal/state-context-factory.js → esm2020/src/internal/state-context-factory.mjs} +4 -4
- package/esm2020/src/internal/state-factory.mjs +292 -0
- package/{esm2015/src/internal/state-operations.js → esm2020/src/internal/state-operations.mjs} +5 -5
- package/esm2020/src/internal/state-operators.mjs +20 -0
- package/esm2020/src/internal/state-stream.mjs +27 -0
- package/{esm2015/src/ivy/ivy-enabled-in-dev-mode.js → esm2020/src/ivy/ivy-enabled-in-dev-mode.mjs} +2 -2
- package/esm2020/src/module.mjs +27 -0
- package/esm2020/src/modules/ngxs-feature.module.mjs +18 -0
- package/esm2020/src/modules/ngxs-root.module.mjs +18 -0
- package/{esm2015/src/operators/of-action.js → esm2020/src/operators/of-action.mjs} +10 -10
- package/{esm2015/src/plugin-manager.js → esm2020/src/plugin-manager.mjs} +4 -4
- package/esm2020/src/public_api.mjs +28 -0
- package/esm2020/src/selectors/create-property-selectors.mjs +20 -0
- package/esm2020/src/selectors/selector-metadata.mjs +35 -0
- package/esm2020/src/standalone-features/feature-providers.mjs +20 -0
- package/esm2020/src/standalone-features/index.mjs +4 -0
- package/esm2020/src/standalone-features/initializers.mjs +86 -0
- package/esm2020/src/standalone-features/plugin.mjs +20 -0
- package/esm2020/src/standalone-features/provide-states.mjs +26 -0
- package/esm2020/src/standalone-features/provide-store.mjs +26 -0
- package/esm2020/src/standalone-features/root-providers.mjs +47 -0
- package/{esm2015/src/store.js → esm2020/src/store.mjs} +6 -5
- package/esm2020/src/symbols.mjs +68 -0
- package/esm2020/src/utils/utils.mjs +92 -0
- package/fesm2015/{ngxs-store-internals-testing.js → ngxs-store-internals-testing.mjs} +19 -13
- package/fesm2015/ngxs-store-internals-testing.mjs.map +1 -0
- package/fesm2015/{ngxs-store-internals.js → ngxs-store-internals.mjs} +9 -7
- package/fesm2015/ngxs-store-internals.mjs.map +1 -0
- package/fesm2015/{ngxs-store-operators.js → ngxs-store-operators.mjs} +1 -1
- package/fesm2015/ngxs-store-operators.mjs.map +1 -0
- package/fesm2015/ngxs-store.mjs +2429 -0
- package/fesm2015/ngxs-store.mjs.map +1 -0
- package/fesm2020/ngxs-store-internals-testing.mjs +180 -0
- package/fesm2020/ngxs-store-internals-testing.mjs.map +1 -0
- package/fesm2020/ngxs-store-internals.mjs +103 -0
- package/fesm2020/ngxs-store-internals.mjs.map +1 -0
- package/fesm2020/ngxs-store-operators.mjs +202 -0
- package/fesm2020/ngxs-store-operators.mjs.map +1 -0
- package/{fesm2015/ngxs-store.js → fesm2020/ngxs-store.mjs} +1153 -1015
- package/fesm2020/ngxs-store.mjs.map +1 -0
- package/internals/initial-state.d.ts +1 -1
- package/internals/testing/helpers/ngxs-test.component.d.ts +1 -1
- package/package.json +46 -10
- package/src/execution/symbols.d.ts +8 -2
- package/src/module.d.ts +0 -11
- package/src/modules/ngxs-feature.module.d.ts +2 -9
- package/src/modules/ngxs-root.module.d.ts +2 -9
- package/src/public_api.d.ts +5 -4
- package/src/standalone-features/feature-providers.d.ts +7 -0
- package/src/standalone-features/index.d.ts +3 -0
- package/src/standalone-features/initializers.d.ts +29 -0
- package/src/standalone-features/plugin.d.ts +17 -0
- package/src/standalone-features/provide-states.d.ts +18 -0
- package/src/standalone-features/provide-store.d.ts +22 -0
- package/src/standalone-features/root-providers.d.ts +8 -0
- package/src/symbols.d.ts +3 -3
- package/bundles/ngxs-store-internals-testing.umd.js +0 -547
- package/bundles/ngxs-store-internals-testing.umd.js.map +0 -1
- package/bundles/ngxs-store-internals.umd.js +0 -141
- package/bundles/ngxs-store-internals.umd.js.map +0 -1
- package/bundles/ngxs-store-operators.umd.js +0 -224
- package/bundles/ngxs-store-operators.umd.js.map +0 -1
- package/bundles/ngxs-store.umd.js +0 -2939
- package/bundles/ngxs-store.umd.js.map +0 -1
- package/esm2015/internals/initial-state.js +0 -17
- package/esm2015/internals/internal-tokens.js +0 -5
- package/esm2015/internals/testing/fresh-platform.js +0 -70
- package/esm2015/internals/testing/helpers/ngxs-test.module.js +0 -21
- package/esm2015/operators/patch.js +0 -21
- package/esm2015/src/decorators/selector/selector.js +0 -32
- package/esm2015/src/decorators/state.js +0 -36
- package/esm2015/src/execution/symbols.js +0 -23
- package/esm2015/src/internal/state-factory.js +0 -288
- package/esm2015/src/internal/state-operators.js +0 -20
- package/esm2015/src/internal/state-stream.js +0 -25
- package/esm2015/src/module.js +0 -88
- package/esm2015/src/modules/ngxs-feature.module.js +0 -45
- package/esm2015/src/modules/ngxs-root.module.js +0 -41
- package/esm2015/src/public_api.js +0 -27
- package/esm2015/src/selectors/create-property-selectors.js +0 -20
- package/esm2015/src/selectors/selector-metadata.js +0 -30
- package/esm2015/src/symbols.js +0 -58
- package/esm2015/src/utils/utils.js +0 -92
- package/fesm2015/ngxs-store-internals-testing.js.map +0 -1
- package/fesm2015/ngxs-store-internals.js.map +0 -1
- package/fesm2015/ngxs-store-operators.js.map +0 -1
- package/fesm2015/ngxs-store.js.map +0 -1
- package/internals/ngxs-store-internals.d.ts +0 -5
- package/internals/package.json +0 -10
- package/internals/testing/ngxs-store-internals-testing.d.ts +0 -5
- package/internals/testing/package.json +0 -10
- package/ngxs-store.d.ts +0 -5
- package/operators/ngxs-store-operators.d.ts +0 -5
- package/operators/package.json +0 -10
- /package/{esm2015/index.js → esm2020/index.mjs} +0 -0
- /package/{esm2015/internals/index.js → esm2020/internals/index.mjs} +0 -0
- /package/{esm2015/internals/memoize.js → esm2020/internals/memoize.mjs} +0 -0
- /package/{esm2015/internals/ngxs-store-internals.js → esm2020/internals/ngxs-store-internals.mjs} +0 -0
- /package/{esm2015/internals/src/symbols.js → esm2020/internals/src/symbols.mjs} +0 -0
- /package/{esm2015/internals/symbols.js → esm2020/internals/symbols.mjs} +0 -0
- /package/{esm2015/internals/testing/index.js → esm2020/internals/testing/index.mjs} +0 -0
- /package/{esm2015/internals/testing/ngxs-store-internals-testing.js → esm2020/internals/testing/ngxs-store-internals-testing.mjs} +0 -0
- /package/{esm2015/internals/testing/skip-console-logging.js → esm2020/internals/testing/skip-console-logging.mjs} +0 -0
- /package/{esm2015/internals/testing/symbol.js → esm2020/internals/testing/symbol.mjs} +0 -0
- /package/{esm2015/ngxs-store.js → esm2020/ngxs-store.mjs} +0 -0
- /package/{esm2015/operators/append.js → esm2020/operators/append.mjs} +0 -0
- /package/{esm2015/operators/compose.js → esm2020/operators/compose.mjs} +0 -0
- /package/{esm2015/operators/iif.js → esm2020/operators/iif.mjs} +0 -0
- /package/{esm2015/operators/index.js → esm2020/operators/index.mjs} +0 -0
- /package/{esm2015/operators/insert-item.js → esm2020/operators/insert-item.mjs} +0 -0
- /package/{esm2015/operators/ngxs-store-operators.js → esm2020/operators/ngxs-store-operators.mjs} +0 -0
- /package/{esm2015/operators/remove-item.js → esm2020/operators/remove-item.mjs} +0 -0
- /package/{esm2015/operators/types.js → esm2020/operators/types.mjs} +0 -0
- /package/{esm2015/operators/update-item.js → esm2020/operators/update-item.mjs} +0 -0
- /package/{esm2015/operators/utils.js → esm2020/operators/utils.mjs} +0 -0
- /package/{esm2015/src/actions/actions.js → esm2020/src/actions/actions.mjs} +0 -0
- /package/{esm2015/src/actions/symbols.js → esm2020/src/actions/symbols.mjs} +0 -0
- /package/{esm2015/src/configs/messages.config.js → esm2020/src/configs/messages.config.mjs} +0 -0
- /package/{esm2015/src/decorators/action.js → esm2020/src/decorators/action.mjs} +0 -0
- /package/{esm2015/src/decorators/select/select.js → esm2020/src/decorators/select/select.mjs} +0 -0
- /package/{esm2015/src/decorators/select/symbols.js → esm2020/src/decorators/select/symbols.mjs} +0 -0
- /package/{esm2015/src/decorators/selector/symbols.js → esm2020/src/decorators/selector/symbols.mjs} +0 -0
- /package/{esm2015/src/decorators/selector-options.js → esm2020/src/decorators/selector-options.mjs} +0 -0
- /package/{esm2015/src/dev-features/symbols.js → esm2020/src/dev-features/symbols.mjs} +0 -0
- /package/{esm2015/src/internal/custom-rxjs-subjects.js → esm2020/src/internal/custom-rxjs-subjects.mjs} +0 -0
- /package/{esm2015/src/internal/internals.js → esm2020/src/internal/internals.mjs} +0 -0
- /package/{esm2015/src/operators/leave-ngxs.js → esm2020/src/operators/leave-ngxs.mjs} +0 -0
- /package/{esm2015/src/plugin_api.js → esm2020/src/plugin_api.mjs} +0 -0
- /package/{esm2015/src/private_api.js → esm2020/src/private_api.mjs} +0 -0
- /package/{esm2015/src/public_to_deprecate.js → esm2020/src/public_to_deprecate.mjs} +0 -0
- /package/{esm2015/src/selectors/create-model-selector.js → esm2020/src/selectors/create-model-selector.mjs} +0 -0
- /package/{esm2015/src/selectors/create-pick-selector.js → esm2020/src/selectors/create-pick-selector.mjs} +0 -0
- /package/{esm2015/src/selectors/create-selector.js → esm2020/src/selectors/create-selector.mjs} +0 -0
- /package/{esm2015/src/selectors/index.js → esm2020/src/selectors/index.mjs} +0 -0
- /package/{esm2015/src/selectors/selector-checks.util.js → esm2020/src/selectors/selector-checks.util.mjs} +0 -0
- /package/{esm2015/src/selectors/selector-models.js → esm2020/src/selectors/selector-models.mjs} +0 -0
- /package/{esm2015/src/selectors/selector-types.util.js → esm2020/src/selectors/selector-types.util.mjs} +0 -0
- /package/{esm2015/src/selectors/selector-utils.js → esm2020/src/selectors/selector-utils.mjs} +0 -0
- /package/{esm2015/src/state-token/state-token.js → esm2020/src/state-token/state-token.mjs} +0 -0
- /package/{esm2015/src/state-token/symbols.js → esm2020/src/state-token/symbols.mjs} +0 -0
- /package/{esm2015/src/utils/compose.js → esm2020/src/utils/compose.mjs} +0 -0
- /package/{esm2015/src/utils/freeze.js → esm2020/src/utils/freeze.mjs} +0 -0
- /package/{esm2015/src/utils/store-validators.js → esm2020/src/utils/store-validators.mjs} +0 -0
|
@@ -1,103 +1,26 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { NgZone, PLATFORM_ID,
|
|
2
|
+
import { Injectable, NgZone, PLATFORM_ID, Inject, InjectionToken, inject, INJECTOR, ɵglobal, ErrorHandler, Optional, SkipSelf, ENVIRONMENT_INITIALIZER, NgModule, APP_BOOTSTRAP_LISTENER, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
+
import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable } from 'rxjs';
|
|
4
|
+
import { share, shareReplay, filter, take, exhaustMap, map, mergeMap, defaultIfEmpty, catchError, takeUntil, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
|
|
3
5
|
import * as i5 from '@ngxs/store/internals';
|
|
4
6
|
import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY } from '@ngxs/store/internals';
|
|
5
7
|
import { isPlatformServer } from '@angular/common';
|
|
6
|
-
import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable } from 'rxjs';
|
|
7
|
-
import { filter, map, share, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
|
|
8
8
|
import { isStateOperator } from '@ngxs/store/operators';
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
function getActionTypeFromInstance(action) {
|
|
15
|
-
if (action.constructor && action.constructor.type) {
|
|
16
|
-
return action.constructor.type;
|
|
10
|
+
class NoopNgxsExecutionStrategy {
|
|
11
|
+
enter(func) {
|
|
12
|
+
return func();
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
return
|
|
14
|
+
leave(func) {
|
|
15
|
+
return func();
|
|
20
16
|
}
|
|
21
17
|
}
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return function (action2) {
|
|
29
|
-
return type1 === getActionTypeFromInstance(action2);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Set a deeply nested value. Example:
|
|
34
|
-
*
|
|
35
|
-
* setValue({ foo: { bar: { eat: false } } },
|
|
36
|
-
* 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
|
|
37
|
-
*
|
|
38
|
-
* While it traverses it also creates new objects from top down.
|
|
39
|
-
*
|
|
40
|
-
* @ignore
|
|
41
|
-
*/
|
|
42
|
-
const setValue = (obj, prop, val) => {
|
|
43
|
-
obj = Object.assign({}, obj);
|
|
44
|
-
const split = prop.split('.');
|
|
45
|
-
const lastIndex = split.length - 1;
|
|
46
|
-
split.reduce((acc, part, index) => {
|
|
47
|
-
if (index === lastIndex) {
|
|
48
|
-
acc[part] = val;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
|
|
52
|
-
}
|
|
53
|
-
return acc && acc[part];
|
|
54
|
-
}, obj);
|
|
55
|
-
return obj;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Get a deeply nested value. Example:
|
|
59
|
-
*
|
|
60
|
-
* getValue({ foo: bar: [] }, 'foo.bar') //=> []
|
|
61
|
-
*
|
|
62
|
-
* @ignore
|
|
63
|
-
*/
|
|
64
|
-
const getValue = (obj, prop) => prop.split('.').reduce((acc, part) => acc && acc[part], obj);
|
|
65
|
-
/**
|
|
66
|
-
* Simple object check.
|
|
67
|
-
*
|
|
68
|
-
* isObject({a:1}) //=> true
|
|
69
|
-
* isObject(1) //=> false
|
|
70
|
-
*
|
|
71
|
-
* @ignore
|
|
72
|
-
*/
|
|
73
|
-
const isObject$1 = (item) => {
|
|
74
|
-
return item && typeof item === 'object' && !Array.isArray(item);
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Deep merge two objects.
|
|
78
|
-
*
|
|
79
|
-
* mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
|
|
80
|
-
*
|
|
81
|
-
* @param base base object onto which `sources` will be applied
|
|
82
|
-
*/
|
|
83
|
-
const mergeDeep = (base, ...sources) => {
|
|
84
|
-
if (!sources.length)
|
|
85
|
-
return base;
|
|
86
|
-
const source = sources.shift();
|
|
87
|
-
if (isObject$1(base) && isObject$1(source)) {
|
|
88
|
-
for (const key in source) {
|
|
89
|
-
if (isObject$1(source[key])) {
|
|
90
|
-
if (!base[key])
|
|
91
|
-
Object.assign(base, { [key]: {} });
|
|
92
|
-
mergeDeep(base[key], source[key]);
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
Object.assign(base, { [key]: source[key] });
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return mergeDeep(base, ...sources);
|
|
100
|
-
};
|
|
18
|
+
/** @nocollapse */ NoopNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NoopNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
19
|
+
/** @nocollapse */ NoopNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NoopNgxsExecutionStrategy, providedIn: 'root' });
|
|
20
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NoopNgxsExecutionStrategy, decorators: [{
|
|
21
|
+
type: Injectable,
|
|
22
|
+
args: [{ providedIn: 'root' }]
|
|
23
|
+
}] });
|
|
101
24
|
|
|
102
25
|
function throwStateNameError(name) {
|
|
103
26
|
throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
|
|
@@ -167,9 +90,9 @@ class DispatchOutsideZoneNgxsExecutionStrategy {
|
|
|
167
90
|
return func();
|
|
168
91
|
}
|
|
169
92
|
}
|
|
170
|
-
/** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
171
|
-
/** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
172
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
93
|
+
/** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, deps: [{ token: i0.NgZone }, { token: PLATFORM_ID }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
94
|
+
/** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: 'root' });
|
|
95
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, decorators: [{
|
|
173
96
|
type: Injectable,
|
|
174
97
|
args: [{ providedIn: 'root' }]
|
|
175
98
|
}], ctorParameters: function () { return [{ type: i0.NgZone }, { type: undefined, decorators: [{
|
|
@@ -188,87 +111,22 @@ function verifyZoneIsNotNooped(ngZone) {
|
|
|
188
111
|
console.warn(getZoneWarningMessage());
|
|
189
112
|
}
|
|
190
113
|
|
|
191
|
-
const
|
|
192
|
-
const ROOT_STATE_TOKEN = new InjectionToken('ROOT_STATE_TOKEN');
|
|
193
|
-
const FEATURE_STATE_TOKEN = new InjectionToken('FEATURE_STATE_TOKEN');
|
|
194
|
-
const NGXS_PLUGINS = new InjectionToken('NGXS_PLUGINS');
|
|
195
|
-
const META_KEY = 'NGXS_META';
|
|
196
|
-
const META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
|
|
197
|
-
const SELECTOR_META_KEY = 'NGXS_SELECTOR_META';
|
|
198
|
-
/**
|
|
199
|
-
* The NGXS config settings.
|
|
200
|
-
*/
|
|
201
|
-
class NgxsConfig {
|
|
202
|
-
constructor() {
|
|
203
|
-
/**
|
|
204
|
-
* Defining the default state before module initialization
|
|
205
|
-
* This is convenient if we need to create a define our own set of states.
|
|
206
|
-
* @deprecated will be removed after v4
|
|
207
|
-
* (default: {})
|
|
208
|
-
*/
|
|
209
|
-
this.defaultsState = {};
|
|
210
|
-
/**
|
|
211
|
-
* Defining shared selector options
|
|
212
|
-
*/
|
|
213
|
-
this.selectorOptions = {
|
|
214
|
-
injectContainerState: true,
|
|
215
|
-
suppressErrors: true // TODO: default is true in v3, will change in v4
|
|
216
|
-
};
|
|
217
|
-
this.compatibility = {
|
|
218
|
-
strictContentSecurityPolicy: false
|
|
219
|
-
};
|
|
220
|
-
this.executionStrategy = DispatchOutsideZoneNgxsExecutionStrategy;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
/** @nocollapse */ NgxsConfig.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
224
|
-
/** @nocollapse */ NgxsConfig.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: (options) => mergeDeep(new NgxsConfig(), options), deps: [{ token: ROOT_OPTIONS }] });
|
|
225
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NgxsConfig, decorators: [{
|
|
226
|
-
type: Injectable,
|
|
227
|
-
args: [{
|
|
228
|
-
providedIn: 'root',
|
|
229
|
-
useFactory: (options) => mergeDeep(new NgxsConfig(), options),
|
|
230
|
-
deps: [ROOT_OPTIONS]
|
|
231
|
-
}]
|
|
232
|
-
}], ctorParameters: function () { return []; } });
|
|
114
|
+
const NG_DEV_MODE$3 = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
233
115
|
/**
|
|
234
|
-
*
|
|
235
|
-
*
|
|
116
|
+
* Consumers have the option to utilize the execution strategy provided by
|
|
117
|
+
* `NgxsModule.forRoot({executionStrategy})` or `provideStore([], {executionStrategy})`.
|
|
236
118
|
*/
|
|
237
|
-
|
|
238
|
-
constructor(previousValue, currentValue, firstChange) {
|
|
239
|
-
this.previousValue = previousValue;
|
|
240
|
-
this.currentValue = currentValue;
|
|
241
|
-
this.firstChange = firstChange;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
class NoopNgxsExecutionStrategy {
|
|
246
|
-
enter(func) {
|
|
247
|
-
return func();
|
|
248
|
-
}
|
|
249
|
-
leave(func) {
|
|
250
|
-
return func();
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
/** @nocollapse */ NoopNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NoopNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
254
|
-
/** @nocollapse */ NoopNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NoopNgxsExecutionStrategy, providedIn: 'root' });
|
|
255
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: NoopNgxsExecutionStrategy, decorators: [{
|
|
256
|
-
type: Injectable,
|
|
257
|
-
args: [{ providedIn: 'root' }]
|
|
258
|
-
}] });
|
|
259
|
-
|
|
119
|
+
const CUSTOM_NGXS_EXECUTION_STRATEGY = new InjectionToken(NG_DEV_MODE$3 ? 'CUSTOM_NGXS_EXECUTION_STRATEGY' : '');
|
|
260
120
|
/**
|
|
261
|
-
* The
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
/*
|
|
265
|
-
* Internal execution strategy injection token
|
|
121
|
+
* The injection token is used internally to resolve an instance of the execution
|
|
122
|
+
* strategy. It checks whether consumers have provided their own `executionStrategy`
|
|
123
|
+
* and also verifies if we are operating in a zone-aware environment.
|
|
266
124
|
*/
|
|
267
|
-
const NGXS_EXECUTION_STRATEGY = new InjectionToken('NGXS_EXECUTION_STRATEGY', {
|
|
125
|
+
const NGXS_EXECUTION_STRATEGY = new InjectionToken(NG_DEV_MODE$3 ? 'NGXS_EXECUTION_STRATEGY' : '', {
|
|
268
126
|
providedIn: 'root',
|
|
269
127
|
factory: () => {
|
|
270
128
|
const injector = inject(INJECTOR);
|
|
271
|
-
const executionStrategy = injector.get(
|
|
129
|
+
const executionStrategy = injector.get(CUSTOM_NGXS_EXECUTION_STRATEGY);
|
|
272
130
|
return executionStrategy
|
|
273
131
|
? injector.get(executionStrategy)
|
|
274
132
|
: injector.get(typeof ɵglobal.Zone !== 'undefined'
|
|
@@ -277,638 +135,449 @@ const NGXS_EXECUTION_STRATEGY = new InjectionToken('NGXS_EXECUTION_STRATEGY', {
|
|
|
277
135
|
}
|
|
278
136
|
});
|
|
279
137
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
actions: {},
|
|
290
|
-
defaults: {},
|
|
291
|
-
path: null,
|
|
292
|
-
makeRootSelector(context) {
|
|
293
|
-
return context.getStateGetter(defaultMetadata.name);
|
|
294
|
-
},
|
|
295
|
-
children: []
|
|
296
|
-
};
|
|
297
|
-
Object.defineProperty(target, META_KEY, { value: defaultMetadata });
|
|
138
|
+
class InternalNgxsExecutionStrategy {
|
|
139
|
+
constructor(_executionStrategy) {
|
|
140
|
+
this._executionStrategy = _executionStrategy;
|
|
141
|
+
}
|
|
142
|
+
enter(func) {
|
|
143
|
+
return this._executionStrategy.enter(func);
|
|
144
|
+
}
|
|
145
|
+
leave(func) {
|
|
146
|
+
return this._executionStrategy.leave(func);
|
|
298
147
|
}
|
|
299
|
-
return getStoreMetadata$1(target);
|
|
300
148
|
}
|
|
149
|
+
/** @nocollapse */ InternalNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [{ token: NGXS_EXECUTION_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
150
|
+
/** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' });
|
|
151
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
|
|
152
|
+
type: Injectable,
|
|
153
|
+
args: [{ providedIn: 'root' }]
|
|
154
|
+
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
155
|
+
type: Inject,
|
|
156
|
+
args: [NGXS_EXECUTION_STRATEGY]
|
|
157
|
+
}] }]; } });
|
|
158
|
+
|
|
301
159
|
/**
|
|
302
|
-
*
|
|
160
|
+
* Composes a array of functions from left to right. Example:
|
|
303
161
|
*
|
|
304
|
-
*
|
|
305
|
-
*/
|
|
306
|
-
function getStoreMetadata$1(target) {
|
|
307
|
-
return target[META_KEY];
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Ensures metadata is attached to the selector and returns it.
|
|
162
|
+
* compose([fn, final])(state, action);
|
|
311
163
|
*
|
|
312
|
-
*
|
|
313
|
-
*/
|
|
314
|
-
function ensureSelectorMetadata$1(target) {
|
|
315
|
-
if (!target.hasOwnProperty(SELECTOR_META_KEY)) {
|
|
316
|
-
const defaultMetadata = {
|
|
317
|
-
makeRootSelector: null,
|
|
318
|
-
originalFn: null,
|
|
319
|
-
containerClass: null,
|
|
320
|
-
selectorName: null,
|
|
321
|
-
getSelectorOptions: () => ({})
|
|
322
|
-
};
|
|
323
|
-
Object.defineProperty(target, SELECTOR_META_KEY, { value: defaultMetadata });
|
|
324
|
-
}
|
|
325
|
-
return getSelectorMetadata$1(target);
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* Get the metadata attached to the selector if it exists.
|
|
164
|
+
* then the funcs have a signature like:
|
|
329
165
|
*
|
|
330
|
-
*
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Get a deeply nested value. Example:
|
|
166
|
+
* function fn (state, action, next) {
|
|
167
|
+
* console.log('here', state, action, next);
|
|
168
|
+
* return next(state, action);
|
|
169
|
+
* }
|
|
337
170
|
*
|
|
338
|
-
*
|
|
171
|
+
* function final (state, action) {
|
|
172
|
+
* console.log('here', state, action);
|
|
173
|
+
* return state;
|
|
174
|
+
* }
|
|
339
175
|
*
|
|
340
|
-
*
|
|
341
|
-
* See perf hit: https://jsperf.com/fast-value-getter-given-path/1
|
|
176
|
+
* the last function should not call `next`.
|
|
342
177
|
*
|
|
343
178
|
* @ignore
|
|
344
179
|
*/
|
|
345
|
-
|
|
346
|
-
const
|
|
347
|
-
return
|
|
348
|
-
}
|
|
180
|
+
const compose = (funcs) => (...args) => {
|
|
181
|
+
const curr = funcs.shift();
|
|
182
|
+
return curr(...args, (...nextArgs) => compose(funcs)(...nextArgs));
|
|
183
|
+
};
|
|
184
|
+
|
|
349
185
|
/**
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
* - memoize
|
|
353
|
-
*
|
|
354
|
-
* @ignore
|
|
186
|
+
* Returns operator that will run
|
|
187
|
+
* `subscribe` outside of the ngxs execution context
|
|
355
188
|
*/
|
|
356
|
-
function
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
189
|
+
function leaveNgxs(ngxsExecutionStrategy) {
|
|
190
|
+
return (source) => {
|
|
191
|
+
return new Observable((sink) => {
|
|
192
|
+
return source.subscribe({
|
|
193
|
+
next(value) {
|
|
194
|
+
ngxsExecutionStrategy.leave(() => sink.next(value));
|
|
195
|
+
},
|
|
196
|
+
error(error) {
|
|
197
|
+
ngxsExecutionStrategy.leave(() => sink.error(error));
|
|
198
|
+
},
|
|
199
|
+
complete() {
|
|
200
|
+
ngxsExecutionStrategy.leave(() => sink.complete());
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
};
|
|
367
205
|
}
|
|
206
|
+
|
|
368
207
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
208
|
+
* This operator is used for piping the observable result
|
|
209
|
+
* from the `dispatch()`. It has a "smart" error handling
|
|
210
|
+
* strategy that allows us to decide whether we propagate
|
|
211
|
+
* errors to Angular's `ErrorHandler` or enable users to
|
|
212
|
+
* handle them manually. We consider following cases:
|
|
213
|
+
* 1) `store.dispatch()` (no subscribe) -> call `handleError()`
|
|
214
|
+
* 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
|
|
215
|
+
* 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
|
|
216
|
+
* 4) `toPromise()` without `catch` -> do `handleError()`
|
|
217
|
+
* 5) `toPromise()` with `catch` -> don't `handleError()`
|
|
374
218
|
*/
|
|
375
|
-
function
|
|
376
|
-
|
|
377
|
-
|
|
219
|
+
function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
|
|
220
|
+
return (source) => {
|
|
221
|
+
let subscribed = false;
|
|
222
|
+
source.subscribe({
|
|
223
|
+
error: error => {
|
|
224
|
+
// Do not trigger change detection for a microtask. This depends on the execution
|
|
225
|
+
// strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
|
|
226
|
+
// leaves the Angular zone.
|
|
227
|
+
ngxsExecutionStrategy.enter(() => Promise.resolve().then(() => {
|
|
228
|
+
if (!subscribed) {
|
|
229
|
+
ngxsExecutionStrategy.leave(() => internalErrorReporter.reportErrorSafely(error));
|
|
230
|
+
}
|
|
231
|
+
}));
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
return new Observable(subscriber => {
|
|
235
|
+
subscribed = true;
|
|
236
|
+
return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
class InternalErrorReporter {
|
|
241
|
+
constructor(_injector) {
|
|
242
|
+
this._injector = _injector;
|
|
243
|
+
/** Will be set lazily to be backward compatible. */
|
|
244
|
+
this._errorHandler = null;
|
|
378
245
|
}
|
|
379
|
-
|
|
380
|
-
|
|
246
|
+
reportErrorSafely(error) {
|
|
247
|
+
if (this._errorHandler === null) {
|
|
248
|
+
this._errorHandler = this._injector.get(ErrorHandler);
|
|
249
|
+
}
|
|
250
|
+
// The `try-catch` is used to avoid handling the error twice. Suppose we call
|
|
251
|
+
// `handleError` which re-throws the error internally. The re-thrown error will
|
|
252
|
+
// be caught by zone.js which will then get to the `zone.onError.emit()` and the
|
|
253
|
+
// `onError` subscriber will call `handleError` again.
|
|
254
|
+
try {
|
|
255
|
+
this._errorHandler.handleError(error);
|
|
256
|
+
}
|
|
257
|
+
catch { }
|
|
381
258
|
}
|
|
382
259
|
}
|
|
260
|
+
/** @nocollapse */ InternalErrorReporter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalErrorReporter, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
261
|
+
/** @nocollapse */ InternalErrorReporter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalErrorReporter, providedIn: 'root' });
|
|
262
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalErrorReporter, decorators: [{
|
|
263
|
+
type: Injectable,
|
|
264
|
+
args: [{ providedIn: 'root' }]
|
|
265
|
+
}], ctorParameters: function () { return [{ type: i0.Injector }]; } });
|
|
266
|
+
|
|
383
267
|
/**
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* ]
|
|
390
|
-
*
|
|
391
|
-
* would return:
|
|
392
|
-
*
|
|
393
|
-
* const graph = {
|
|
394
|
-
* cart: ['saved'],
|
|
395
|
-
* saved: ['items'],
|
|
396
|
-
* items: []
|
|
397
|
-
* };
|
|
268
|
+
* This wraps the provided function, and will enforce the following:
|
|
269
|
+
* - The calls will execute in the order that they are made
|
|
270
|
+
* - A call will only be initiated when the previous call has completed
|
|
271
|
+
* - If there is a call currently executing then the new call will be added
|
|
272
|
+
* to the queue and the function will return immediately
|
|
398
273
|
*
|
|
399
|
-
*
|
|
274
|
+
* NOTE: The following assumptions about the operation must hold true:
|
|
275
|
+
* - The operation is synchronous in nature
|
|
276
|
+
* - If any asynchronous side effects of the call exist, it should not
|
|
277
|
+
* have any bearing on the correctness of the next call in the queue
|
|
278
|
+
* - The operation has a void return
|
|
279
|
+
* - The caller should not assume that the call has completed upon
|
|
280
|
+
* return of the function
|
|
281
|
+
* - The caller can assume that all the queued calls will complete
|
|
282
|
+
* within the current microtask
|
|
283
|
+
* - The only way that a call will encounter another call in the queue
|
|
284
|
+
* would be if the call at the front of the queue initiated this call
|
|
285
|
+
* as part of its synchronous execution
|
|
400
286
|
*/
|
|
401
|
-
function
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
287
|
+
function orderedQueueOperation(operation) {
|
|
288
|
+
const callsQueue = [];
|
|
289
|
+
let busyPushingNext = false;
|
|
290
|
+
return function callOperation(...args) {
|
|
291
|
+
if (busyPushingNext) {
|
|
292
|
+
callsQueue.unshift(args);
|
|
293
|
+
return;
|
|
408
294
|
}
|
|
409
|
-
|
|
295
|
+
busyPushingNext = true;
|
|
296
|
+
operation(...args);
|
|
297
|
+
while (callsQueue.length > 0) {
|
|
298
|
+
const nextCallArgs = callsQueue.pop();
|
|
299
|
+
nextCallArgs && operation(...nextCallArgs);
|
|
300
|
+
}
|
|
301
|
+
busyPushingNext = false;
|
|
410
302
|
};
|
|
411
|
-
return stateClasses.reduce((result, stateClass) => {
|
|
412
|
-
const { name, children } = stateClass[META_KEY];
|
|
413
|
-
result[name] = (children || []).map(findName);
|
|
414
|
-
return result;
|
|
415
|
-
}, {});
|
|
416
303
|
}
|
|
417
304
|
/**
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
305
|
+
* Custom Subject that ensures that subscribers are notified of values in the order that they arrived.
|
|
306
|
+
* A standard Subject does not have this guarantee.
|
|
307
|
+
* For example, given the following code:
|
|
308
|
+
* ```typescript
|
|
309
|
+
* const subject = new Subject<string>();
|
|
310
|
+
subject.subscribe(value => {
|
|
311
|
+
if (value === 'start') subject.next('end');
|
|
312
|
+
});
|
|
313
|
+
subject.subscribe(value => { });
|
|
314
|
+
subject.next('start');
|
|
315
|
+
* ```
|
|
316
|
+
* When `subject` is a standard `Subject<T>` the second subscriber would recieve `end` and then `start`.
|
|
317
|
+
* When `subject` is a `OrderedSubject<T>` the second subscriber would recieve `start` and then `end`.
|
|
426
318
|
*/
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
319
|
+
class OrderedSubject extends Subject {
|
|
320
|
+
constructor() {
|
|
321
|
+
super(...arguments);
|
|
322
|
+
this._orderedNext = orderedQueueOperation((value) => super.next(value));
|
|
323
|
+
}
|
|
324
|
+
next(value) {
|
|
325
|
+
this._orderedNext(value);
|
|
326
|
+
}
|
|
433
327
|
}
|
|
434
328
|
/**
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
*
|
|
448
|
-
* saved: 'cart.saved',
|
|
449
|
-
* items: 'cart.saved.items'
|
|
450
|
-
* };
|
|
451
|
-
*
|
|
452
|
-
* @ignore
|
|
329
|
+
* Custom BehaviorSubject that ensures that subscribers are notified of values in the order that they arrived.
|
|
330
|
+
* A standard BehaviorSubject does not have this guarantee.
|
|
331
|
+
* For example, given the following code:
|
|
332
|
+
* ```typescript
|
|
333
|
+
* const subject = new BehaviorSubject<string>();
|
|
334
|
+
subject.subscribe(value => {
|
|
335
|
+
if (value === 'start') subject.next('end');
|
|
336
|
+
});
|
|
337
|
+
subject.subscribe(value => { });
|
|
338
|
+
subject.next('start');
|
|
339
|
+
* ```
|
|
340
|
+
* When `subject` is a standard `BehaviorSubject<T>` the second subscriber would recieve `end` and then `start`.
|
|
341
|
+
* When `subject` is a `OrderedBehaviorSubject<T>` the second subscriber would recieve `start` and then `end`.
|
|
453
342
|
*/
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
const parent = visit(obj, key);
|
|
467
|
-
newObj[key] = parent ? `${parent}.${key}` : key;
|
|
468
|
-
}
|
|
343
|
+
class OrderedBehaviorSubject extends BehaviorSubject {
|
|
344
|
+
constructor(value) {
|
|
345
|
+
super(value);
|
|
346
|
+
this._orderedNext = orderedQueueOperation((value) => super.next(value));
|
|
347
|
+
this._currentValue = value;
|
|
348
|
+
}
|
|
349
|
+
getValue() {
|
|
350
|
+
return this._currentValue;
|
|
351
|
+
}
|
|
352
|
+
next(value) {
|
|
353
|
+
this._currentValue = value;
|
|
354
|
+
this._orderedNext(value);
|
|
469
355
|
}
|
|
470
|
-
return newObj;
|
|
471
356
|
}
|
|
357
|
+
|
|
472
358
|
/**
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
* const graph = {
|
|
476
|
-
* cart: ['saved'],
|
|
477
|
-
* saved: ['items'],
|
|
478
|
-
* items: []
|
|
479
|
-
* };
|
|
480
|
-
*
|
|
481
|
-
* would return:
|
|
482
|
-
*
|
|
483
|
-
* const results = [
|
|
484
|
-
* 'items',
|
|
485
|
-
* 'saved',
|
|
486
|
-
* 'cart'
|
|
487
|
-
* ];
|
|
488
|
-
*
|
|
489
|
-
* @ignore
|
|
359
|
+
* Internal Action stream that is emitted anytime an action is dispatched.
|
|
490
360
|
*/
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
if (!Array.isArray(ancestors)) {
|
|
496
|
-
ancestors = [];
|
|
497
|
-
}
|
|
498
|
-
ancestors.push(name);
|
|
499
|
-
visited[name] = true;
|
|
500
|
-
graph[name].forEach((dep) => {
|
|
501
|
-
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
502
|
-
// creating a breaking change for projects that still use the View Engine.
|
|
503
|
-
if ((typeof ngDevMode === 'undefined' || ngDevMode) && ancestors.indexOf(dep) >= 0) {
|
|
504
|
-
throw new Error(`Circular dependency '${dep}' is required by '${name}': ${ancestors.join(' -> ')}`);
|
|
505
|
-
}
|
|
506
|
-
if (visited[dep]) {
|
|
507
|
-
return;
|
|
508
|
-
}
|
|
509
|
-
visit(dep, ancestors.slice(0));
|
|
510
|
-
});
|
|
511
|
-
if (sorted.indexOf(name) < 0) {
|
|
512
|
-
sorted.push(name);
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
Object.keys(graph).forEach(k => visit(k));
|
|
516
|
-
return sorted.reverse();
|
|
361
|
+
class InternalActions extends OrderedSubject {
|
|
362
|
+
ngOnDestroy() {
|
|
363
|
+
this.complete();
|
|
364
|
+
}
|
|
517
365
|
}
|
|
366
|
+
/** @nocollapse */ InternalActions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalActions, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
367
|
+
/** @nocollapse */ InternalActions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalActions, providedIn: 'root' });
|
|
368
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalActions, decorators: [{
|
|
369
|
+
type: Injectable,
|
|
370
|
+
args: [{ providedIn: 'root' }]
|
|
371
|
+
}] });
|
|
518
372
|
/**
|
|
519
|
-
*
|
|
373
|
+
* Action stream that is emitted anytime an action is dispatched.
|
|
520
374
|
*
|
|
375
|
+
* You can listen to this in services to react without stores.
|
|
376
|
+
*/
|
|
377
|
+
class Actions extends Observable {
|
|
378
|
+
constructor(internalActions$, internalExecutionStrategy) {
|
|
379
|
+
const sharedInternalActions$ = internalActions$.pipe(leaveNgxs(internalExecutionStrategy),
|
|
380
|
+
// The `InternalActions` subject emits outside of the Angular zone.
|
|
381
|
+
// We have to re-enter the Angular zone for any incoming consumer.
|
|
382
|
+
// The `share()` operator reduces the number of change detections.
|
|
383
|
+
// This would call leave only once for any stream emission across all active subscribers.
|
|
384
|
+
share());
|
|
385
|
+
super(observer => {
|
|
386
|
+
const childSubscription = sharedInternalActions$.subscribe({
|
|
387
|
+
next: ctx => observer.next(ctx),
|
|
388
|
+
error: error => observer.error(error),
|
|
389
|
+
complete: () => observer.complete()
|
|
390
|
+
});
|
|
391
|
+
observer.add(childSubscription);
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
/** @nocollapse */ Actions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Actions, deps: [{ token: InternalActions }, { token: InternalNgxsExecutionStrategy }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
396
|
+
/** @nocollapse */ Actions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Actions, providedIn: 'root' });
|
|
397
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Actions, decorators: [{
|
|
398
|
+
type: Injectable,
|
|
399
|
+
args: [{ providedIn: 'root' }]
|
|
400
|
+
}], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalNgxsExecutionStrategy }]; } });
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* BehaviorSubject of the entire state.
|
|
521
404
|
* @ignore
|
|
522
405
|
*/
|
|
523
|
-
|
|
524
|
-
|
|
406
|
+
class StateStream extends OrderedBehaviorSubject {
|
|
407
|
+
constructor() {
|
|
408
|
+
super({});
|
|
409
|
+
}
|
|
410
|
+
ngOnDestroy() {
|
|
411
|
+
// The StateStream should never emit values once the root view is removed,
|
|
412
|
+
// such as when the `NgModuleRef.destroy()` method is called. This is crucial
|
|
413
|
+
// for preventing memory leaks in server-side rendered apps, where a new StateStream
|
|
414
|
+
// is created for each HTTP request. If users forget to unsubscribe from `store.select`
|
|
415
|
+
// or `store.subscribe`, it can result in significant memory leaks in SSR apps.
|
|
416
|
+
this.complete();
|
|
417
|
+
}
|
|
525
418
|
}
|
|
419
|
+
/** @nocollapse */ StateStream.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateStream, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
420
|
+
/** @nocollapse */ StateStream.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateStream, providedIn: 'root' });
|
|
421
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateStream, decorators: [{
|
|
422
|
+
type: Injectable,
|
|
423
|
+
args: [{ providedIn: 'root' }]
|
|
424
|
+
}], ctorParameters: function () { return []; } });
|
|
526
425
|
|
|
527
426
|
/**
|
|
528
|
-
*
|
|
529
|
-
*
|
|
530
|
-
* This will grab actions that have just been dispatched as well as actions that have completed
|
|
427
|
+
* Returns the type from an action instance/class.
|
|
428
|
+
* @ignore
|
|
531
429
|
*/
|
|
532
|
-
function
|
|
533
|
-
|
|
430
|
+
function getActionTypeFromInstance(action) {
|
|
431
|
+
if (action.constructor && action.constructor.type) {
|
|
432
|
+
return action.constructor.type;
|
|
433
|
+
}
|
|
434
|
+
else {
|
|
435
|
+
return action.type;
|
|
436
|
+
}
|
|
534
437
|
}
|
|
535
438
|
/**
|
|
536
|
-
*
|
|
537
|
-
*
|
|
538
|
-
* This will ONLY grab actions that have just been dispatched
|
|
439
|
+
* Matches a action
|
|
440
|
+
* @ignore
|
|
539
441
|
*/
|
|
540
|
-
function
|
|
541
|
-
|
|
442
|
+
function actionMatcher(action1) {
|
|
443
|
+
const type1 = getActionTypeFromInstance(action1);
|
|
444
|
+
return function (action2) {
|
|
445
|
+
return type1 === getActionTypeFromInstance(action2);
|
|
446
|
+
};
|
|
542
447
|
}
|
|
543
448
|
/**
|
|
544
|
-
*
|
|
449
|
+
* Set a deeply nested value. Example:
|
|
545
450
|
*
|
|
546
|
-
*
|
|
451
|
+
* setValue({ foo: { bar: { eat: false } } },
|
|
452
|
+
* 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
|
|
453
|
+
*
|
|
454
|
+
* While it traverses it also creates new objects from top down.
|
|
455
|
+
*
|
|
456
|
+
* @ignore
|
|
547
457
|
*/
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
458
|
+
const setValue = (obj, prop, val) => {
|
|
459
|
+
obj = { ...obj };
|
|
460
|
+
const split = prop.split('.');
|
|
461
|
+
const lastIndex = split.length - 1;
|
|
462
|
+
split.reduce((acc, part, index) => {
|
|
463
|
+
if (index === lastIndex) {
|
|
464
|
+
acc[part] = val;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : { ...acc[part] };
|
|
468
|
+
}
|
|
469
|
+
return acc && acc[part];
|
|
470
|
+
}, obj);
|
|
471
|
+
return obj;
|
|
472
|
+
};
|
|
551
473
|
/**
|
|
552
|
-
*
|
|
474
|
+
* Get a deeply nested value. Example:
|
|
553
475
|
*
|
|
554
|
-
*
|
|
476
|
+
* getValue({ foo: bar: [] }, 'foo.bar') //=> []
|
|
477
|
+
*
|
|
478
|
+
* @ignore
|
|
555
479
|
*/
|
|
556
|
-
|
|
557
|
-
return ofActionOperator(allowedTypes, ["CANCELED" /* Canceled */]);
|
|
558
|
-
}
|
|
480
|
+
const getValue = (obj, prop) => prop.split('.').reduce((acc, part) => acc && acc[part], obj);
|
|
559
481
|
/**
|
|
560
|
-
*
|
|
482
|
+
* Simple object check.
|
|
561
483
|
*
|
|
562
|
-
*
|
|
484
|
+
* isObject({a:1}) //=> true
|
|
485
|
+
* isObject(1) //=> false
|
|
486
|
+
*
|
|
487
|
+
* @ignore
|
|
563
488
|
*/
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
"CANCELED" /* Canceled */,
|
|
568
|
-
"ERRORED" /* Errored */
|
|
569
|
-
];
|
|
570
|
-
return ofActionOperator(allowedTypes, allowedStatuses, mapActionResult);
|
|
571
|
-
}
|
|
489
|
+
const isObject$1 = (item) => {
|
|
490
|
+
return item && typeof item === 'object' && !Array.isArray(item);
|
|
491
|
+
};
|
|
572
492
|
/**
|
|
573
|
-
*
|
|
493
|
+
* Deep merge two objects.
|
|
574
494
|
*
|
|
575
|
-
*
|
|
495
|
+
* mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
|
|
496
|
+
*
|
|
497
|
+
* @param base base object onto which `sources` will be applied
|
|
576
498
|
*/
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
return function (o) {
|
|
588
|
-
return o.pipe(filterStatus(allowedMap, allowedStatusMap), mapOperator());
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
function filterStatus(allowedTypes, allowedStatuses) {
|
|
592
|
-
return filter((ctx) => {
|
|
593
|
-
const actionType = getActionTypeFromInstance(ctx.action);
|
|
594
|
-
const typeMatch = allowedTypes[actionType];
|
|
595
|
-
const statusMatch = allowedStatuses ? allowedStatuses[ctx.status] : true;
|
|
596
|
-
return typeMatch && statusMatch;
|
|
597
|
-
});
|
|
598
|
-
}
|
|
599
|
-
function mapActionResult() {
|
|
600
|
-
return map(({ action, status, error }) => {
|
|
601
|
-
return {
|
|
602
|
-
action,
|
|
603
|
-
result: {
|
|
604
|
-
successful: "SUCCESSFUL" /* Successful */ === status,
|
|
605
|
-
canceled: "CANCELED" /* Canceled */ === status,
|
|
606
|
-
error
|
|
499
|
+
const mergeDeep = (base, ...sources) => {
|
|
500
|
+
if (!sources.length)
|
|
501
|
+
return base;
|
|
502
|
+
const source = sources.shift();
|
|
503
|
+
if (isObject$1(base) && isObject$1(source)) {
|
|
504
|
+
for (const key in source) {
|
|
505
|
+
if (isObject$1(source[key])) {
|
|
506
|
+
if (!base[key])
|
|
507
|
+
Object.assign(base, { [key]: {} });
|
|
508
|
+
mergeDeep(base[key], source[key]);
|
|
607
509
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
return types.reduce((filterMap, klass) => {
|
|
616
|
-
filterMap[getActionTypeFromInstance(klass)] = true;
|
|
617
|
-
return filterMap;
|
|
618
|
-
}, {});
|
|
619
|
-
}
|
|
620
|
-
function createAllowedStatusesMap(statuses) {
|
|
621
|
-
return statuses.reduce((filterMap, status) => {
|
|
622
|
-
filterMap[status] = true;
|
|
623
|
-
return filterMap;
|
|
624
|
-
}, {});
|
|
625
|
-
}
|
|
510
|
+
else {
|
|
511
|
+
Object.assign(base, { [key]: source[key] });
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return mergeDeep(base, ...sources);
|
|
516
|
+
};
|
|
626
517
|
|
|
518
|
+
const NG_DEV_MODE$2 = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
519
|
+
// The injection token is used to resolve a list of states provided at
|
|
520
|
+
// the root level through either `NgxsModule.forRoot` or `provideStore`.
|
|
521
|
+
const ROOT_STATE_TOKEN = new InjectionToken(NG_DEV_MODE$2 ? 'ROOT_STATE_TOKEN' : '');
|
|
522
|
+
// The injection token is used to resolve a list of states provided at
|
|
523
|
+
// the feature level through either `NgxsModule.forFeature` or `provideStates`.
|
|
524
|
+
// The Array<Array> is used to overload the resolved value of the token because
|
|
525
|
+
// it is a multi-provider token.
|
|
526
|
+
const FEATURE_STATE_TOKEN = new InjectionToken(NG_DEV_MODE$2 ? 'FEATURE_STATE_TOKEN' : '');
|
|
527
|
+
// The injection token is used to resolve to custom NGXS plugins provided
|
|
528
|
+
// at the root level through either `{provide}` scheme or `withNgxsPlugin`.
|
|
529
|
+
const NGXS_PLUGINS = new InjectionToken(NG_DEV_MODE$2 ? 'NGXS_PLUGINS' : '');
|
|
530
|
+
// The injection token is used to resolve to options provided at the root
|
|
531
|
+
// level through either `NgxsModule.forRoot` or `provideStore`.
|
|
532
|
+
const NGXS_OPTIONS = new InjectionToken(NG_DEV_MODE$2 ? 'NGXS_OPTIONS' : '');
|
|
533
|
+
const META_KEY = 'NGXS_META';
|
|
534
|
+
const META_OPTIONS_KEY = 'NGXS_OPTIONS_META';
|
|
535
|
+
const SELECTOR_META_KEY = 'NGXS_SELECTOR_META';
|
|
627
536
|
/**
|
|
628
|
-
*
|
|
629
|
-
* `subscribe` outside of the ngxs execution context
|
|
537
|
+
* The NGXS config settings.
|
|
630
538
|
*/
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
539
|
+
class NgxsConfig {
|
|
540
|
+
constructor() {
|
|
541
|
+
/**
|
|
542
|
+
* Defining the default state before module initialization
|
|
543
|
+
* This is convenient if we need to create a define our own set of states.
|
|
544
|
+
* @deprecated will be removed after v4
|
|
545
|
+
* (default: {})
|
|
546
|
+
*/
|
|
547
|
+
this.defaultsState = {};
|
|
548
|
+
/**
|
|
549
|
+
* Defining shared selector options
|
|
550
|
+
*/
|
|
551
|
+
this.selectorOptions = {
|
|
552
|
+
injectContainerState: true,
|
|
553
|
+
suppressErrors: true // TODO: default is true in v3, will change in v4
|
|
554
|
+
};
|
|
555
|
+
this.compatibility = {
|
|
556
|
+
strictContentSecurityPolicy: false
|
|
557
|
+
};
|
|
558
|
+
this.executionStrategy = DispatchOutsideZoneNgxsExecutionStrategy;
|
|
559
|
+
}
|
|
647
560
|
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
this._executionStrategy = _executionStrategy;
|
|
652
|
-
}
|
|
653
|
-
enter(func) {
|
|
654
|
-
return this._executionStrategy.enter(func);
|
|
655
|
-
}
|
|
656
|
-
leave(func) {
|
|
657
|
-
return this._executionStrategy.leave(func);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
/** @nocollapse */ InternalNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, deps: [{ token: NGXS_EXECUTION_STRATEGY }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
661
|
-
/** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' });
|
|
662
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
|
|
663
|
-
type: Injectable,
|
|
664
|
-
args: [{ providedIn: 'root' }]
|
|
665
|
-
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
666
|
-
type: Inject,
|
|
667
|
-
args: [NGXS_EXECUTION_STRATEGY]
|
|
668
|
-
}] }]; } });
|
|
669
|
-
|
|
670
|
-
/**
|
|
671
|
-
* This wraps the provided function, and will enforce the following:
|
|
672
|
-
* - The calls will execute in the order that they are made
|
|
673
|
-
* - A call will only be initiated when the previous call has completed
|
|
674
|
-
* - If there is a call currently executing then the new call will be added
|
|
675
|
-
* to the queue and the function will return immediately
|
|
676
|
-
*
|
|
677
|
-
* NOTE: The following assumptions about the operation must hold true:
|
|
678
|
-
* - The operation is synchronous in nature
|
|
679
|
-
* - If any asynchronous side effects of the call exist, it should not
|
|
680
|
-
* have any bearing on the correctness of the next call in the queue
|
|
681
|
-
* - The operation has a void return
|
|
682
|
-
* - The caller should not assume that the call has completed upon
|
|
683
|
-
* return of the function
|
|
684
|
-
* - The caller can assume that all the queued calls will complete
|
|
685
|
-
* within the current microtask
|
|
686
|
-
* - The only way that a call will encounter another call in the queue
|
|
687
|
-
* would be if the call at the front of the queue initiated this call
|
|
688
|
-
* as part of its synchronous execution
|
|
689
|
-
*/
|
|
690
|
-
function orderedQueueOperation(operation) {
|
|
691
|
-
const callsQueue = [];
|
|
692
|
-
let busyPushingNext = false;
|
|
693
|
-
return function callOperation(...args) {
|
|
694
|
-
if (busyPushingNext) {
|
|
695
|
-
callsQueue.unshift(args);
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
busyPushingNext = true;
|
|
699
|
-
operation(...args);
|
|
700
|
-
while (callsQueue.length > 0) {
|
|
701
|
-
const nextCallArgs = callsQueue.pop();
|
|
702
|
-
nextCallArgs && operation(...nextCallArgs);
|
|
703
|
-
}
|
|
704
|
-
busyPushingNext = false;
|
|
705
|
-
};
|
|
706
|
-
}
|
|
707
|
-
/**
|
|
708
|
-
* Custom Subject that ensures that subscribers are notified of values in the order that they arrived.
|
|
709
|
-
* A standard Subject does not have this guarantee.
|
|
710
|
-
* For example, given the following code:
|
|
711
|
-
* ```typescript
|
|
712
|
-
* const subject = new Subject<string>();
|
|
713
|
-
subject.subscribe(value => {
|
|
714
|
-
if (value === 'start') subject.next('end');
|
|
715
|
-
});
|
|
716
|
-
subject.subscribe(value => { });
|
|
717
|
-
subject.next('start');
|
|
718
|
-
* ```
|
|
719
|
-
* When `subject` is a standard `Subject<T>` the second subscriber would recieve `end` and then `start`.
|
|
720
|
-
* When `subject` is a `OrderedSubject<T>` the second subscriber would recieve `start` and then `end`.
|
|
721
|
-
*/
|
|
722
|
-
class OrderedSubject extends Subject {
|
|
723
|
-
constructor() {
|
|
724
|
-
super(...arguments);
|
|
725
|
-
this._orderedNext = orderedQueueOperation((value) => super.next(value));
|
|
726
|
-
}
|
|
727
|
-
next(value) {
|
|
728
|
-
this._orderedNext(value);
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
/**
|
|
732
|
-
* Custom BehaviorSubject that ensures that subscribers are notified of values in the order that they arrived.
|
|
733
|
-
* A standard BehaviorSubject does not have this guarantee.
|
|
734
|
-
* For example, given the following code:
|
|
735
|
-
* ```typescript
|
|
736
|
-
* const subject = new BehaviorSubject<string>();
|
|
737
|
-
subject.subscribe(value => {
|
|
738
|
-
if (value === 'start') subject.next('end');
|
|
739
|
-
});
|
|
740
|
-
subject.subscribe(value => { });
|
|
741
|
-
subject.next('start');
|
|
742
|
-
* ```
|
|
743
|
-
* When `subject` is a standard `BehaviorSubject<T>` the second subscriber would recieve `end` and then `start`.
|
|
744
|
-
* When `subject` is a `OrderedBehaviorSubject<T>` the second subscriber would recieve `start` and then `end`.
|
|
745
|
-
*/
|
|
746
|
-
class OrderedBehaviorSubject extends BehaviorSubject {
|
|
747
|
-
constructor(value) {
|
|
748
|
-
super(value);
|
|
749
|
-
this._orderedNext = orderedQueueOperation((value) => super.next(value));
|
|
750
|
-
this._currentValue = value;
|
|
751
|
-
}
|
|
752
|
-
getValue() {
|
|
753
|
-
return this._currentValue;
|
|
754
|
-
}
|
|
755
|
-
next(value) {
|
|
756
|
-
this._currentValue = value;
|
|
757
|
-
this._orderedNext(value);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
/**
|
|
762
|
-
* Internal Action stream that is emitted anytime an action is dispatched.
|
|
763
|
-
*/
|
|
764
|
-
class InternalActions extends OrderedSubject {
|
|
765
|
-
ngOnDestroy() {
|
|
766
|
-
this.complete();
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
/** @nocollapse */ InternalActions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
770
|
-
/** @nocollapse */ InternalActions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, providedIn: 'root' });
|
|
771
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalActions, decorators: [{
|
|
772
|
-
type: Injectable,
|
|
773
|
-
args: [{ providedIn: 'root' }]
|
|
774
|
-
}] });
|
|
775
|
-
/**
|
|
776
|
-
* Action stream that is emitted anytime an action is dispatched.
|
|
777
|
-
*
|
|
778
|
-
* You can listen to this in services to react without stores.
|
|
779
|
-
*/
|
|
780
|
-
class Actions extends Observable {
|
|
781
|
-
constructor(internalActions$, internalExecutionStrategy) {
|
|
782
|
-
const sharedInternalActions$ = internalActions$.pipe(leaveNgxs(internalExecutionStrategy),
|
|
783
|
-
// The `InternalActions` subject emits outside of the Angular zone.
|
|
784
|
-
// We have to re-enter the Angular zone for any incoming consumer.
|
|
785
|
-
// The `share()` operator reduces the number of change detections.
|
|
786
|
-
// This would call leave only once for any stream emission across all active subscribers.
|
|
787
|
-
share());
|
|
788
|
-
super(observer => {
|
|
789
|
-
const childSubscription = sharedInternalActions$.subscribe({
|
|
790
|
-
next: ctx => observer.next(ctx),
|
|
791
|
-
error: error => observer.error(error),
|
|
792
|
-
complete: () => observer.complete()
|
|
793
|
-
});
|
|
794
|
-
observer.add(childSubscription);
|
|
795
|
-
});
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
/** @nocollapse */ Actions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, deps: [{ token: InternalActions }, { token: InternalNgxsExecutionStrategy }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
799
|
-
/** @nocollapse */ Actions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, providedIn: 'root' });
|
|
800
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: Actions, decorators: [{
|
|
801
|
-
type: Injectable,
|
|
802
|
-
args: [{ providedIn: 'root' }]
|
|
803
|
-
}], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalNgxsExecutionStrategy }]; } });
|
|
804
|
-
|
|
805
|
-
/**
|
|
806
|
-
* Composes a array of functions from left to right. Example:
|
|
807
|
-
*
|
|
808
|
-
* compose([fn, final])(state, action);
|
|
809
|
-
*
|
|
810
|
-
* then the funcs have a signature like:
|
|
811
|
-
*
|
|
812
|
-
* function fn (state, action, next) {
|
|
813
|
-
* console.log('here', state, action, next);
|
|
814
|
-
* return next(state, action);
|
|
815
|
-
* }
|
|
816
|
-
*
|
|
817
|
-
* function final (state, action) {
|
|
818
|
-
* console.log('here', state, action);
|
|
819
|
-
* return state;
|
|
820
|
-
* }
|
|
821
|
-
*
|
|
822
|
-
* the last function should not call `next`.
|
|
823
|
-
*
|
|
824
|
-
* @ignore
|
|
825
|
-
*/
|
|
826
|
-
const compose = (funcs) => (...args) => {
|
|
827
|
-
const curr = funcs.shift();
|
|
828
|
-
return curr(...args, (...nextArgs) => compose(funcs)(...nextArgs));
|
|
829
|
-
};
|
|
830
|
-
|
|
831
|
-
/**
|
|
832
|
-
* This operator is used for piping the observable result
|
|
833
|
-
* from the `dispatch()`. It has a "smart" error handling
|
|
834
|
-
* strategy that allows us to decide whether we propagate
|
|
835
|
-
* errors to Angular's `ErrorHandler` or enable users to
|
|
836
|
-
* handle them manually. We consider following cases:
|
|
837
|
-
* 1) `store.dispatch()` (no subscribe) -> call `handleError()`
|
|
838
|
-
* 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
|
|
839
|
-
* 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
|
|
840
|
-
* 4) `toPromise()` without `catch` -> do `handleError()`
|
|
841
|
-
* 5) `toPromise()` with `catch` -> don't `handleError()`
|
|
842
|
-
*/
|
|
843
|
-
function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
|
|
844
|
-
return (source) => {
|
|
845
|
-
let subscribed = false;
|
|
846
|
-
source.subscribe({
|
|
847
|
-
error: error => {
|
|
848
|
-
// Do not trigger change detection for a microtask. This depends on the execution
|
|
849
|
-
// strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
|
|
850
|
-
// leaves the Angular zone.
|
|
851
|
-
ngxsExecutionStrategy.enter(() => Promise.resolve().then(() => {
|
|
852
|
-
if (!subscribed) {
|
|
853
|
-
ngxsExecutionStrategy.leave(() => internalErrorReporter.reportErrorSafely(error));
|
|
854
|
-
}
|
|
855
|
-
}));
|
|
856
|
-
}
|
|
857
|
-
});
|
|
858
|
-
return new Observable(subscriber => {
|
|
859
|
-
subscribed = true;
|
|
860
|
-
return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
|
|
861
|
-
});
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
class InternalErrorReporter {
|
|
865
|
-
constructor(_injector) {
|
|
866
|
-
this._injector = _injector;
|
|
867
|
-
/** Will be set lazily to be backward compatible. */
|
|
868
|
-
this._errorHandler = null;
|
|
869
|
-
}
|
|
870
|
-
reportErrorSafely(error) {
|
|
871
|
-
if (this._errorHandler === null) {
|
|
872
|
-
this._errorHandler = this._injector.get(ErrorHandler);
|
|
873
|
-
}
|
|
874
|
-
// The `try-catch` is used to avoid handling the error twice. Suppose we call
|
|
875
|
-
// `handleError` which re-throws the error internally. The re-thrown error will
|
|
876
|
-
// be caught by zone.js which will then get to the `zone.onError.emit()` and the
|
|
877
|
-
// `onError` subscriber will call `handleError` again.
|
|
878
|
-
try {
|
|
879
|
-
this._errorHandler.handleError(error);
|
|
880
|
-
}
|
|
881
|
-
catch (_a) { }
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
/** @nocollapse */ InternalErrorReporter.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalErrorReporter, deps: [{ token: i0.Injector }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
885
|
-
/** @nocollapse */ InternalErrorReporter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalErrorReporter, providedIn: 'root' });
|
|
886
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: InternalErrorReporter, decorators: [{
|
|
561
|
+
/** @nocollapse */ NgxsConfig.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
562
|
+
/** @nocollapse */ NgxsConfig.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsConfig, providedIn: 'root', useFactory: () => mergeDeep(new NgxsConfig(), inject(NGXS_OPTIONS)) });
|
|
563
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsConfig, decorators: [{
|
|
887
564
|
type: Injectable,
|
|
888
|
-
args: [{
|
|
889
|
-
|
|
890
|
-
|
|
565
|
+
args: [{
|
|
566
|
+
providedIn: 'root',
|
|
567
|
+
useFactory: () => mergeDeep(new NgxsConfig(), inject(NGXS_OPTIONS))
|
|
568
|
+
}]
|
|
569
|
+
}], ctorParameters: function () { return []; } });
|
|
891
570
|
/**
|
|
892
|
-
*
|
|
893
|
-
*
|
|
571
|
+
* Represents a basic change from a previous to a new value for a single state instance.
|
|
572
|
+
* Passed as a value in a NgxsSimpleChanges object to the ngxsOnChanges hook.
|
|
894
573
|
*/
|
|
895
|
-
class
|
|
896
|
-
constructor() {
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
// The `StateStream` should never emit values once the root view is removed, e.g. when the `NgModuleRef.destroy()` is called.
|
|
901
|
-
// This will eliminate memory leaks in server-side rendered apps where the `StateStream` is created per each HTTP request, users
|
|
902
|
-
// might forget to unsubscribe from `store.select` or `store.subscribe`, thus this will lead to huge memory leaks in SSR apps.
|
|
903
|
-
this.complete();
|
|
574
|
+
class NgxsSimpleChange {
|
|
575
|
+
constructor(previousValue, currentValue, firstChange) {
|
|
576
|
+
this.previousValue = previousValue;
|
|
577
|
+
this.currentValue = currentValue;
|
|
578
|
+
this.firstChange = firstChange;
|
|
904
579
|
}
|
|
905
580
|
}
|
|
906
|
-
/** @nocollapse */ StateStream.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
907
|
-
/** @nocollapse */ StateStream.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, providedIn: 'root' });
|
|
908
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImport: i0, type: StateStream, decorators: [{
|
|
909
|
-
type: Injectable,
|
|
910
|
-
args: [{ providedIn: 'root' }]
|
|
911
|
-
}], ctorParameters: function () { return []; } });
|
|
912
581
|
|
|
913
582
|
class PluginManager {
|
|
914
583
|
constructor(_parentManager, _pluginHandlers) {
|
|
@@ -929,9 +598,9 @@ class PluginManager {
|
|
|
929
598
|
return handlers.map((plugin) => (plugin.handle ? plugin.handle.bind(plugin) : plugin));
|
|
930
599
|
}
|
|
931
600
|
}
|
|
932
|
-
/** @nocollapse */ PluginManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
933
|
-
/** @nocollapse */ PluginManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
934
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
601
|
+
/** @nocollapse */ PluginManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: PluginManager, deps: [{ token: PluginManager, optional: true, skipSelf: true }, { token: NGXS_PLUGINS, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
602
|
+
/** @nocollapse */ PluginManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: PluginManager });
|
|
603
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: PluginManager, decorators: [{
|
|
935
604
|
type: Injectable
|
|
936
605
|
}], ctorParameters: function () { return [{ type: PluginManager, decorators: [{
|
|
937
606
|
type: Optional
|
|
@@ -952,9 +621,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
|
|
|
952
621
|
*/
|
|
953
622
|
class InternalDispatchedActionResults extends Subject {
|
|
954
623
|
}
|
|
955
|
-
/** @nocollapse */ InternalDispatchedActionResults.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
956
|
-
/** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
957
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
624
|
+
/** @nocollapse */ InternalDispatchedActionResults.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatchedActionResults, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
625
|
+
/** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatchedActionResults, providedIn: 'root' });
|
|
626
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatchedActionResults, decorators: [{
|
|
958
627
|
type: Injectable,
|
|
959
628
|
args: [{ providedIn: 'root' }]
|
|
960
629
|
}] });
|
|
@@ -1002,21 +671,21 @@ class InternalDispatcher {
|
|
|
1002
671
|
}
|
|
1003
672
|
const actionResult$ = this.getActionResultStream(nextAction);
|
|
1004
673
|
actionResult$.subscribe(ctx => this._actions.next(ctx));
|
|
1005
|
-
this._actions.next({ action: nextAction, status: "DISPATCHED" /* Dispatched */ });
|
|
674
|
+
this._actions.next({ action: nextAction, status: "DISPATCHED" /* ActionStatus.Dispatched */ });
|
|
1006
675
|
return this.createDispatchObservable(actionResult$);
|
|
1007
676
|
}
|
|
1008
677
|
])(prevState, action).pipe(shareReplay());
|
|
1009
678
|
}
|
|
1010
679
|
getActionResultStream(action) {
|
|
1011
|
-
return this._actionResults.pipe(filter((ctx) => ctx.action === action && ctx.status !== "DISPATCHED" /* Dispatched */), take(1), shareReplay());
|
|
680
|
+
return this._actionResults.pipe(filter((ctx) => ctx.action === action && ctx.status !== "DISPATCHED" /* ActionStatus.Dispatched */), take(1), shareReplay());
|
|
1012
681
|
}
|
|
1013
682
|
createDispatchObservable(actionResult$) {
|
|
1014
683
|
return actionResult$
|
|
1015
684
|
.pipe(exhaustMap((ctx) => {
|
|
1016
685
|
switch (ctx.status) {
|
|
1017
|
-
case "SUCCESSFUL" /* Successful */:
|
|
686
|
+
case "SUCCESSFUL" /* ActionStatus.Successful */:
|
|
1018
687
|
return of(this._stateStream.getValue());
|
|
1019
|
-
case "ERRORED" /* Errored */:
|
|
688
|
+
case "ERRORED" /* ActionStatus.Errored */:
|
|
1020
689
|
return throwError(ctx.error);
|
|
1021
690
|
default:
|
|
1022
691
|
return EMPTY;
|
|
@@ -1025,9 +694,9 @@ class InternalDispatcher {
|
|
|
1025
694
|
.pipe(shareReplay());
|
|
1026
695
|
}
|
|
1027
696
|
}
|
|
1028
|
-
/** @nocollapse */ InternalDispatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1029
|
-
/** @nocollapse */ InternalDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1030
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
697
|
+
/** @nocollapse */ InternalDispatcher.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatcher, deps: [{ token: InternalActions }, { token: InternalDispatchedActionResults }, { token: PluginManager }, { token: StateStream }, { token: InternalNgxsExecutionStrategy }, { token: InternalErrorReporter }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
698
|
+
/** @nocollapse */ InternalDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatcher, providedIn: 'root' });
|
|
699
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatcher, decorators: [{
|
|
1031
700
|
type: Injectable,
|
|
1032
701
|
args: [{ providedIn: 'root' }]
|
|
1033
702
|
}], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalDispatchedActionResults }, { type: PluginManager }, { type: StateStream }, { type: InternalNgxsExecutionStrategy }, { type: InternalErrorReporter }]; } });
|
|
@@ -1053,58 +722,477 @@ const deepFreeze = (o) => {
|
|
|
1053
722
|
};
|
|
1054
723
|
|
|
1055
724
|
/**
|
|
1056
|
-
* @ignore
|
|
725
|
+
* @ignore
|
|
726
|
+
*/
|
|
727
|
+
class InternalStateOperations {
|
|
728
|
+
constructor(_stateStream, _dispatcher, _config) {
|
|
729
|
+
this._stateStream = _stateStream;
|
|
730
|
+
this._dispatcher = _dispatcher;
|
|
731
|
+
this._config = _config;
|
|
732
|
+
}
|
|
733
|
+
/**
|
|
734
|
+
* Returns the root state operators.
|
|
735
|
+
*/
|
|
736
|
+
getRootStateOperations() {
|
|
737
|
+
const rootStateOperations = {
|
|
738
|
+
getState: () => this._stateStream.getValue(),
|
|
739
|
+
setState: (newState) => this._stateStream.next(newState),
|
|
740
|
+
dispatch: (actionOrActions) => this._dispatcher.dispatch(actionOrActions)
|
|
741
|
+
};
|
|
742
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
743
|
+
return this._config.developmentMode
|
|
744
|
+
? ensureStateAndActionsAreImmutable(rootStateOperations)
|
|
745
|
+
: rootStateOperations;
|
|
746
|
+
}
|
|
747
|
+
else {
|
|
748
|
+
return rootStateOperations;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
setStateToTheCurrentWithNew(results) {
|
|
752
|
+
const stateOperations = this.getRootStateOperations();
|
|
753
|
+
// Get our current stream
|
|
754
|
+
const currentState = stateOperations.getState();
|
|
755
|
+
// Set the state to the current + new
|
|
756
|
+
stateOperations.setState({ ...currentState, ...results.defaults });
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
/** @nocollapse */ InternalStateOperations.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalStateOperations, deps: [{ token: StateStream }, { token: InternalDispatcher }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
760
|
+
/** @nocollapse */ InternalStateOperations.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalStateOperations, providedIn: 'root' });
|
|
761
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalStateOperations, decorators: [{
|
|
762
|
+
type: Injectable,
|
|
763
|
+
args: [{ providedIn: 'root' }]
|
|
764
|
+
}], ctorParameters: function () { return [{ type: StateStream }, { type: InternalDispatcher }, { type: NgxsConfig }]; } });
|
|
765
|
+
function ensureStateAndActionsAreImmutable(root) {
|
|
766
|
+
return {
|
|
767
|
+
getState: () => root.getState(),
|
|
768
|
+
setState: value => {
|
|
769
|
+
const frozenValue = deepFreeze(value);
|
|
770
|
+
return root.setState(frozenValue);
|
|
771
|
+
},
|
|
772
|
+
dispatch: actions => {
|
|
773
|
+
return root.dispatch(actions);
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Ensures metadata is attached to the class and returns it.
|
|
780
|
+
*
|
|
781
|
+
* @ignore
|
|
782
|
+
*/
|
|
783
|
+
function ensureStoreMetadata$1(target) {
|
|
784
|
+
if (!target.hasOwnProperty(META_KEY)) {
|
|
785
|
+
const defaultMetadata = {
|
|
786
|
+
name: null,
|
|
787
|
+
actions: {},
|
|
788
|
+
defaults: {},
|
|
789
|
+
path: null,
|
|
790
|
+
makeRootSelector(context) {
|
|
791
|
+
return context.getStateGetter(defaultMetadata.name);
|
|
792
|
+
},
|
|
793
|
+
children: []
|
|
794
|
+
};
|
|
795
|
+
Object.defineProperty(target, META_KEY, { value: defaultMetadata });
|
|
796
|
+
}
|
|
797
|
+
return getStoreMetadata$1(target);
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Get the metadata attached to the state class if it exists.
|
|
801
|
+
*
|
|
802
|
+
* @ignore
|
|
803
|
+
*/
|
|
804
|
+
function getStoreMetadata$1(target) {
|
|
805
|
+
return target[META_KEY];
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Ensures metadata is attached to the selector and returns it.
|
|
809
|
+
*
|
|
810
|
+
* @ignore
|
|
811
|
+
*/
|
|
812
|
+
function ensureSelectorMetadata$1(target) {
|
|
813
|
+
if (!target.hasOwnProperty(SELECTOR_META_KEY)) {
|
|
814
|
+
const defaultMetadata = {
|
|
815
|
+
makeRootSelector: null,
|
|
816
|
+
originalFn: null,
|
|
817
|
+
containerClass: null,
|
|
818
|
+
selectorName: null,
|
|
819
|
+
getSelectorOptions: () => ({})
|
|
820
|
+
};
|
|
821
|
+
Object.defineProperty(target, SELECTOR_META_KEY, { value: defaultMetadata });
|
|
822
|
+
}
|
|
823
|
+
return getSelectorMetadata$1(target);
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Get the metadata attached to the selector if it exists.
|
|
827
|
+
*
|
|
828
|
+
* @ignore
|
|
829
|
+
*/
|
|
830
|
+
function getSelectorMetadata$1(target) {
|
|
831
|
+
return target[SELECTOR_META_KEY];
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Get a deeply nested value. Example:
|
|
835
|
+
*
|
|
836
|
+
* getValue({ foo: bar: [] }, 'foo.bar') //=> []
|
|
837
|
+
*
|
|
838
|
+
* Note: This is not as fast as the `fastPropGetter` but is strict Content Security Policy compliant.
|
|
839
|
+
* See perf hit: https://jsperf.com/fast-value-getter-given-path/1
|
|
840
|
+
*
|
|
841
|
+
* @ignore
|
|
842
|
+
*/
|
|
843
|
+
function compliantPropGetter(paths) {
|
|
844
|
+
const copyOfPaths = paths.slice();
|
|
845
|
+
return obj => copyOfPaths.reduce((acc, part) => acc && acc[part], obj);
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* The generated function is faster than:
|
|
849
|
+
* - pluck (Observable operator)
|
|
850
|
+
* - memoize
|
|
851
|
+
*
|
|
852
|
+
* @ignore
|
|
853
|
+
*/
|
|
854
|
+
function fastPropGetter(paths) {
|
|
855
|
+
const segments = paths;
|
|
856
|
+
let seg = 'store.' + segments[0];
|
|
857
|
+
let i = 0;
|
|
858
|
+
const l = segments.length;
|
|
859
|
+
let expr = seg;
|
|
860
|
+
while (++i < l) {
|
|
861
|
+
expr = expr + ' && ' + (seg = seg + '.' + segments[i]);
|
|
862
|
+
}
|
|
863
|
+
const fn = new Function('store', 'return ' + expr + ';');
|
|
864
|
+
return fn;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Get a deeply nested value. Example:
|
|
868
|
+
*
|
|
869
|
+
* getValue({ foo: bar: [] }, 'foo.bar') //=> []
|
|
870
|
+
*
|
|
871
|
+
* @ignore
|
|
872
|
+
*/
|
|
873
|
+
function propGetter(paths, config) {
|
|
874
|
+
if (config && config.compatibility && config.compatibility.strictContentSecurityPolicy) {
|
|
875
|
+
return compliantPropGetter(paths);
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
return fastPropGetter(paths);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
882
|
+
* Given an array of states, it will return a object graph. Example:
|
|
883
|
+
* const states = [
|
|
884
|
+
* Cart,
|
|
885
|
+
* CartSaved,
|
|
886
|
+
* CartSavedItems
|
|
887
|
+
* ]
|
|
888
|
+
*
|
|
889
|
+
* would return:
|
|
890
|
+
*
|
|
891
|
+
* const graph = {
|
|
892
|
+
* cart: ['saved'],
|
|
893
|
+
* saved: ['items'],
|
|
894
|
+
* items: []
|
|
895
|
+
* };
|
|
896
|
+
*
|
|
897
|
+
* @ignore
|
|
898
|
+
*/
|
|
899
|
+
function buildGraph(stateClasses) {
|
|
900
|
+
const findName = (stateClass) => {
|
|
901
|
+
const meta = stateClasses.find(g => g === stateClass);
|
|
902
|
+
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
903
|
+
// creating a breaking change for projects that still use the View Engine.
|
|
904
|
+
if ((typeof ngDevMode === 'undefined' || ngDevMode) && !meta) {
|
|
905
|
+
throw new Error(`Child state not found: ${stateClass}. \r\nYou may have forgotten to add states to module`);
|
|
906
|
+
}
|
|
907
|
+
return meta[META_KEY].name;
|
|
908
|
+
};
|
|
909
|
+
return stateClasses.reduce((result, stateClass) => {
|
|
910
|
+
const { name, children } = stateClass[META_KEY];
|
|
911
|
+
result[name] = (children || []).map(findName);
|
|
912
|
+
return result;
|
|
913
|
+
}, {});
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Given a states array, returns object graph
|
|
917
|
+
* returning the name and state metadata. Example:
|
|
918
|
+
*
|
|
919
|
+
* const graph = {
|
|
920
|
+
* cart: { metadata }
|
|
921
|
+
* };
|
|
922
|
+
*
|
|
923
|
+
* @ignore
|
|
924
|
+
*/
|
|
925
|
+
function nameToState(states) {
|
|
926
|
+
return states.reduce((result, stateClass) => {
|
|
927
|
+
const meta = stateClass[META_KEY];
|
|
928
|
+
result[meta.name] = stateClass;
|
|
929
|
+
return result;
|
|
930
|
+
}, {});
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Given a object relationship graph will return the full path
|
|
934
|
+
* for the child items. Example:
|
|
935
|
+
*
|
|
936
|
+
* const graph = {
|
|
937
|
+
* cart: ['saved'],
|
|
938
|
+
* saved: ['items'],
|
|
939
|
+
* items: []
|
|
940
|
+
* };
|
|
941
|
+
*
|
|
942
|
+
* would return:
|
|
943
|
+
*
|
|
944
|
+
* const r = {
|
|
945
|
+
* cart: 'cart',
|
|
946
|
+
* saved: 'cart.saved',
|
|
947
|
+
* items: 'cart.saved.items'
|
|
948
|
+
* };
|
|
949
|
+
*
|
|
950
|
+
* @ignore
|
|
951
|
+
*/
|
|
952
|
+
function findFullParentPath(obj, newObj = {}) {
|
|
953
|
+
const visit = (child, keyToFind) => {
|
|
954
|
+
for (const key in child) {
|
|
955
|
+
if (child.hasOwnProperty(key) && child[key].indexOf(keyToFind) >= 0) {
|
|
956
|
+
const parent = visit(child, key);
|
|
957
|
+
return parent !== null ? `${parent}.${key}` : key;
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
return null;
|
|
961
|
+
};
|
|
962
|
+
for (const key in obj) {
|
|
963
|
+
if (obj.hasOwnProperty(key)) {
|
|
964
|
+
const parent = visit(obj, key);
|
|
965
|
+
newObj[key] = parent ? `${parent}.${key}` : key;
|
|
966
|
+
}
|
|
967
|
+
}
|
|
968
|
+
return newObj;
|
|
969
|
+
}
|
|
970
|
+
/**
|
|
971
|
+
* Given a object graph, it will return the items topologically sorted Example:
|
|
972
|
+
*
|
|
973
|
+
* const graph = {
|
|
974
|
+
* cart: ['saved'],
|
|
975
|
+
* saved: ['items'],
|
|
976
|
+
* items: []
|
|
977
|
+
* };
|
|
978
|
+
*
|
|
979
|
+
* would return:
|
|
980
|
+
*
|
|
981
|
+
* const results = [
|
|
982
|
+
* 'items',
|
|
983
|
+
* 'saved',
|
|
984
|
+
* 'cart'
|
|
985
|
+
* ];
|
|
986
|
+
*
|
|
987
|
+
* @ignore
|
|
988
|
+
*/
|
|
989
|
+
function topologicalSort(graph) {
|
|
990
|
+
const sorted = [];
|
|
991
|
+
const visited = {};
|
|
992
|
+
const visit = (name, ancestors = []) => {
|
|
993
|
+
if (!Array.isArray(ancestors)) {
|
|
994
|
+
ancestors = [];
|
|
995
|
+
}
|
|
996
|
+
ancestors.push(name);
|
|
997
|
+
visited[name] = true;
|
|
998
|
+
graph[name].forEach((dep) => {
|
|
999
|
+
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
1000
|
+
// creating a breaking change for projects that still use the View Engine.
|
|
1001
|
+
if ((typeof ngDevMode === 'undefined' || ngDevMode) && ancestors.indexOf(dep) >= 0) {
|
|
1002
|
+
throw new Error(`Circular dependency '${dep}' is required by '${name}': ${ancestors.join(' -> ')}`);
|
|
1003
|
+
}
|
|
1004
|
+
if (visited[dep]) {
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
visit(dep, ancestors.slice(0));
|
|
1008
|
+
});
|
|
1009
|
+
if (sorted.indexOf(name) < 0) {
|
|
1010
|
+
sorted.push(name);
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
Object.keys(graph).forEach(k => visit(k));
|
|
1014
|
+
return sorted.reverse();
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Returns if the parameter is a object or not.
|
|
1018
|
+
*
|
|
1019
|
+
* @ignore
|
|
1020
|
+
*/
|
|
1021
|
+
function isObject(obj) {
|
|
1022
|
+
return (typeof obj === 'object' && obj !== null) || typeof obj === 'function';
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
function createRootSelectorFactory(selectorMetaData, selectors, memoizedSelectorFn) {
|
|
1026
|
+
return (context) => {
|
|
1027
|
+
const { argumentSelectorFunctions, selectorOptions } = getRuntimeSelectorInfo(context, selectorMetaData, selectors);
|
|
1028
|
+
return function selectFromRoot(rootState) {
|
|
1029
|
+
// Determine arguments from the app state using the selectors
|
|
1030
|
+
const results = argumentSelectorFunctions.map((argFn) => argFn(rootState));
|
|
1031
|
+
// if the lambda tries to access a something on the
|
|
1032
|
+
// state that doesn't exist, it will throw a TypeError.
|
|
1033
|
+
// since this is quite usual behaviour, we simply return undefined if so.
|
|
1034
|
+
try {
|
|
1035
|
+
return memoizedSelectorFn(...results);
|
|
1036
|
+
}
|
|
1037
|
+
catch (ex) {
|
|
1038
|
+
if (ex instanceof TypeError && selectorOptions.suppressErrors) {
|
|
1039
|
+
return undefined;
|
|
1040
|
+
}
|
|
1041
|
+
throw ex;
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
};
|
|
1045
|
+
}
|
|
1046
|
+
function createMemoizedSelectorFn(originalFn, creationMetadata) {
|
|
1047
|
+
const containerClass = creationMetadata && creationMetadata.containerClass;
|
|
1048
|
+
const wrappedFn = function wrappedSelectorFn(...args) {
|
|
1049
|
+
const returnValue = originalFn.apply(containerClass, args);
|
|
1050
|
+
if (returnValue instanceof Function) {
|
|
1051
|
+
const innerMemoizedFn = memoize.apply(null, [returnValue]);
|
|
1052
|
+
return innerMemoizedFn;
|
|
1053
|
+
}
|
|
1054
|
+
return returnValue;
|
|
1055
|
+
};
|
|
1056
|
+
const memoizedFn = memoize(wrappedFn);
|
|
1057
|
+
Object.setPrototypeOf(memoizedFn, originalFn);
|
|
1058
|
+
return memoizedFn;
|
|
1059
|
+
}
|
|
1060
|
+
function getRuntimeSelectorInfo(context, selectorMetaData, selectors = []) {
|
|
1061
|
+
const localSelectorOptions = selectorMetaData.getSelectorOptions();
|
|
1062
|
+
const selectorOptions = context.getSelectorOptions(localSelectorOptions);
|
|
1063
|
+
const selectorsToApply = getSelectorsToApply(selectors, selectorOptions, selectorMetaData.containerClass);
|
|
1064
|
+
const argumentSelectorFunctions = selectorsToApply.map((selector) => {
|
|
1065
|
+
const factory = getRootSelectorFactory(selector);
|
|
1066
|
+
return factory(context);
|
|
1067
|
+
});
|
|
1068
|
+
return {
|
|
1069
|
+
selectorOptions,
|
|
1070
|
+
argumentSelectorFunctions,
|
|
1071
|
+
};
|
|
1072
|
+
}
|
|
1073
|
+
function getSelectorsToApply(selectors = [], selectorOptions, containerClass) {
|
|
1074
|
+
const selectorsToApply = [];
|
|
1075
|
+
const canInjectContainerState = selectors.length === 0 || selectorOptions.injectContainerState;
|
|
1076
|
+
if (containerClass && canInjectContainerState) {
|
|
1077
|
+
// If we are on a state class, add it as the first selector parameter
|
|
1078
|
+
const metadata = getStoreMetadata$1(containerClass);
|
|
1079
|
+
if (metadata) {
|
|
1080
|
+
selectorsToApply.push(containerClass);
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
if (selectors) {
|
|
1084
|
+
selectorsToApply.push(...selectors);
|
|
1085
|
+
}
|
|
1086
|
+
return selectorsToApply;
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* This function gets the factory function to create the selector to get the selected slice from the app state
|
|
1090
|
+
* @ignore
|
|
1091
|
+
*/
|
|
1092
|
+
function getRootSelectorFactory(selector) {
|
|
1093
|
+
const metadata = getSelectorMetadata$1(selector) || getStoreMetadata$1(selector);
|
|
1094
|
+
return (metadata && metadata.makeRootSelector) || (() => selector);
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
/**
|
|
1098
|
+
* RxJS operator for selecting out specific actions.
|
|
1099
|
+
*
|
|
1100
|
+
* This will grab actions that have just been dispatched as well as actions that have completed
|
|
1101
|
+
*/
|
|
1102
|
+
function ofAction(...allowedTypes) {
|
|
1103
|
+
return ofActionOperator(allowedTypes);
|
|
1104
|
+
}
|
|
1105
|
+
/**
|
|
1106
|
+
* RxJS operator for selecting out specific actions.
|
|
1107
|
+
*
|
|
1108
|
+
* This will ONLY grab actions that have just been dispatched
|
|
1109
|
+
*/
|
|
1110
|
+
function ofActionDispatched(...allowedTypes) {
|
|
1111
|
+
return ofActionOperator(allowedTypes, ["DISPATCHED" /* ActionStatus.Dispatched */]);
|
|
1112
|
+
}
|
|
1113
|
+
/**
|
|
1114
|
+
* RxJS operator for selecting out specific actions.
|
|
1115
|
+
*
|
|
1116
|
+
* This will ONLY grab actions that have just been successfully completed
|
|
1117
|
+
*/
|
|
1118
|
+
function ofActionSuccessful(...allowedTypes) {
|
|
1119
|
+
return ofActionOperator(allowedTypes, ["SUCCESSFUL" /* ActionStatus.Successful */]);
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* RxJS operator for selecting out specific actions.
|
|
1123
|
+
*
|
|
1124
|
+
* This will ONLY grab actions that have just been canceled
|
|
1125
|
+
*/
|
|
1126
|
+
function ofActionCanceled(...allowedTypes) {
|
|
1127
|
+
return ofActionOperator(allowedTypes, ["CANCELED" /* ActionStatus.Canceled */]);
|
|
1128
|
+
}
|
|
1129
|
+
/**
|
|
1130
|
+
* RxJS operator for selecting out specific actions.
|
|
1131
|
+
*
|
|
1132
|
+
* This will ONLY grab actions that have just been completed
|
|
1133
|
+
*/
|
|
1134
|
+
function ofActionCompleted(...allowedTypes) {
|
|
1135
|
+
const allowedStatuses = [
|
|
1136
|
+
"SUCCESSFUL" /* ActionStatus.Successful */,
|
|
1137
|
+
"CANCELED" /* ActionStatus.Canceled */,
|
|
1138
|
+
"ERRORED" /* ActionStatus.Errored */
|
|
1139
|
+
];
|
|
1140
|
+
return ofActionOperator(allowedTypes, allowedStatuses, mapActionResult);
|
|
1141
|
+
}
|
|
1142
|
+
/**
|
|
1143
|
+
* RxJS operator for selecting out specific actions.
|
|
1144
|
+
*
|
|
1145
|
+
* This will ONLY grab actions that have just thrown an error
|
|
1057
1146
|
*/
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
this._stateStream = _stateStream;
|
|
1061
|
-
this._dispatcher = _dispatcher;
|
|
1062
|
-
this._config = _config;
|
|
1063
|
-
}
|
|
1064
|
-
/**
|
|
1065
|
-
* Returns the root state operators.
|
|
1066
|
-
*/
|
|
1067
|
-
getRootStateOperations() {
|
|
1068
|
-
const rootStateOperations = {
|
|
1069
|
-
getState: () => this._stateStream.getValue(),
|
|
1070
|
-
setState: (newState) => this._stateStream.next(newState),
|
|
1071
|
-
dispatch: (actionOrActions) => this._dispatcher.dispatch(actionOrActions)
|
|
1072
|
-
};
|
|
1073
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
1074
|
-
return this._config.developmentMode
|
|
1075
|
-
? ensureStateAndActionsAreImmutable(rootStateOperations)
|
|
1076
|
-
: rootStateOperations;
|
|
1077
|
-
}
|
|
1078
|
-
else {
|
|
1079
|
-
return rootStateOperations;
|
|
1080
|
-
}
|
|
1081
|
-
}
|
|
1082
|
-
setStateToTheCurrentWithNew(results) {
|
|
1083
|
-
const stateOperations = this.getRootStateOperations();
|
|
1084
|
-
// Get our current stream
|
|
1085
|
-
const currentState = stateOperations.getState();
|
|
1086
|
-
// Set the state to the current + new
|
|
1087
|
-
stateOperations.setState(Object.assign(Object.assign({}, currentState), results.defaults));
|
|
1088
|
-
}
|
|
1147
|
+
function ofActionErrored(...allowedTypes) {
|
|
1148
|
+
return ofActionOperator(allowedTypes, ["ERRORED" /* ActionStatus.Errored */]);
|
|
1089
1149
|
}
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
return {
|
|
1098
|
-
|
|
1099
|
-
setState: value => {
|
|
1100
|
-
const frozenValue = deepFreeze(value);
|
|
1101
|
-
return root.setState(frozenValue);
|
|
1102
|
-
},
|
|
1103
|
-
dispatch: actions => {
|
|
1104
|
-
return root.dispatch(actions);
|
|
1105
|
-
}
|
|
1150
|
+
function ofActionOperator(allowedTypes, statuses,
|
|
1151
|
+
// This actually could've been `OperatorFunction<ActionContext, ActionCompletion | any>`,
|
|
1152
|
+
// since it maps either to `ctx.action` OR to `ActionCompletion`. But `ActionCompleteion | any`
|
|
1153
|
+
// defaults to `any`, thus there is no sense from union type.
|
|
1154
|
+
mapOperator = mapAction) {
|
|
1155
|
+
const allowedMap = createAllowedActionTypesMap(allowedTypes);
|
|
1156
|
+
const allowedStatusMap = statuses && createAllowedStatusesMap(statuses);
|
|
1157
|
+
return function (o) {
|
|
1158
|
+
return o.pipe(filterStatus(allowedMap, allowedStatusMap), mapOperator());
|
|
1106
1159
|
};
|
|
1107
1160
|
}
|
|
1161
|
+
function filterStatus(allowedTypes, allowedStatuses) {
|
|
1162
|
+
return filter((ctx) => {
|
|
1163
|
+
const actionType = getActionTypeFromInstance(ctx.action);
|
|
1164
|
+
const typeMatch = allowedTypes[actionType];
|
|
1165
|
+
const statusMatch = allowedStatuses ? allowedStatuses[ctx.status] : true;
|
|
1166
|
+
return typeMatch && statusMatch;
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
function mapActionResult() {
|
|
1170
|
+
return map(({ action, status, error }) => {
|
|
1171
|
+
return {
|
|
1172
|
+
action,
|
|
1173
|
+
result: {
|
|
1174
|
+
successful: "SUCCESSFUL" /* ActionStatus.Successful */ === status,
|
|
1175
|
+
canceled: "CANCELED" /* ActionStatus.Canceled */ === status,
|
|
1176
|
+
error
|
|
1177
|
+
}
|
|
1178
|
+
};
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
function mapAction() {
|
|
1182
|
+
return map((ctx) => ctx.action);
|
|
1183
|
+
}
|
|
1184
|
+
function createAllowedActionTypesMap(types) {
|
|
1185
|
+
return types.reduce((filterMap, klass) => {
|
|
1186
|
+
filterMap[getActionTypeFromInstance(klass)] = true;
|
|
1187
|
+
return filterMap;
|
|
1188
|
+
}, {});
|
|
1189
|
+
}
|
|
1190
|
+
function createAllowedStatusesMap(statuses) {
|
|
1191
|
+
return statuses.reduce((filterMap, status) => {
|
|
1192
|
+
filterMap[status] = true;
|
|
1193
|
+
return filterMap;
|
|
1194
|
+
}, {});
|
|
1195
|
+
}
|
|
1108
1196
|
|
|
1109
1197
|
function simplePatch(value) {
|
|
1110
1198
|
return (existingState) => {
|
|
@@ -1116,7 +1204,7 @@ function simplePatch(value) {
|
|
|
1116
1204
|
throwPatchingPrimitiveError();
|
|
1117
1205
|
}
|
|
1118
1206
|
}
|
|
1119
|
-
const newState =
|
|
1207
|
+
const newState = { ...existingState };
|
|
1120
1208
|
for (const key in value) {
|
|
1121
1209
|
// deep clone for patch compatibility
|
|
1122
1210
|
newState[key] = value[key];
|
|
@@ -1160,9 +1248,9 @@ class StateContextFactory {
|
|
|
1160
1248
|
};
|
|
1161
1249
|
}
|
|
1162
1250
|
}
|
|
1163
|
-
/** @nocollapse */ StateContextFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1164
|
-
/** @nocollapse */ StateContextFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1165
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1251
|
+
/** @nocollapse */ StateContextFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateContextFactory, deps: [{ token: InternalStateOperations }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1252
|
+
/** @nocollapse */ StateContextFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateContextFactory, providedIn: 'root' });
|
|
1253
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateContextFactory, decorators: [{
|
|
1166
1254
|
type: Injectable,
|
|
1167
1255
|
args: [{ providedIn: 'root' }]
|
|
1168
1256
|
}], ctorParameters: function () { return [{ type: InternalStateOperations }]; } });
|
|
@@ -1230,7 +1318,7 @@ function aot_hasNgInjectableDef(stateClass) {
|
|
|
1230
1318
|
function jit_hasInjectableAnnotation(stateClass) {
|
|
1231
1319
|
// `ɵprov` doesn't exist in JIT mode (for instance when running unit tests with Jest).
|
|
1232
1320
|
const annotations = stateClass.__annotations__ || [];
|
|
1233
|
-
return annotations.some((annotation) =>
|
|
1321
|
+
return annotations.some((annotation) => annotation?.ngMetadataName === 'Injectable');
|
|
1234
1322
|
}
|
|
1235
1323
|
|
|
1236
1324
|
/**
|
|
@@ -1286,16 +1374,16 @@ class NgxsUnhandledActionsLogger {
|
|
|
1286
1374
|
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.`);
|
|
1287
1375
|
}
|
|
1288
1376
|
}
|
|
1289
|
-
/** @nocollapse */ NgxsUnhandledActionsLogger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1290
|
-
/** @nocollapse */ NgxsUnhandledActionsLogger.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1291
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1377
|
+
/** @nocollapse */ NgxsUnhandledActionsLogger.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsUnhandledActionsLogger, deps: [{ token: NGXS_DEVELOPMENT_OPTIONS }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1378
|
+
/** @nocollapse */ NgxsUnhandledActionsLogger.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsUnhandledActionsLogger });
|
|
1379
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsUnhandledActionsLogger, decorators: [{
|
|
1292
1380
|
type: Injectable
|
|
1293
1381
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
1294
1382
|
type: Inject,
|
|
1295
1383
|
args: [NGXS_DEVELOPMENT_OPTIONS]
|
|
1296
1384
|
}] }]; } });
|
|
1297
1385
|
|
|
1298
|
-
const NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
1386
|
+
const NG_DEV_MODE$1 = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
1299
1387
|
/**
|
|
1300
1388
|
* The `StateFactory` class adds root and feature states to the graph.
|
|
1301
1389
|
* This extracts state names from state classes, checks if they already
|
|
@@ -1333,21 +1421,26 @@ class StateFactory {
|
|
|
1333
1421
|
? this._parentFactory.getRuntimeSelectorContext()
|
|
1334
1422
|
: {
|
|
1335
1423
|
getStateGetter(key) {
|
|
1336
|
-
|
|
1424
|
+
// Use `@__INLINE__` annotation to forcely inline `resolveGetter`.
|
|
1425
|
+
// This is a Terser annotation, which will function only in the production mode.
|
|
1426
|
+
let getter = /*@__INLINE__*/ resolveGetter(key);
|
|
1337
1427
|
if (getter) {
|
|
1338
1428
|
return getter;
|
|
1339
1429
|
}
|
|
1340
1430
|
return (...args) => {
|
|
1341
1431
|
// Late loaded getter
|
|
1342
1432
|
if (!getter) {
|
|
1343
|
-
getter = resolveGetter(key);
|
|
1433
|
+
getter = /*@__INLINE__*/ resolveGetter(key);
|
|
1344
1434
|
}
|
|
1345
1435
|
return getter ? getter(...args) : undefined;
|
|
1346
1436
|
};
|
|
1347
1437
|
},
|
|
1348
1438
|
getSelectorOptions(localOptions) {
|
|
1349
1439
|
const globalSelectorOptions = stateFactory._config.selectorOptions;
|
|
1350
|
-
return
|
|
1440
|
+
return {
|
|
1441
|
+
...globalSelectorOptions,
|
|
1442
|
+
...(localOptions || {})
|
|
1443
|
+
};
|
|
1351
1444
|
}
|
|
1352
1445
|
};
|
|
1353
1446
|
return context;
|
|
@@ -1368,7 +1461,7 @@ class StateFactory {
|
|
|
1368
1461
|
value = defaults.slice();
|
|
1369
1462
|
}
|
|
1370
1463
|
else if (isObject(defaults)) {
|
|
1371
|
-
value =
|
|
1464
|
+
value = { ...defaults };
|
|
1372
1465
|
}
|
|
1373
1466
|
else if (defaults === undefined) {
|
|
1374
1467
|
value = {};
|
|
@@ -1376,14 +1469,13 @@ class StateFactory {
|
|
|
1376
1469
|
return value;
|
|
1377
1470
|
}
|
|
1378
1471
|
ngOnDestroy() {
|
|
1379
|
-
|
|
1380
|
-
(_a = this._actionsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
1472
|
+
this._actionsSubscription?.unsubscribe();
|
|
1381
1473
|
}
|
|
1382
1474
|
/**
|
|
1383
1475
|
* Add a new state to the global defs.
|
|
1384
1476
|
*/
|
|
1385
1477
|
add(stateClasses) {
|
|
1386
|
-
if (NG_DEV_MODE) {
|
|
1478
|
+
if (NG_DEV_MODE$1) {
|
|
1387
1479
|
ensureStatesAreDecorated(stateClasses);
|
|
1388
1480
|
}
|
|
1389
1481
|
const { newStates } = this.addToStatesMap(stateClasses);
|
|
@@ -1403,7 +1495,7 @@ class StateFactory {
|
|
|
1403
1495
|
// `State` decorator. This check is moved here because the `ɵprov` property
|
|
1404
1496
|
// will not exist on the class in JIT mode (because it's set asynchronously
|
|
1405
1497
|
// during JIT compilation through `Object.defineProperty`).
|
|
1406
|
-
if (NG_DEV_MODE) {
|
|
1498
|
+
if (NG_DEV_MODE$1) {
|
|
1407
1499
|
ensureStateClassIsInjectable(stateClass);
|
|
1408
1500
|
}
|
|
1409
1501
|
const stateMap = {
|
|
@@ -1442,10 +1534,10 @@ class StateFactory {
|
|
|
1442
1534
|
}
|
|
1443
1535
|
const dispatched$ = new Subject();
|
|
1444
1536
|
this._actionsSubscription = this._actions
|
|
1445
|
-
.pipe(filter((ctx) => ctx.status === "DISPATCHED" /* Dispatched */), mergeMap(ctx => {
|
|
1537
|
+
.pipe(filter((ctx) => ctx.status === "DISPATCHED" /* ActionStatus.Dispatched */), mergeMap(ctx => {
|
|
1446
1538
|
dispatched$.next(ctx);
|
|
1447
1539
|
const action = ctx.action;
|
|
1448
|
-
return this.invokeActions(dispatched$, action).pipe(map(() => ({ action, status: "SUCCESSFUL" /* Successful */ })), defaultIfEmpty({ action, status: "CANCELED" /* Canceled */ }), catchError(error => of({ action, status: "ERRORED" /* Errored */, error })));
|
|
1540
|
+
return this.invokeActions(dispatched$, action).pipe(map(() => ({ action, status: "SUCCESSFUL" /* ActionStatus.Successful */ })), defaultIfEmpty({ action, status: "CANCELED" /* ActionStatus.Canceled */ }), catchError(error => of({ action, status: "ERRORED" /* ActionStatus.Errored */, error })));
|
|
1449
1541
|
}))
|
|
1450
1542
|
.subscribe(ctx => this._actionResults.next(ctx));
|
|
1451
1543
|
}
|
|
@@ -1505,7 +1597,7 @@ class StateFactory {
|
|
|
1505
1597
|
}
|
|
1506
1598
|
// The `NgxsUnhandledActionsLogger` is a tree-shakable class which functions
|
|
1507
1599
|
// only during development.
|
|
1508
|
-
if (NG_DEV_MODE && !actionHasBeenHandled) {
|
|
1600
|
+
if (NG_DEV_MODE$1 && !actionHasBeenHandled) {
|
|
1509
1601
|
const unhandledActionsLogger = this._injector.get(NgxsUnhandledActionsLogger, null);
|
|
1510
1602
|
// The `NgxsUnhandledActionsLogger` will not be resolved by the injector if the
|
|
1511
1603
|
// `NgxsDevelopmentModule` is not provided. It's enough to check whether the `injector.get`
|
|
@@ -1524,7 +1616,7 @@ class StateFactory {
|
|
|
1524
1616
|
const statesMap = this.statesByName;
|
|
1525
1617
|
for (const stateClass of stateClasses) {
|
|
1526
1618
|
const stateName = getStoreMetadata$1(stateClass).name;
|
|
1527
|
-
if (NG_DEV_MODE) {
|
|
1619
|
+
if (NG_DEV_MODE$1) {
|
|
1528
1620
|
ensureStateNameIsUnique(stateName, stateClass, statesMap);
|
|
1529
1621
|
}
|
|
1530
1622
|
const unmountedState = !statesMap[stateName];
|
|
@@ -1549,9 +1641,9 @@ class StateFactory {
|
|
|
1549
1641
|
return this.statesByName[name] && valueIsBootstrappedInInitialState;
|
|
1550
1642
|
}
|
|
1551
1643
|
}
|
|
1552
|
-
/** @nocollapse */ StateFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1553
|
-
/** @nocollapse */ StateFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1554
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1644
|
+
/** @nocollapse */ StateFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateFactory, deps: [{ token: i0.Injector }, { token: NgxsConfig }, { token: StateFactory, optional: true, skipSelf: true }, { token: InternalActions }, { token: InternalDispatchedActionResults }, { token: StateContextFactory }, { token: INITIAL_STATE_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1645
|
+
/** @nocollapse */ StateFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateFactory });
|
|
1646
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateFactory, decorators: [{
|
|
1555
1647
|
type: Injectable
|
|
1556
1648
|
}], ctorParameters: function () { return [{ type: i0.Injector }, { type: NgxsConfig }, { type: StateFactory, decorators: [{
|
|
1557
1649
|
type: Optional
|
|
@@ -1564,78 +1656,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
|
|
|
1564
1656
|
args: [INITIAL_STATE_TOKEN]
|
|
1565
1657
|
}] }]; } });
|
|
1566
1658
|
|
|
1567
|
-
function createRootSelectorFactory(selectorMetaData, selectors, memoizedSelectorFn) {
|
|
1568
|
-
return (context) => {
|
|
1569
|
-
const { argumentSelectorFunctions, selectorOptions } = getRuntimeSelectorInfo(context, selectorMetaData, selectors);
|
|
1570
|
-
return function selectFromRoot(rootState) {
|
|
1571
|
-
// Determine arguments from the app state using the selectors
|
|
1572
|
-
const results = argumentSelectorFunctions.map((argFn) => argFn(rootState));
|
|
1573
|
-
// if the lambda tries to access a something on the
|
|
1574
|
-
// state that doesn't exist, it will throw a TypeError.
|
|
1575
|
-
// since this is quite usual behaviour, we simply return undefined if so.
|
|
1576
|
-
try {
|
|
1577
|
-
return memoizedSelectorFn(...results);
|
|
1578
|
-
}
|
|
1579
|
-
catch (ex) {
|
|
1580
|
-
if (ex instanceof TypeError && selectorOptions.suppressErrors) {
|
|
1581
|
-
return undefined;
|
|
1582
|
-
}
|
|
1583
|
-
throw ex;
|
|
1584
|
-
}
|
|
1585
|
-
};
|
|
1586
|
-
};
|
|
1587
|
-
}
|
|
1588
|
-
function createMemoizedSelectorFn(originalFn, creationMetadata) {
|
|
1589
|
-
const containerClass = creationMetadata && creationMetadata.containerClass;
|
|
1590
|
-
const wrappedFn = function wrappedSelectorFn(...args) {
|
|
1591
|
-
const returnValue = originalFn.apply(containerClass, args);
|
|
1592
|
-
if (returnValue instanceof Function) {
|
|
1593
|
-
const innerMemoizedFn = memoize.apply(null, [returnValue]);
|
|
1594
|
-
return innerMemoizedFn;
|
|
1595
|
-
}
|
|
1596
|
-
return returnValue;
|
|
1597
|
-
};
|
|
1598
|
-
const memoizedFn = memoize(wrappedFn);
|
|
1599
|
-
Object.setPrototypeOf(memoizedFn, originalFn);
|
|
1600
|
-
return memoizedFn;
|
|
1601
|
-
}
|
|
1602
|
-
function getRuntimeSelectorInfo(context, selectorMetaData, selectors = []) {
|
|
1603
|
-
const localSelectorOptions = selectorMetaData.getSelectorOptions();
|
|
1604
|
-
const selectorOptions = context.getSelectorOptions(localSelectorOptions);
|
|
1605
|
-
const selectorsToApply = getSelectorsToApply(selectors, selectorOptions, selectorMetaData.containerClass);
|
|
1606
|
-
const argumentSelectorFunctions = selectorsToApply.map((selector) => {
|
|
1607
|
-
const factory = getRootSelectorFactory(selector);
|
|
1608
|
-
return factory(context);
|
|
1609
|
-
});
|
|
1610
|
-
return {
|
|
1611
|
-
selectorOptions,
|
|
1612
|
-
argumentSelectorFunctions,
|
|
1613
|
-
};
|
|
1614
|
-
}
|
|
1615
|
-
function getSelectorsToApply(selectors = [], selectorOptions, containerClass) {
|
|
1616
|
-
const selectorsToApply = [];
|
|
1617
|
-
const canInjectContainerState = selectors.length === 0 || selectorOptions.injectContainerState;
|
|
1618
|
-
if (containerClass && canInjectContainerState) {
|
|
1619
|
-
// If we are on a state class, add it as the first selector parameter
|
|
1620
|
-
const metadata = getStoreMetadata$1(containerClass);
|
|
1621
|
-
if (metadata) {
|
|
1622
|
-
selectorsToApply.push(containerClass);
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
if (selectors) {
|
|
1626
|
-
selectorsToApply.push(...selectors);
|
|
1627
|
-
}
|
|
1628
|
-
return selectorsToApply;
|
|
1629
|
-
}
|
|
1630
|
-
/**
|
|
1631
|
-
* This function gets the factory function to create the selector to get the selected slice from the app state
|
|
1632
|
-
* @ignore
|
|
1633
|
-
*/
|
|
1634
|
-
function getRootSelectorFactory(selector) {
|
|
1635
|
-
const metadata = getSelectorMetadata$1(selector) || getStoreMetadata$1(selector);
|
|
1636
|
-
return (metadata && metadata.makeRootSelector) || (() => selector);
|
|
1637
|
-
}
|
|
1638
|
-
|
|
1639
1659
|
// tslint:disable:unified-signatures
|
|
1640
1660
|
class Store {
|
|
1641
1661
|
constructor(_stateStream, _internalStateOperations, _config, _internalExecutionStrategy, _stateFactory, initialStateValue) {
|
|
@@ -1709,14 +1729,15 @@ class Store {
|
|
|
1709
1729
|
if (storeIsEmpty) {
|
|
1710
1730
|
const defaultStateNotEmpty = Object.keys(this._config.defaultsState).length > 0;
|
|
1711
1731
|
const storeValues = defaultStateNotEmpty
|
|
1712
|
-
?
|
|
1732
|
+
? { ...this._config.defaultsState, ...initialStateValue }
|
|
1733
|
+
: initialStateValue;
|
|
1713
1734
|
this._stateStream.next(storeValues);
|
|
1714
1735
|
}
|
|
1715
1736
|
}
|
|
1716
1737
|
}
|
|
1717
|
-
/** @nocollapse */ Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1718
|
-
/** @nocollapse */ Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1719
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1738
|
+
/** @nocollapse */ Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Store, deps: [{ token: StateStream }, { token: InternalStateOperations }, { token: NgxsConfig }, { token: InternalNgxsExecutionStrategy }, { token: StateFactory }, { token: INITIAL_STATE_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1739
|
+
/** @nocollapse */ Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Store, providedIn: 'root' });
|
|
1740
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Store, decorators: [{
|
|
1720
1741
|
type: Injectable,
|
|
1721
1742
|
args: [{ providedIn: 'root' }]
|
|
1722
1743
|
}], ctorParameters: function () { return [{ type: StateStream }, { type: InternalStateOperations }, { type: NgxsConfig }, { type: InternalNgxsExecutionStrategy }, { type: StateFactory }, { type: undefined, decorators: [{
|
|
@@ -1742,9 +1763,9 @@ class SelectFactory {
|
|
|
1742
1763
|
}
|
|
1743
1764
|
SelectFactory.store = null;
|
|
1744
1765
|
SelectFactory.config = null;
|
|
1745
|
-
/** @nocollapse */ SelectFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1746
|
-
/** @nocollapse */ SelectFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1747
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1766
|
+
/** @nocollapse */ SelectFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: SelectFactory, deps: [{ token: Store }, { token: NgxsConfig }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1767
|
+
/** @nocollapse */ SelectFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: SelectFactory, providedIn: 'root' });
|
|
1768
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: SelectFactory, decorators: [{
|
|
1748
1769
|
type: Injectable,
|
|
1749
1770
|
args: [{ providedIn: 'root' }]
|
|
1750
1771
|
}], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
|
|
@@ -1805,148 +1826,196 @@ class LifecycleStateManager {
|
|
|
1805
1826
|
return this._stateContextFactory.createStateContext(mappedStore);
|
|
1806
1827
|
}
|
|
1807
1828
|
}
|
|
1808
|
-
/** @nocollapse */ LifecycleStateManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1809
|
-
/** @nocollapse */ LifecycleStateManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "
|
|
1810
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1829
|
+
/** @nocollapse */ LifecycleStateManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: LifecycleStateManager, deps: [{ token: Store }, { token: InternalErrorReporter }, { token: InternalStateOperations }, { token: StateContextFactory }, { token: i5.NgxsBootstrapper }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1830
|
+
/** @nocollapse */ LifecycleStateManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: LifecycleStateManager, providedIn: 'root' });
|
|
1831
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: LifecycleStateManager, decorators: [{
|
|
1811
1832
|
type: Injectable,
|
|
1812
1833
|
args: [{ providedIn: 'root' }]
|
|
1813
1834
|
}], ctorParameters: function () { return [{ type: Store }, { type: InternalErrorReporter }, { type: InternalStateOperations }, { type: StateContextFactory }, { type: i5.NgxsBootstrapper }]; } });
|
|
1814
1835
|
|
|
1836
|
+
const NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
1837
|
+
/**
|
|
1838
|
+
* This function is shared by both NgModule and standalone features.
|
|
1839
|
+
* When using `NgxsModule.forRoot` and `provideStore`, we can depend on the
|
|
1840
|
+
* same initialization functionality.
|
|
1841
|
+
*/
|
|
1842
|
+
function rootStoreInitializer() {
|
|
1843
|
+
const factory = inject(StateFactory);
|
|
1844
|
+
const internalStateOperations = inject(InternalStateOperations);
|
|
1845
|
+
inject(Store);
|
|
1846
|
+
inject(SelectFactory);
|
|
1847
|
+
const states = inject(ROOT_STATE_TOKEN, { optional: true }) || [];
|
|
1848
|
+
const lifecycleStateManager = inject(LifecycleStateManager);
|
|
1849
|
+
// Add stores to the state graph and return their defaults.
|
|
1850
|
+
const results = factory.addAndReturnDefaults(states);
|
|
1851
|
+
internalStateOperations.setStateToTheCurrentWithNew(results);
|
|
1852
|
+
// Connect our actions stream.
|
|
1853
|
+
factory.connectActionHandlers();
|
|
1854
|
+
// Dispatch the init action and invoke init and bootstrap functions after.
|
|
1855
|
+
lifecycleStateManager.ngxsBootstrap(new InitState(), results);
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* This function is utilized by both NgModule and standalone features.
|
|
1859
|
+
* When using `NgxsModule.forFeature` and `provideStates`, we can depend on
|
|
1860
|
+
* the same initialization functionality.
|
|
1861
|
+
*/
|
|
1862
|
+
function featureStatesInitializer() {
|
|
1863
|
+
inject(Store);
|
|
1864
|
+
const internalStateOperations = inject(InternalStateOperations);
|
|
1865
|
+
const factory = inject(StateFactory);
|
|
1866
|
+
const states = inject(FEATURE_STATE_TOKEN, { optional: true }) || [];
|
|
1867
|
+
const lifecycleStateManager = inject(LifecycleStateManager);
|
|
1868
|
+
// Since FEATURE_STATE_TOKEN is a multi token, we need to
|
|
1869
|
+
// flatten it [[Feature1State, Feature2State], [Feature3State]].
|
|
1870
|
+
const flattenedStates = states.reduce((total, values) => total.concat(values), []);
|
|
1871
|
+
// add stores to the state graph and return their defaults.
|
|
1872
|
+
const results = factory.addAndReturnDefaults(flattenedStates);
|
|
1873
|
+
if (results.states.length) {
|
|
1874
|
+
internalStateOperations.setStateToTheCurrentWithNew(results);
|
|
1875
|
+
// Dispatch the update action and invoke init and bootstrap functions after.
|
|
1876
|
+
lifecycleStateManager.ngxsBootstrap(new UpdateState(results.defaults), results);
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
/**
|
|
1880
|
+
* InjectionToken that registers the global Store.
|
|
1881
|
+
*/
|
|
1882
|
+
const NGXS_ROOT_STORE_INITIALIZER = new InjectionToken(NG_DEV_MODE ? 'NGXS_ROOT_STORE_INITIALIZER' : '');
|
|
1883
|
+
/**
|
|
1884
|
+
* InjectionToken that registers feature states.
|
|
1885
|
+
*/
|
|
1886
|
+
const NGXS_FEATURE_STORE_INITIALIZER = new InjectionToken(NG_DEV_MODE ? 'NGXS_FEATURE_STORE_INITIALIZER' : '');
|
|
1887
|
+
const NGXS_ROOT_ENVIRONMENT_INITIALIZER = [
|
|
1888
|
+
{ provide: NGXS_ROOT_STORE_INITIALIZER, useFactory: rootStoreInitializer },
|
|
1889
|
+
{
|
|
1890
|
+
provide: ENVIRONMENT_INITIALIZER,
|
|
1891
|
+
multi: true,
|
|
1892
|
+
useFactory() {
|
|
1893
|
+
return () => inject(NGXS_ROOT_STORE_INITIALIZER);
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
];
|
|
1897
|
+
/**
|
|
1898
|
+
* The `NGXS_FEATURE_ENVIRONMENT_INITIALIZER` functions as an environment initializer
|
|
1899
|
+
* at the `Route` level. Angular Router creates an environment route injector for each
|
|
1900
|
+
* matched route where navigation occurs. The injector is created once, ensuring that
|
|
1901
|
+
* the feature states initialization only happens once as well.
|
|
1902
|
+
*/
|
|
1903
|
+
const NGXS_FEATURE_ENVIRONMENT_INITIALIZER = [
|
|
1904
|
+
{ provide: NGXS_FEATURE_STORE_INITIALIZER, useFactory: featureStatesInitializer },
|
|
1905
|
+
{
|
|
1906
|
+
provide: ENVIRONMENT_INITIALIZER,
|
|
1907
|
+
multi: true,
|
|
1908
|
+
useFactory() {
|
|
1909
|
+
return () => inject(NGXS_FEATURE_STORE_INITIALIZER);
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
];
|
|
1913
|
+
|
|
1815
1914
|
/**
|
|
1816
|
-
* Root module
|
|
1817
1915
|
* @ignore
|
|
1818
1916
|
*/
|
|
1819
1917
|
class NgxsRootModule {
|
|
1820
|
-
constructor(
|
|
1821
|
-
|
|
1822
|
-
const results = factory.addAndReturnDefaults(states);
|
|
1823
|
-
internalStateOperations.setStateToTheCurrentWithNew(results);
|
|
1824
|
-
// Connect our actions stream
|
|
1825
|
-
factory.connectActionHandlers();
|
|
1826
|
-
// Dispatch the init action and invoke init and bootstrap functions after
|
|
1827
|
-
lifecycleStateManager.ngxsBootstrap(new InitState(), results);
|
|
1918
|
+
constructor() {
|
|
1919
|
+
rootStoreInitializer();
|
|
1828
1920
|
}
|
|
1829
1921
|
}
|
|
1830
|
-
/** @nocollapse */ NgxsRootModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1831
|
-
/** @nocollapse */ NgxsRootModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "
|
|
1832
|
-
/** @nocollapse */ NgxsRootModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
1833
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1922
|
+
/** @nocollapse */ NgxsRootModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1923
|
+
/** @nocollapse */ NgxsRootModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule });
|
|
1924
|
+
/** @nocollapse */ NgxsRootModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule });
|
|
1925
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule, decorators: [{
|
|
1834
1926
|
type: NgModule
|
|
1835
|
-
}], ctorParameters: function () { return [
|
|
1836
|
-
type: Optional
|
|
1837
|
-
}, {
|
|
1838
|
-
type: Inject,
|
|
1839
|
-
args: [ROOT_STATE_TOKEN]
|
|
1840
|
-
}] }, { type: LifecycleStateManager }]; } });
|
|
1927
|
+
}], ctorParameters: function () { return []; } });
|
|
1841
1928
|
|
|
1842
1929
|
/**
|
|
1843
|
-
* Feature module
|
|
1844
1930
|
* @ignore
|
|
1845
1931
|
*/
|
|
1846
1932
|
class NgxsFeatureModule {
|
|
1847
|
-
constructor(
|
|
1848
|
-
|
|
1849
|
-
// flatten it [[Feature1State, Feature2State], [Feature3State]]
|
|
1850
|
-
const flattenedStates = NgxsFeatureModule.flattenStates(states);
|
|
1851
|
-
// add stores to the state graph and return their defaults
|
|
1852
|
-
const results = factory.addAndReturnDefaults(flattenedStates);
|
|
1853
|
-
if (results.states.length) {
|
|
1854
|
-
internalStateOperations.setStateToTheCurrentWithNew(results);
|
|
1855
|
-
// dispatch the update action and invoke init and bootstrap functions after
|
|
1856
|
-
lifecycleStateManager.ngxsBootstrap(new UpdateState(results.defaults), results);
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
static flattenStates(states = []) {
|
|
1860
|
-
return states.reduce((total, values) => total.concat(values), []);
|
|
1933
|
+
constructor() {
|
|
1934
|
+
featureStatesInitializer();
|
|
1861
1935
|
}
|
|
1862
1936
|
}
|
|
1863
|
-
/** @nocollapse */ NgxsFeatureModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1864
|
-
/** @nocollapse */ NgxsFeatureModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "
|
|
1865
|
-
/** @nocollapse */ NgxsFeatureModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
1866
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
1937
|
+
/** @nocollapse */ NgxsFeatureModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1938
|
+
/** @nocollapse */ NgxsFeatureModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule });
|
|
1939
|
+
/** @nocollapse */ NgxsFeatureModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule });
|
|
1940
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule, decorators: [{
|
|
1867
1941
|
type: NgModule
|
|
1868
|
-
}], ctorParameters: function () { return [
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1942
|
+
}], ctorParameters: function () { return []; } });
|
|
1943
|
+
|
|
1944
|
+
/**
|
|
1945
|
+
* This function provides the required providers when invoking `NgxsModule.forRoot`
|
|
1946
|
+
* or `provideStore`. It is shared between the NgModule and standalone APIs.
|
|
1947
|
+
*/
|
|
1948
|
+
function getRootProviders(states, options) {
|
|
1949
|
+
return [
|
|
1950
|
+
StateFactory,
|
|
1951
|
+
PluginManager,
|
|
1952
|
+
...states,
|
|
1953
|
+
{
|
|
1954
|
+
provide: ROOT_STATE_TOKEN,
|
|
1955
|
+
useValue: states
|
|
1956
|
+
},
|
|
1957
|
+
{
|
|
1958
|
+
provide: APP_BOOTSTRAP_LISTENER,
|
|
1959
|
+
useFactory: () => {
|
|
1960
|
+
const bootstrapper = inject(NgxsBootstrapper);
|
|
1961
|
+
return () => bootstrapper.bootstrap();
|
|
1962
|
+
},
|
|
1963
|
+
multi: true
|
|
1964
|
+
},
|
|
1965
|
+
{
|
|
1966
|
+
provide: NGXS_OPTIONS,
|
|
1967
|
+
useValue: options
|
|
1968
|
+
},
|
|
1969
|
+
{
|
|
1970
|
+
provide: CUSTOM_NGXS_EXECUTION_STRATEGY,
|
|
1971
|
+
useValue: options.executionStrategy
|
|
1972
|
+
},
|
|
1973
|
+
{
|
|
1974
|
+
provide: ɵNGXS_STATE_CONTEXT_FACTORY,
|
|
1975
|
+
useExisting: StateContextFactory
|
|
1976
|
+
},
|
|
1977
|
+
{
|
|
1978
|
+
provide: ɵNGXS_STATE_FACTORY,
|
|
1979
|
+
useExisting: StateFactory
|
|
1980
|
+
}
|
|
1981
|
+
];
|
|
1982
|
+
}
|
|
1874
1983
|
|
|
1875
1984
|
/**
|
|
1876
|
-
*
|
|
1985
|
+
* This function provides the required providers when calling `NgxsModule.forFeature`
|
|
1986
|
+
* or `provideStates`. It is shared between the NgModule and standalone APIs.
|
|
1877
1987
|
*/
|
|
1988
|
+
function getFeatureProviders(states) {
|
|
1989
|
+
return [
|
|
1990
|
+
StateFactory,
|
|
1991
|
+
PluginManager,
|
|
1992
|
+
...states,
|
|
1993
|
+
{
|
|
1994
|
+
provide: FEATURE_STATE_TOKEN,
|
|
1995
|
+
multi: true,
|
|
1996
|
+
useValue: states
|
|
1997
|
+
}
|
|
1998
|
+
];
|
|
1999
|
+
}
|
|
2000
|
+
|
|
1878
2001
|
class NgxsModule {
|
|
1879
|
-
/**
|
|
1880
|
-
* Root module factory
|
|
1881
|
-
*/
|
|
1882
2002
|
static forRoot(states = [], options = {}) {
|
|
1883
2003
|
return {
|
|
1884
2004
|
ngModule: NgxsRootModule,
|
|
1885
|
-
providers:
|
|
1886
|
-
StateFactory,
|
|
1887
|
-
PluginManager,
|
|
1888
|
-
...states,
|
|
1889
|
-
...NgxsModule.ngxsTokenProviders(states, options)
|
|
1890
|
-
]
|
|
2005
|
+
providers: getRootProviders(states, options)
|
|
1891
2006
|
};
|
|
1892
2007
|
}
|
|
1893
|
-
/**
|
|
1894
|
-
* Feature module factory
|
|
1895
|
-
*/
|
|
1896
2008
|
static forFeature(states = []) {
|
|
1897
2009
|
return {
|
|
1898
2010
|
ngModule: NgxsFeatureModule,
|
|
1899
|
-
providers:
|
|
1900
|
-
// This is required on the feature level, see comments in `state-factory.ts`.
|
|
1901
|
-
StateFactory,
|
|
1902
|
-
PluginManager,
|
|
1903
|
-
...states,
|
|
1904
|
-
{
|
|
1905
|
-
provide: FEATURE_STATE_TOKEN,
|
|
1906
|
-
multi: true,
|
|
1907
|
-
useValue: states
|
|
1908
|
-
}
|
|
1909
|
-
]
|
|
2011
|
+
providers: getFeatureProviders(states)
|
|
1910
2012
|
};
|
|
1911
2013
|
}
|
|
1912
|
-
static ngxsTokenProviders(states, options) {
|
|
1913
|
-
return [
|
|
1914
|
-
{
|
|
1915
|
-
provide: USER_PROVIDED_NGXS_EXECUTION_STRATEGY,
|
|
1916
|
-
useValue: options.executionStrategy
|
|
1917
|
-
},
|
|
1918
|
-
{
|
|
1919
|
-
provide: ROOT_STATE_TOKEN,
|
|
1920
|
-
useValue: states
|
|
1921
|
-
},
|
|
1922
|
-
{
|
|
1923
|
-
provide: ROOT_OPTIONS,
|
|
1924
|
-
useValue: options
|
|
1925
|
-
},
|
|
1926
|
-
{
|
|
1927
|
-
provide: APP_BOOTSTRAP_LISTENER,
|
|
1928
|
-
useFactory: NgxsModule.appBootstrapListenerFactory,
|
|
1929
|
-
multi: true,
|
|
1930
|
-
deps: [NgxsBootstrapper]
|
|
1931
|
-
},
|
|
1932
|
-
{
|
|
1933
|
-
provide: ɵNGXS_STATE_CONTEXT_FACTORY,
|
|
1934
|
-
useExisting: StateContextFactory
|
|
1935
|
-
},
|
|
1936
|
-
{
|
|
1937
|
-
provide: ɵNGXS_STATE_FACTORY,
|
|
1938
|
-
useExisting: StateFactory
|
|
1939
|
-
}
|
|
1940
|
-
];
|
|
1941
|
-
}
|
|
1942
|
-
static appBootstrapListenerFactory(bootstrapper) {
|
|
1943
|
-
return () => bootstrapper.bootstrap();
|
|
1944
|
-
}
|
|
1945
2014
|
}
|
|
1946
|
-
/** @nocollapse */ NgxsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
1947
|
-
/** @nocollapse */ NgxsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "
|
|
1948
|
-
/** @nocollapse */ NgxsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
1949
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
2015
|
+
/** @nocollapse */ NgxsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
2016
|
+
/** @nocollapse */ NgxsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule });
|
|
2017
|
+
/** @nocollapse */ NgxsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule });
|
|
2018
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule, decorators: [{
|
|
1950
2019
|
type: NgModule
|
|
1951
2020
|
}] });
|
|
1952
2021
|
|
|
@@ -1996,7 +2065,7 @@ function State(options) {
|
|
|
1996
2065
|
}
|
|
1997
2066
|
function getStateOptions(inheritedStateClass, options) {
|
|
1998
2067
|
const inheritanceOptions = inheritedStateClass[META_OPTIONS_KEY] || {};
|
|
1999
|
-
return
|
|
2068
|
+
return { ...inheritanceOptions, ...options };
|
|
2000
2069
|
}
|
|
2001
2070
|
function mutateMetaData(params) {
|
|
2002
2071
|
const { meta, inheritedStateClass, optionsWithInheritance } = params;
|
|
@@ -2007,7 +2076,7 @@ function mutateMetaData(params) {
|
|
|
2007
2076
|
}
|
|
2008
2077
|
if (inheritedStateClass.hasOwnProperty(META_KEY)) {
|
|
2009
2078
|
const inheritedMeta = inheritedStateClass[META_KEY] || {};
|
|
2010
|
-
meta.actions =
|
|
2079
|
+
meta.actions = { ...meta.actions, ...inheritedMeta.actions };
|
|
2011
2080
|
}
|
|
2012
2081
|
meta.children = children;
|
|
2013
2082
|
meta.defaults = defaults;
|
|
@@ -2086,12 +2155,17 @@ function setupSelectorMetadata(originalFn, creationMetadata) {
|
|
|
2086
2155
|
getExplicitSelectorOptions =
|
|
2087
2156
|
creationMetadata.getSelectorOptions || getExplicitSelectorOptions;
|
|
2088
2157
|
}
|
|
2089
|
-
const selectorMetaDataClone =
|
|
2158
|
+
const selectorMetaDataClone = { ...selectorMetaData };
|
|
2090
2159
|
selectorMetaData.getSelectorOptions = () => getLocalSelectorOptions(selectorMetaDataClone, getExplicitSelectorOptions());
|
|
2091
2160
|
return selectorMetaData;
|
|
2092
2161
|
}
|
|
2093
2162
|
function getLocalSelectorOptions(selectorMetaData, explicitOptions) {
|
|
2094
|
-
return
|
|
2163
|
+
return {
|
|
2164
|
+
...(selectorOptionsMetaAccessor.getOptions(selectorMetaData.containerClass) || {}),
|
|
2165
|
+
...(selectorOptionsMetaAccessor.getOptions(selectorMetaData.originalFn) || {}),
|
|
2166
|
+
...(selectorMetaData.getSelectorOptions() || {}),
|
|
2167
|
+
...explicitOptions,
|
|
2168
|
+
};
|
|
2095
2169
|
}
|
|
2096
2170
|
|
|
2097
2171
|
/**
|
|
@@ -2137,7 +2211,7 @@ function createSelector(selectors, projector, creationMetadata) {
|
|
|
2137
2211
|
function Selector(selectors) {
|
|
2138
2212
|
return (target, key, descriptor) => {
|
|
2139
2213
|
descriptor || (descriptor = Object.getOwnPropertyDescriptor(target, key));
|
|
2140
|
-
const originalFn = descriptor
|
|
2214
|
+
const originalFn = descriptor?.value;
|
|
2141
2215
|
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
2142
2216
|
// creating a breaking change for projects that still use the View Engine.
|
|
2143
2217
|
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
@@ -2191,10 +2265,10 @@ class NgxsDevelopmentModule {
|
|
|
2191
2265
|
};
|
|
2192
2266
|
}
|
|
2193
2267
|
}
|
|
2194
|
-
/** @nocollapse */ NgxsDevelopmentModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "
|
|
2195
|
-
/** @nocollapse */ NgxsDevelopmentModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "
|
|
2196
|
-
/** @nocollapse */ NgxsDevelopmentModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "
|
|
2197
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "
|
|
2268
|
+
/** @nocollapse */ NgxsDevelopmentModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
2269
|
+
/** @nocollapse */ NgxsDevelopmentModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule });
|
|
2270
|
+
/** @nocollapse */ NgxsDevelopmentModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule });
|
|
2271
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule, decorators: [{
|
|
2198
2272
|
type: NgModule
|
|
2199
2273
|
}] });
|
|
2200
2274
|
|
|
@@ -2268,13 +2342,77 @@ function createPropertySelectors(parentSelector) {
|
|
|
2268
2342
|
return new Proxy({}, {
|
|
2269
2343
|
get(_target, prop) {
|
|
2270
2344
|
const selector = cache[prop] ||
|
|
2271
|
-
createSelector([parentSelector], (s) => s
|
|
2345
|
+
createSelector([parentSelector], (s) => s?.[prop]);
|
|
2272
2346
|
cache[prop] = selector;
|
|
2273
2347
|
return selector;
|
|
2274
2348
|
}
|
|
2275
2349
|
});
|
|
2276
2350
|
}
|
|
2277
2351
|
|
|
2352
|
+
function provideStore(states = [], ...optionsAndFeatures) {
|
|
2353
|
+
const features = [];
|
|
2354
|
+
// Options are empty by default (see `forRoot`).
|
|
2355
|
+
let options = {};
|
|
2356
|
+
if (optionsAndFeatures.length > 0) {
|
|
2357
|
+
if (isEnvironmentProvider(optionsAndFeatures[0])) {
|
|
2358
|
+
features.push(...optionsAndFeatures);
|
|
2359
|
+
}
|
|
2360
|
+
else {
|
|
2361
|
+
options = optionsAndFeatures[0];
|
|
2362
|
+
features.push(...optionsAndFeatures.slice(1));
|
|
2363
|
+
}
|
|
2364
|
+
}
|
|
2365
|
+
return makeEnvironmentProviders([
|
|
2366
|
+
...getRootProviders(states, options),
|
|
2367
|
+
features,
|
|
2368
|
+
NGXS_ROOT_ENVIRONMENT_INITIALIZER
|
|
2369
|
+
]);
|
|
2370
|
+
}
|
|
2371
|
+
function isEnvironmentProvider(target) {
|
|
2372
|
+
return !!target.ɵproviders;
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
/**
|
|
2376
|
+
* This version serves as a standalone alternative to `NgxsModule.forFeature`.
|
|
2377
|
+
* It can be used in a similar manner to register feature states, but at the
|
|
2378
|
+
* `Route` providers level:
|
|
2379
|
+
*
|
|
2380
|
+
* ```ts
|
|
2381
|
+
* const routes: Routes = [
|
|
2382
|
+
* {
|
|
2383
|
+
* path: 'products',
|
|
2384
|
+
* loadComponent: async () => {...},
|
|
2385
|
+
* providers: [provideStates([ProductsState])]
|
|
2386
|
+
* }
|
|
2387
|
+
* ];
|
|
2388
|
+
* ```
|
|
2389
|
+
*/
|
|
2390
|
+
function provideStates(states, ...features) {
|
|
2391
|
+
return makeEnvironmentProviders([
|
|
2392
|
+
...getFeatureProviders(states),
|
|
2393
|
+
features,
|
|
2394
|
+
NGXS_FEATURE_ENVIRONMENT_INITIALIZER
|
|
2395
|
+
]);
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
/**
|
|
2399
|
+
* This function registers a custom global plugin for the state.
|
|
2400
|
+
*
|
|
2401
|
+
* ```ts
|
|
2402
|
+
* bootstrapApplication(AppComponent, {
|
|
2403
|
+
* providers: [
|
|
2404
|
+
* provideStore(
|
|
2405
|
+
* [CountriesState],
|
|
2406
|
+
* withNgxsPlugin(logoutPlugin)
|
|
2407
|
+
* )
|
|
2408
|
+
* ]
|
|
2409
|
+
* });
|
|
2410
|
+
* ```
|
|
2411
|
+
*/
|
|
2412
|
+
function withNgxsPlugin(plugin) {
|
|
2413
|
+
return makeEnvironmentProviders([{ provide: NGXS_PLUGINS, useClass: plugin, multi: true }]);
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2278
2416
|
/**
|
|
2279
2417
|
* The public api for consumers of @ngxs/store
|
|
2280
2418
|
*/
|
|
@@ -2283,5 +2421,5 @@ function createPropertySelectors(parentSelector) {
|
|
|
2283
2421
|
* Generated bundle index. Do not edit.
|
|
2284
2422
|
*/
|
|
2285
2423
|
|
|
2286
|
-
export { Action, Actions, InitState, NGXS_PLUGINS, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, StateStream, StateToken, Store, UpdateState, actionMatcher, createModelSelector, createPickSelector, createPropertySelectors, createSelector, ensureSelectorMetadata, ensureStoreMetadata, getActionTypeFromInstance, getSelectorMetadata, getStoreMetadata, getValue, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, setValue, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule };
|
|
2287
|
-
//# sourceMappingURL=ngxs-store.
|
|
2424
|
+
export { Action, Actions, InitState, NGXS_PLUGINS, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NoopNgxsExecutionStrategy, Select, Selector, SelectorOptions, State, StateStream, StateToken, Store, UpdateState, actionMatcher, createModelSelector, createPickSelector, createPropertySelectors, createSelector, ensureSelectorMetadata, ensureStoreMetadata, getActionTypeFromInstance, getSelectorMetadata, getStoreMetadata, getValue, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, setValue, withNgxsPlugin, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule };
|
|
2425
|
+
//# sourceMappingURL=ngxs-store.mjs.map
|