@ngxs/store 3.8.2-dev.master-0fd1fe5 → 3.8.2
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/bundles/ngxs-store-internals-testing.umd.js +684 -0
- package/bundles/ngxs-store-internals-testing.umd.js.map +1 -0
- package/bundles/ngxs-store-internals.umd.js +141 -0
- package/bundles/ngxs-store-internals.umd.js.map +1 -0
- package/bundles/ngxs-store-operators.umd.js +224 -0
- package/bundles/ngxs-store-operators.umd.js.map +1 -0
- package/bundles/ngxs-store.umd.js +3076 -0
- package/bundles/ngxs-store.umd.js.map +1 -0
- package/esm2015/internals/index.js +5 -0
- package/esm2015/internals/initial-state.js +17 -0
- package/esm2015/internals/internal-tokens.js +5 -0
- package/{esm2020/internals/ngxs-bootstrapper.mjs → esm2015/internals/ngxs-bootstrapper.js} +4 -4
- package/esm2015/internals/src/symbols.js +2 -0
- package/esm2015/internals/symbols.js +2 -0
- package/esm2015/internals/testing/fresh-platform.js +70 -0
- package/{esm2020/internals/testing/helpers/ngxs-test.component.mjs → esm2015/internals/testing/helpers/ngxs-test.component.js} +4 -4
- package/esm2015/internals/testing/helpers/ngxs-test.module.js +21 -0
- package/{esm2020/internals/testing/ngxs.setup.mjs → esm2015/internals/testing/ngxs.setup.js} +2 -4
- package/esm2015/internals/testing/symbol.js +2 -0
- package/esm2015/operators/patch.js +21 -0
- package/{esm2020/src/actions-stream.mjs → esm2015/src/actions-stream.js} +7 -7
- package/esm2015/src/configs/messages.config.js +36 -0
- package/{esm2020/src/decorators/select/select-factory.mjs → esm2015/src/decorators/select/select-factory.js} +4 -4
- package/esm2015/src/decorators/selector/selector.js +32 -0
- package/esm2015/src/decorators/state.js +36 -0
- package/{esm2020/src/dev-features/ngxs-development.module.mjs → esm2015/src/dev-features/ngxs-development.module.js} +5 -5
- package/{esm2020/src/dev-features/ngxs-unhandled-actions-logger.mjs → esm2015/src/dev-features/ngxs-unhandled-actions-logger.js} +4 -4
- package/{esm2020/src/execution/dispatch-outside-zone-ngxs-execution-strategy.mjs → esm2015/src/execution/dispatch-outside-zone-ngxs-execution-strategy.js} +4 -4
- package/{esm2020/src/execution/internal-ngxs-execution-strategy.mjs → esm2015/src/execution/internal-ngxs-execution-strategy.js} +4 -4
- package/{esm2020/src/execution/noop-ngxs-execution-strategy.mjs → esm2015/src/execution/noop-ngxs-execution-strategy.js} +4 -4
- package/esm2015/src/execution/symbols.js +23 -0
- package/{esm2020/src/internal/dispatcher.mjs → esm2015/src/internal/dispatcher.js} +11 -11
- package/{esm2020/src/internal/error-handler.mjs → esm2015/src/internal/error-handler.js} +5 -5
- package/esm2015/src/internal/internals.js +248 -0
- package/esm2015/src/internal/lifecycle-state-manager.js +79 -0
- package/{esm2020/src/internal/state-context-factory.mjs → esm2015/src/internal/state-context-factory.js} +4 -4
- package/esm2015/src/internal/state-factory.js +288 -0
- package/{esm2020/src/internal/state-operations.mjs → esm2015/src/internal/state-operations.js} +5 -5
- package/esm2015/src/internal/state-operators.js +20 -0
- package/esm2015/src/internal/state-stream.js +25 -0
- package/{esm2020/src/ivy/ivy-enabled-in-dev-mode.mjs → esm2015/src/ivy/ivy-enabled-in-dev-mode.js} +2 -2
- package/esm2015/src/module.js +88 -0
- package/esm2015/src/modules/ngxs-feature.module.js +45 -0
- package/esm2015/src/modules/ngxs-root.module.js +41 -0
- package/{esm2020/src/operators/of-action.mjs → esm2015/src/operators/of-action.js} +10 -10
- package/{esm2020/src/plugin-manager.mjs → esm2015/src/plugin-manager.js} +4 -4
- package/esm2015/src/public_api.js +27 -0
- package/esm2015/src/selectors/create-property-selectors.js +20 -0
- package/esm2015/src/selectors/selector-metadata.js +30 -0
- package/esm2015/src/selectors/selector-types.util.js +2 -0
- package/{esm2020/src/store.mjs → esm2015/src/store.js} +5 -6
- package/esm2015/src/symbols.js +58 -0
- package/esm2015/src/utils/utils.js +92 -0
- package/fesm2015/{ngxs-store-internals-testing.mjs → ngxs-store-internals-testing.js} +13 -19
- package/fesm2015/ngxs-store-internals-testing.js.map +1 -0
- package/{fesm2020/ngxs-store-internals.mjs → fesm2015/ngxs-store-internals.js} +8 -21
- package/fesm2015/ngxs-store-internals.js.map +1 -0
- package/fesm2015/{ngxs-store-operators.mjs → ngxs-store-operators.js} +1 -1
- package/fesm2015/ngxs-store-operators.js.map +1 -0
- package/{fesm2020/ngxs-store.mjs → fesm2015/ngxs-store.js} +1029 -1192
- package/fesm2015/ngxs-store.js.map +1 -0
- package/internals/index.d.ts +1 -1
- package/internals/initial-state.d.ts +1 -1
- package/internals/ngxs-store-internals.d.ts +5 -0
- package/internals/package.json +10 -0
- package/internals/src/symbols.d.ts +1 -4
- package/internals/symbols.d.ts +1 -4
- package/internals/testing/helpers/ngxs-test.component.d.ts +1 -1
- package/internals/testing/ngxs-store-internals-testing.d.ts +5 -0
- package/internals/testing/package.json +10 -0
- package/internals/testing/symbol.d.ts +2 -2
- package/ngxs-store.d.ts +5 -0
- package/operators/ngxs-store-operators.d.ts +5 -0
- package/operators/package.json +10 -0
- package/package.json +11 -48
- package/src/configs/messages.config.d.ts +0 -2
- package/src/decorators/state.d.ts +2 -2
- package/src/execution/symbols.d.ts +2 -8
- package/src/internal/internals.d.ts +5 -5
- package/src/internal/lifecycle-state-manager.d.ts +1 -3
- package/src/module.d.ts +14 -3
- package/src/modules/ngxs-feature.module.d.ts +9 -2
- package/src/modules/ngxs-root.module.d.ts +9 -2
- package/src/public_api.d.ts +4 -5
- package/src/selectors/selector-types.util.d.ts +3 -3
- package/src/symbols.d.ts +8 -5
- package/esm2020/internals/index.mjs +0 -6
- package/esm2020/internals/initial-state.mjs +0 -18
- package/esm2020/internals/internal-tokens.mjs +0 -6
- package/esm2020/internals/src/symbols.mjs +0 -11
- package/esm2020/internals/symbols.mjs +0 -11
- package/esm2020/internals/testing/fresh-platform.mjs +0 -72
- package/esm2020/internals/testing/helpers/ngxs-test.module.mjs +0 -20
- package/esm2020/internals/testing/symbol.mjs +0 -2
- package/esm2020/operators/patch.mjs +0 -21
- package/esm2020/src/configs/messages.config.mjs +0 -48
- package/esm2020/src/decorators/selector/selector.mjs +0 -32
- package/esm2020/src/decorators/state.mjs +0 -36
- package/esm2020/src/execution/symbols.mjs +0 -27
- package/esm2020/src/internal/internals.mjs +0 -248
- package/esm2020/src/internal/lifecycle-state-manager.mjs +0 -97
- package/esm2020/src/internal/state-factory.mjs +0 -292
- package/esm2020/src/internal/state-operators.mjs +0 -20
- package/esm2020/src/internal/state-stream.mjs +0 -27
- package/esm2020/src/module.mjs +0 -27
- package/esm2020/src/modules/ngxs-feature.module.mjs +0 -18
- package/esm2020/src/modules/ngxs-root.module.mjs +0 -18
- package/esm2020/src/public_api.mjs +0 -28
- package/esm2020/src/selectors/create-property-selectors.mjs +0 -20
- package/esm2020/src/selectors/selector-metadata.mjs +0 -35
- package/esm2020/src/selectors/selector-types.util.mjs +0 -2
- package/esm2020/src/standalone-features/feature-providers.mjs +0 -20
- package/esm2020/src/standalone-features/index.mjs +0 -4
- package/esm2020/src/standalone-features/initializers.mjs +0 -86
- package/esm2020/src/standalone-features/plugin.mjs +0 -20
- package/esm2020/src/standalone-features/provide-states.mjs +0 -26
- package/esm2020/src/standalone-features/provide-store.mjs +0 -26
- package/esm2020/src/standalone-features/root-providers.mjs +0 -47
- package/esm2020/src/symbols.mjs +0 -65
- package/esm2020/src/utils/utils.mjs +0 -92
- package/fesm2015/ngxs-store-internals-testing.mjs.map +0 -1
- package/fesm2015/ngxs-store-internals.mjs +0 -114
- package/fesm2015/ngxs-store-internals.mjs.map +0 -1
- package/fesm2015/ngxs-store-operators.mjs.map +0 -1
- package/fesm2015/ngxs-store.mjs +0 -2454
- package/fesm2015/ngxs-store.mjs.map +0 -1
- package/fesm2020/ngxs-store-internals-testing.mjs +0 -180
- package/fesm2020/ngxs-store-internals-testing.mjs.map +0 -1
- package/fesm2020/ngxs-store-internals.mjs.map +0 -1
- package/fesm2020/ngxs-store-operators.mjs +0 -202
- package/fesm2020/ngxs-store-operators.mjs.map +0 -1
- package/fesm2020/ngxs-store.mjs.map +0 -1
- package/schematics/collection.json +0 -36
- package/schematics/src/actions/actions.factory.d.ts +0 -3
- package/schematics/src/actions/actions.factory.js +0 -22
- package/schematics/src/actions/actions.factory.js.map +0 -1
- package/schematics/src/actions/files/__name__.actions.ts__template__ +0 -4
- package/schematics/src/actions/schema.json +0 -28
- package/schematics/src/ng-add/add-declaration.d.ts +0 -4
- package/schematics/src/ng-add/add-declaration.js +0 -109
- package/schematics/src/ng-add/add-declaration.js.map +0 -1
- package/schematics/src/ng-add/ng-add.factory.d.ts +0 -9
- package/schematics/src/ng-add/ng-add.factory.js +0 -86
- package/schematics/src/ng-add/ng-add.factory.js.map +0 -1
- package/schematics/src/ng-add/schema.json +0 -72
- package/schematics/src/starter-kit/files/store/auth/auth.actions.ts__template__ +0 -7
- package/schematics/src/starter-kit/files/store/auth/auth.state.spec.ts__template__ +0 -46
- package/schematics/src/starter-kit/files/store/auth/auth.state.ts__template__ +0 -45
- package/schematics/src/starter-kit/files/store/dashboard/index.ts__template__ +0 -11
- package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.actions.ts__template__ +0 -13
- package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.spec.ts__template__ +0 -77
- package/schematics/src/starter-kit/files/store/dashboard/states/dictionary/dictionary.state.ts__template__ +0 -60
- package/schematics/src/starter-kit/files/store/dashboard/states/user/user.actions.ts__template__ +0 -6
- package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.spec.ts__template__ +0 -54
- package/schematics/src/starter-kit/files/store/dashboard/states/user/user.state.ts__template__ +0 -40
- package/schematics/src/starter-kit/files/store/store.config.ts__template__ +0 -38
- package/schematics/src/starter-kit/files/store/store.module.ts__template__ +0 -22
- package/schematics/src/starter-kit/schema.json +0 -18
- package/schematics/src/starter-kit/starter-kit.factory.d.ts +0 -3
- package/schematics/src/starter-kit/starter-kit.factory.js +0 -12
- package/schematics/src/starter-kit/starter-kit.factory.js.map +0 -1
- package/schematics/src/state/files/__name__.state.spec.ts__template__ +0 -22
- package/schematics/src/state/files/__name__.state.ts__template__ +0 -20
- package/schematics/src/state/schema.json +0 -33
- package/schematics/src/state/state.factory.d.ts +0 -3
- package/schematics/src/state/state.factory.js +0 -20
- package/schematics/src/state/state.factory.js.map +0 -1
- package/schematics/src/store/files/__name__.actions.ts__template__ +0 -4
- package/schematics/src/store/files/__name__.state.spec.ts__template__ +0 -24
- package/schematics/src/store/files/__name__.state.ts__template__ +0 -27
- package/schematics/src/store/schema.json +0 -33
- package/schematics/src/store/store.factory.d.ts +0 -3
- package/schematics/src/store/store.factory.js +0 -20
- package/schematics/src/store/store.factory.js.map +0 -1
- package/schematics/src/utils/common/lib.config.d.ts +0 -10
- package/schematics/src/utils/common/lib.config.js +0 -15
- package/schematics/src/utils/common/lib.config.js.map +0 -1
- package/schematics/src/utils/common/project-files.config.d.ts +0 -3
- package/schematics/src/utils/common/project-files.config.js +0 -7
- package/schematics/src/utils/common/project-files.config.js.map +0 -1
- package/schematics/src/utils/common/properties.d.ts +0 -1
- package/schematics/src/utils/common/properties.js +0 -8
- package/schematics/src/utils/common/properties.js.map +0 -1
- package/schematics/src/utils/config.d.ts +0 -119
- package/schematics/src/utils/config.js +0 -21
- package/schematics/src/utils/config.js.map +0 -1
- package/schematics/src/utils/generate-utils.d.ts +0 -4
- package/schematics/src/utils/generate-utils.js +0 -14
- package/schematics/src/utils/generate-utils.js.map +0 -1
- package/schematics/src/utils/interfaces/package.interface.d.ts +0 -7
- package/schematics/src/utils/interfaces/package.interface.js +0 -3
- package/schematics/src/utils/interfaces/package.interface.js.map +0 -1
- package/schematics/src/utils/ng-utils/README.md +0 -1
- package/schematics/src/utils/ng-utils/ast-utils.d.ts +0 -99
- package/schematics/src/utils/ng-utils/ast-utils.js +0 -517
- package/schematics/src/utils/ng-utils/ast-utils.js.map +0 -1
- package/schematics/src/utils/ng-utils/ng-ast-utils.d.ts +0 -5
- package/schematics/src/utils/ng-utils/ng-ast-utils.js +0 -67
- package/schematics/src/utils/ng-utils/ng-ast-utils.js.map +0 -1
- package/schematics/src/utils/ng-utils/project.d.ts +0 -2
- package/schematics/src/utils/ng-utils/project.js +0 -21
- package/schematics/src/utils/ng-utils/project.js.map +0 -1
- package/schematics/src/utils/ng-utils/standalone/app_config.d.ts +0 -16
- package/schematics/src/utils/ng-utils/standalone/app_config.js +0 -84
- package/schematics/src/utils/ng-utils/standalone/app_config.js.map +0 -1
- package/schematics/src/utils/ng-utils/standalone/code_block.d.ts +0 -46
- package/schematics/src/utils/ng-utils/standalone/code_block.js +0 -73
- package/schematics/src/utils/ng-utils/standalone/code_block.js.map +0 -1
- package/schematics/src/utils/ng-utils/standalone/index.d.ts +0 -1
- package/schematics/src/utils/ng-utils/standalone/index.js +0 -7
- package/schematics/src/utils/ng-utils/standalone/index.js.map +0 -1
- package/schematics/src/utils/ng-utils/standalone/rules.d.ts +0 -38
- package/schematics/src/utils/ng-utils/standalone/rules.js +0 -195
- package/schematics/src/utils/ng-utils/standalone/rules.js.map +0 -1
- package/schematics/src/utils/ng-utils/standalone/util.d.ts +0 -28
- package/schematics/src/utils/ng-utils/standalone/util.js +0 -138
- package/schematics/src/utils/ng-utils/standalone/util.js.map +0 -1
- package/schematics/src/utils/normalize-options.d.ts +0 -9
- package/schematics/src/utils/normalize-options.js +0 -24
- package/schematics/src/utils/normalize-options.js.map +0 -1
- package/schematics/src/utils/project.d.ts +0 -16
- package/schematics/src/utils/project.js +0 -40
- package/schematics/src/utils/project.js.map +0 -1
- package/schematics/src/utils/versions.json +0 -3
- package/src/standalone-features/feature-providers.d.ts +0 -7
- package/src/standalone-features/index.d.ts +0 -3
- package/src/standalone-features/initializers.d.ts +0 -29
- package/src/standalone-features/plugin.d.ts +0 -17
- package/src/standalone-features/provide-states.d.ts +0 -18
- package/src/standalone-features/provide-store.d.ts +0 -22
- package/src/standalone-features/root-providers.d.ts +0 -8
- /package/{esm2020/index.mjs → esm2015/index.js} +0 -0
- /package/{esm2020/internals/memoize.mjs → esm2015/internals/memoize.js} +0 -0
- /package/{esm2020/internals/ngxs-store-internals.mjs → esm2015/internals/ngxs-store-internals.js} +0 -0
- /package/{esm2020/internals/testing/index.mjs → esm2015/internals/testing/index.js} +0 -0
- /package/{esm2020/internals/testing/ngxs-store-internals-testing.mjs → esm2015/internals/testing/ngxs-store-internals-testing.js} +0 -0
- /package/{esm2020/internals/testing/skip-console-logging.mjs → esm2015/internals/testing/skip-console-logging.js} +0 -0
- /package/{esm2020/ngxs-store.mjs → esm2015/ngxs-store.js} +0 -0
- /package/{esm2020/operators/append.mjs → esm2015/operators/append.js} +0 -0
- /package/{esm2020/operators/compose.mjs → esm2015/operators/compose.js} +0 -0
- /package/{esm2020/operators/iif.mjs → esm2015/operators/iif.js} +0 -0
- /package/{esm2020/operators/index.mjs → esm2015/operators/index.js} +0 -0
- /package/{esm2020/operators/insert-item.mjs → esm2015/operators/insert-item.js} +0 -0
- /package/{esm2020/operators/ngxs-store-operators.mjs → esm2015/operators/ngxs-store-operators.js} +0 -0
- /package/{esm2020/operators/remove-item.mjs → esm2015/operators/remove-item.js} +0 -0
- /package/{esm2020/operators/types.mjs → esm2015/operators/types.js} +0 -0
- /package/{esm2020/operators/update-item.mjs → esm2015/operators/update-item.js} +0 -0
- /package/{esm2020/operators/utils.mjs → esm2015/operators/utils.js} +0 -0
- /package/{esm2020/src/actions/actions.mjs → esm2015/src/actions/actions.js} +0 -0
- /package/{esm2020/src/actions/symbols.mjs → esm2015/src/actions/symbols.js} +0 -0
- /package/{esm2020/src/decorators/action.mjs → esm2015/src/decorators/action.js} +0 -0
- /package/{esm2020/src/decorators/select/select.mjs → esm2015/src/decorators/select/select.js} +0 -0
- /package/{esm2020/src/decorators/select/symbols.mjs → esm2015/src/decorators/select/symbols.js} +0 -0
- /package/{esm2020/src/decorators/selector/symbols.mjs → esm2015/src/decorators/selector/symbols.js} +0 -0
- /package/{esm2020/src/decorators/selector-options.mjs → esm2015/src/decorators/selector-options.js} +0 -0
- /package/{esm2020/src/dev-features/symbols.mjs → esm2015/src/dev-features/symbols.js} +0 -0
- /package/{esm2020/src/internal/custom-rxjs-subjects.mjs → esm2015/src/internal/custom-rxjs-subjects.js} +0 -0
- /package/{esm2020/src/operators/leave-ngxs.mjs → esm2015/src/operators/leave-ngxs.js} +0 -0
- /package/{esm2020/src/plugin_api.mjs → esm2015/src/plugin_api.js} +0 -0
- /package/{esm2020/src/private_api.mjs → esm2015/src/private_api.js} +0 -0
- /package/{esm2020/src/public_to_deprecate.mjs → esm2015/src/public_to_deprecate.js} +0 -0
- /package/{esm2020/src/selectors/create-model-selector.mjs → esm2015/src/selectors/create-model-selector.js} +0 -0
- /package/{esm2020/src/selectors/create-pick-selector.mjs → esm2015/src/selectors/create-pick-selector.js} +0 -0
- /package/{esm2020/src/selectors/create-selector.mjs → esm2015/src/selectors/create-selector.js} +0 -0
- /package/{esm2020/src/selectors/index.mjs → esm2015/src/selectors/index.js} +0 -0
- /package/{esm2020/src/selectors/selector-checks.util.mjs → esm2015/src/selectors/selector-checks.util.js} +0 -0
- /package/{esm2020/src/selectors/selector-models.mjs → esm2015/src/selectors/selector-models.js} +0 -0
- /package/{esm2020/src/selectors/selector-utils.mjs → esm2015/src/selectors/selector-utils.js} +0 -0
- /package/{esm2020/src/state-token/state-token.mjs → esm2015/src/state-token/state-token.js} +0 -0
- /package/{esm2020/src/state-token/symbols.mjs → esm2015/src/state-token/symbols.js} +0 -0
- /package/{esm2020/src/utils/compose.mjs → esm2015/src/utils/compose.js} +0 -0
- /package/{esm2020/src/utils/freeze.mjs → esm2015/src/utils/freeze.js} +0 -0
- /package/{esm2020/src/utils/store-validators.mjs → esm2015/src/utils/store-validators.js} +0 -0
package/fesm2015/ngxs-store.mjs
DELETED
|
@@ -1,2454 +0,0 @@
|
|
|
1
|
-
import * as i0 from '@angular/core';
|
|
2
|
-
import { Injectable, ErrorHandler, NgZone, PLATFORM_ID, Inject, InjectionToken, inject, INJECTOR, ɵglobal, Optional, SkipSelf, ENVIRONMENT_INITIALIZER, NgModule, APP_BOOTSTRAP_LISTENER, makeEnvironmentProviders } from '@angular/core';
|
|
3
|
-
import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable, ReplaySubject } from 'rxjs';
|
|
4
|
-
import { share, shareReplay, filter, take, exhaustMap, map, mergeMap, defaultIfEmpty, catchError, takeUntil, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
|
|
5
|
-
import * as i5 from '@ngxs/store/internals';
|
|
6
|
-
import { ɵMETA_KEY, ɵSELECTOR_META_KEY, memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY, ɵMETA_OPTIONS_KEY } from '@ngxs/store/internals';
|
|
7
|
-
import { isPlatformServer } from '@angular/common';
|
|
8
|
-
import { isStateOperator } from '@ngxs/store/operators';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Ensures metadata is attached to the class and returns it.
|
|
12
|
-
*
|
|
13
|
-
* @ignore
|
|
14
|
-
*/
|
|
15
|
-
function ensureStoreMetadata$1(target) {
|
|
16
|
-
if (!target.hasOwnProperty(ɵMETA_KEY)) {
|
|
17
|
-
const defaultMetadata = {
|
|
18
|
-
name: null,
|
|
19
|
-
actions: {},
|
|
20
|
-
defaults: {},
|
|
21
|
-
path: null,
|
|
22
|
-
makeRootSelector(context) {
|
|
23
|
-
return context.getStateGetter(defaultMetadata.name);
|
|
24
|
-
},
|
|
25
|
-
children: []
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(target, ɵMETA_KEY, { value: defaultMetadata });
|
|
28
|
-
}
|
|
29
|
-
return getStoreMetadata$1(target);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Get the metadata attached to the state class if it exists.
|
|
33
|
-
*
|
|
34
|
-
* @ignore
|
|
35
|
-
*/
|
|
36
|
-
function getStoreMetadata$1(target) {
|
|
37
|
-
return target[ɵMETA_KEY];
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Ensures metadata is attached to the selector and returns it.
|
|
41
|
-
*
|
|
42
|
-
* @ignore
|
|
43
|
-
*/
|
|
44
|
-
function ensureSelectorMetadata$1(target) {
|
|
45
|
-
if (!target.hasOwnProperty(ɵSELECTOR_META_KEY)) {
|
|
46
|
-
const defaultMetadata = {
|
|
47
|
-
makeRootSelector: null,
|
|
48
|
-
originalFn: null,
|
|
49
|
-
containerClass: null,
|
|
50
|
-
selectorName: null,
|
|
51
|
-
getSelectorOptions: () => ({})
|
|
52
|
-
};
|
|
53
|
-
Object.defineProperty(target, ɵSELECTOR_META_KEY, { value: defaultMetadata });
|
|
54
|
-
}
|
|
55
|
-
return getSelectorMetadata$1(target);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Get the metadata attached to the selector if it exists.
|
|
59
|
-
*
|
|
60
|
-
* @ignore
|
|
61
|
-
*/
|
|
62
|
-
function getSelectorMetadata$1(target) {
|
|
63
|
-
return target[ɵSELECTOR_META_KEY];
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Get a deeply nested value. Example:
|
|
67
|
-
*
|
|
68
|
-
* getValue({ foo: bar: [] }, 'foo.bar') //=> []
|
|
69
|
-
*
|
|
70
|
-
* Note: This is not as fast as the `fastPropGetter` but is strict Content Security Policy compliant.
|
|
71
|
-
* See perf hit: https://jsperf.com/fast-value-getter-given-path/1
|
|
72
|
-
*
|
|
73
|
-
* @ignore
|
|
74
|
-
*/
|
|
75
|
-
function compliantPropGetter(paths) {
|
|
76
|
-
const copyOfPaths = paths.slice();
|
|
77
|
-
return obj => copyOfPaths.reduce((acc, part) => acc && acc[part], obj);
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* The generated function is faster than:
|
|
81
|
-
* - pluck (Observable operator)
|
|
82
|
-
* - memoize
|
|
83
|
-
*
|
|
84
|
-
* @ignore
|
|
85
|
-
*/
|
|
86
|
-
function fastPropGetter(paths) {
|
|
87
|
-
const segments = paths;
|
|
88
|
-
let seg = 'store.' + segments[0];
|
|
89
|
-
let i = 0;
|
|
90
|
-
const l = segments.length;
|
|
91
|
-
let expr = seg;
|
|
92
|
-
while (++i < l) {
|
|
93
|
-
expr = expr + ' && ' + (seg = seg + '.' + segments[i]);
|
|
94
|
-
}
|
|
95
|
-
const fn = new Function('store', 'return ' + expr + ';');
|
|
96
|
-
return fn;
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Get a deeply nested value. Example:
|
|
100
|
-
*
|
|
101
|
-
* getValue({ foo: bar: [] }, 'foo.bar') //=> []
|
|
102
|
-
*
|
|
103
|
-
* @ignore
|
|
104
|
-
*/
|
|
105
|
-
function propGetter(paths, config) {
|
|
106
|
-
if (config && config.compatibility && config.compatibility.strictContentSecurityPolicy) {
|
|
107
|
-
return compliantPropGetter(paths);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
return fastPropGetter(paths);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Given an array of states, it will return a object graph. Example:
|
|
115
|
-
* const states = [
|
|
116
|
-
* Cart,
|
|
117
|
-
* CartSaved,
|
|
118
|
-
* CartSavedItems
|
|
119
|
-
* ]
|
|
120
|
-
*
|
|
121
|
-
* would return:
|
|
122
|
-
*
|
|
123
|
-
* const graph = {
|
|
124
|
-
* cart: ['saved'],
|
|
125
|
-
* saved: ['items'],
|
|
126
|
-
* items: []
|
|
127
|
-
* };
|
|
128
|
-
*
|
|
129
|
-
* @ignore
|
|
130
|
-
*/
|
|
131
|
-
function buildGraph(stateClasses) {
|
|
132
|
-
const findName = (stateClass) => {
|
|
133
|
-
const meta = stateClasses.find(g => g === stateClass);
|
|
134
|
-
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
135
|
-
// creating a breaking change for projects that still use the View Engine.
|
|
136
|
-
if ((typeof ngDevMode === 'undefined' || ngDevMode) && !meta) {
|
|
137
|
-
throw new Error(`Child state not found: ${stateClass}. \r\nYou may have forgotten to add states to module`);
|
|
138
|
-
}
|
|
139
|
-
return meta[ɵMETA_KEY].name;
|
|
140
|
-
};
|
|
141
|
-
return stateClasses.reduce((result, stateClass) => {
|
|
142
|
-
const { name, children } = stateClass[ɵMETA_KEY];
|
|
143
|
-
result[name] = (children || []).map(findName);
|
|
144
|
-
return result;
|
|
145
|
-
}, {});
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Given a states array, returns object graph
|
|
149
|
-
* returning the name and state metadata. Example:
|
|
150
|
-
*
|
|
151
|
-
* const graph = {
|
|
152
|
-
* cart: { metadata }
|
|
153
|
-
* };
|
|
154
|
-
*
|
|
155
|
-
* @ignore
|
|
156
|
-
*/
|
|
157
|
-
function nameToState(states) {
|
|
158
|
-
return states.reduce((result, stateClass) => {
|
|
159
|
-
const meta = stateClass[ɵMETA_KEY];
|
|
160
|
-
result[meta.name] = stateClass;
|
|
161
|
-
return result;
|
|
162
|
-
}, {});
|
|
163
|
-
}
|
|
164
|
-
/**
|
|
165
|
-
* Given a object relationship graph will return the full path
|
|
166
|
-
* for the child items. Example:
|
|
167
|
-
*
|
|
168
|
-
* const graph = {
|
|
169
|
-
* cart: ['saved'],
|
|
170
|
-
* saved: ['items'],
|
|
171
|
-
* items: []
|
|
172
|
-
* };
|
|
173
|
-
*
|
|
174
|
-
* would return:
|
|
175
|
-
*
|
|
176
|
-
* const r = {
|
|
177
|
-
* cart: 'cart',
|
|
178
|
-
* saved: 'cart.saved',
|
|
179
|
-
* items: 'cart.saved.items'
|
|
180
|
-
* };
|
|
181
|
-
*
|
|
182
|
-
* @ignore
|
|
183
|
-
*/
|
|
184
|
-
function findFullParentPath(obj, newObj = {}) {
|
|
185
|
-
const visit = (child, keyToFind) => {
|
|
186
|
-
for (const key in child) {
|
|
187
|
-
if (child.hasOwnProperty(key) && child[key].indexOf(keyToFind) >= 0) {
|
|
188
|
-
const parent = visit(child, key);
|
|
189
|
-
return parent !== null ? `${parent}.${key}` : key;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return null;
|
|
193
|
-
};
|
|
194
|
-
for (const key in obj) {
|
|
195
|
-
if (obj.hasOwnProperty(key)) {
|
|
196
|
-
const parent = visit(obj, key);
|
|
197
|
-
newObj[key] = parent ? `${parent}.${key}` : key;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return newObj;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Given a object graph, it will return the items topologically sorted Example:
|
|
204
|
-
*
|
|
205
|
-
* const graph = {
|
|
206
|
-
* cart: ['saved'],
|
|
207
|
-
* saved: ['items'],
|
|
208
|
-
* items: []
|
|
209
|
-
* };
|
|
210
|
-
*
|
|
211
|
-
* would return:
|
|
212
|
-
*
|
|
213
|
-
* const results = [
|
|
214
|
-
* 'items',
|
|
215
|
-
* 'saved',
|
|
216
|
-
* 'cart'
|
|
217
|
-
* ];
|
|
218
|
-
*
|
|
219
|
-
* @ignore
|
|
220
|
-
*/
|
|
221
|
-
function topologicalSort(graph) {
|
|
222
|
-
const sorted = [];
|
|
223
|
-
const visited = {};
|
|
224
|
-
const visit = (name, ancestors = []) => {
|
|
225
|
-
if (!Array.isArray(ancestors)) {
|
|
226
|
-
ancestors = [];
|
|
227
|
-
}
|
|
228
|
-
ancestors.push(name);
|
|
229
|
-
visited[name] = true;
|
|
230
|
-
graph[name].forEach((dep) => {
|
|
231
|
-
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
232
|
-
// creating a breaking change for projects that still use the View Engine.
|
|
233
|
-
if ((typeof ngDevMode === 'undefined' || ngDevMode) && ancestors.indexOf(dep) >= 0) {
|
|
234
|
-
throw new Error(`Circular dependency '${dep}' is required by '${name}': ${ancestors.join(' -> ')}`);
|
|
235
|
-
}
|
|
236
|
-
if (visited[dep]) {
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
visit(dep, ancestors.slice(0));
|
|
240
|
-
});
|
|
241
|
-
if (sorted.indexOf(name) < 0) {
|
|
242
|
-
sorted.push(name);
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
Object.keys(graph).forEach(k => visit(k));
|
|
246
|
-
return sorted.reverse();
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Returns if the parameter is a object or not.
|
|
250
|
-
*
|
|
251
|
-
* @ignore
|
|
252
|
-
*/
|
|
253
|
-
function isObject$1(obj) {
|
|
254
|
-
return (typeof obj === 'object' && obj !== null) || typeof obj === 'function';
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function createRootSelectorFactory(selectorMetaData, selectors, memoizedSelectorFn) {
|
|
258
|
-
return (context) => {
|
|
259
|
-
const { argumentSelectorFunctions, selectorOptions } = getRuntimeSelectorInfo(context, selectorMetaData, selectors);
|
|
260
|
-
return function selectFromRoot(rootState) {
|
|
261
|
-
// Determine arguments from the app state using the selectors
|
|
262
|
-
const results = argumentSelectorFunctions.map((argFn) => argFn(rootState));
|
|
263
|
-
// if the lambda tries to access a something on the
|
|
264
|
-
// state that doesn't exist, it will throw a TypeError.
|
|
265
|
-
// since this is quite usual behaviour, we simply return undefined if so.
|
|
266
|
-
try {
|
|
267
|
-
return memoizedSelectorFn(...results);
|
|
268
|
-
}
|
|
269
|
-
catch (ex) {
|
|
270
|
-
if (ex instanceof TypeError && selectorOptions.suppressErrors) {
|
|
271
|
-
return undefined;
|
|
272
|
-
}
|
|
273
|
-
throw ex;
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
};
|
|
277
|
-
}
|
|
278
|
-
function createMemoizedSelectorFn(originalFn, creationMetadata) {
|
|
279
|
-
const containerClass = creationMetadata && creationMetadata.containerClass;
|
|
280
|
-
const wrappedFn = function wrappedSelectorFn(...args) {
|
|
281
|
-
const returnValue = originalFn.apply(containerClass, args);
|
|
282
|
-
if (returnValue instanceof Function) {
|
|
283
|
-
const innerMemoizedFn = memoize.apply(null, [returnValue]);
|
|
284
|
-
return innerMemoizedFn;
|
|
285
|
-
}
|
|
286
|
-
return returnValue;
|
|
287
|
-
};
|
|
288
|
-
const memoizedFn = memoize(wrappedFn);
|
|
289
|
-
Object.setPrototypeOf(memoizedFn, originalFn);
|
|
290
|
-
return memoizedFn;
|
|
291
|
-
}
|
|
292
|
-
function getRuntimeSelectorInfo(context, selectorMetaData, selectors = []) {
|
|
293
|
-
const localSelectorOptions = selectorMetaData.getSelectorOptions();
|
|
294
|
-
const selectorOptions = context.getSelectorOptions(localSelectorOptions);
|
|
295
|
-
const selectorsToApply = getSelectorsToApply(selectors, selectorOptions, selectorMetaData.containerClass);
|
|
296
|
-
const argumentSelectorFunctions = selectorsToApply.map((selector) => {
|
|
297
|
-
const factory = getRootSelectorFactory(selector);
|
|
298
|
-
return factory(context);
|
|
299
|
-
});
|
|
300
|
-
return {
|
|
301
|
-
selectorOptions,
|
|
302
|
-
argumentSelectorFunctions,
|
|
303
|
-
};
|
|
304
|
-
}
|
|
305
|
-
function getSelectorsToApply(selectors = [], selectorOptions, containerClass) {
|
|
306
|
-
const selectorsToApply = [];
|
|
307
|
-
const canInjectContainerState = selectors.length === 0 || selectorOptions.injectContainerState;
|
|
308
|
-
if (containerClass && canInjectContainerState) {
|
|
309
|
-
// If we are on a state class, add it as the first selector parameter
|
|
310
|
-
const metadata = getStoreMetadata$1(containerClass);
|
|
311
|
-
if (metadata) {
|
|
312
|
-
selectorsToApply.push(containerClass);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
if (selectors) {
|
|
316
|
-
selectorsToApply.push(...selectors);
|
|
317
|
-
}
|
|
318
|
-
return selectorsToApply;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* This function gets the factory function to create the selector to get the selected slice from the app state
|
|
322
|
-
* @ignore
|
|
323
|
-
*/
|
|
324
|
-
function getRootSelectorFactory(selector) {
|
|
325
|
-
const metadata = getSelectorMetadata$1(selector) || getStoreMetadata$1(selector);
|
|
326
|
-
return (metadata && metadata.makeRootSelector) || (() => selector);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
/**
|
|
330
|
-
* Returns operator that will run
|
|
331
|
-
* `subscribe` outside of the ngxs execution context
|
|
332
|
-
*/
|
|
333
|
-
function leaveNgxs(ngxsExecutionStrategy) {
|
|
334
|
-
return (source) => {
|
|
335
|
-
return new Observable((sink) => {
|
|
336
|
-
return source.subscribe({
|
|
337
|
-
next(value) {
|
|
338
|
-
ngxsExecutionStrategy.leave(() => sink.next(value));
|
|
339
|
-
},
|
|
340
|
-
error(error) {
|
|
341
|
-
ngxsExecutionStrategy.leave(() => sink.error(error));
|
|
342
|
-
},
|
|
343
|
-
complete() {
|
|
344
|
-
ngxsExecutionStrategy.leave(() => sink.complete());
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* This wraps the provided function, and will enforce the following:
|
|
353
|
-
* - The calls will execute in the order that they are made
|
|
354
|
-
* - A call will only be initiated when the previous call has completed
|
|
355
|
-
* - If there is a call currently executing then the new call will be added
|
|
356
|
-
* to the queue and the function will return immediately
|
|
357
|
-
*
|
|
358
|
-
* NOTE: The following assumptions about the operation must hold true:
|
|
359
|
-
* - The operation is synchronous in nature
|
|
360
|
-
* - If any asynchronous side effects of the call exist, it should not
|
|
361
|
-
* have any bearing on the correctness of the next call in the queue
|
|
362
|
-
* - The operation has a void return
|
|
363
|
-
* - The caller should not assume that the call has completed upon
|
|
364
|
-
* return of the function
|
|
365
|
-
* - The caller can assume that all the queued calls will complete
|
|
366
|
-
* within the current microtask
|
|
367
|
-
* - The only way that a call will encounter another call in the queue
|
|
368
|
-
* would be if the call at the front of the queue initiated this call
|
|
369
|
-
* as part of its synchronous execution
|
|
370
|
-
*/
|
|
371
|
-
function orderedQueueOperation(operation) {
|
|
372
|
-
const callsQueue = [];
|
|
373
|
-
let busyPushingNext = false;
|
|
374
|
-
return function callOperation(...args) {
|
|
375
|
-
if (busyPushingNext) {
|
|
376
|
-
callsQueue.unshift(args);
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
busyPushingNext = true;
|
|
380
|
-
operation(...args);
|
|
381
|
-
while (callsQueue.length > 0) {
|
|
382
|
-
const nextCallArgs = callsQueue.pop();
|
|
383
|
-
nextCallArgs && operation(...nextCallArgs);
|
|
384
|
-
}
|
|
385
|
-
busyPushingNext = false;
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Custom Subject that ensures that subscribers are notified of values in the order that they arrived.
|
|
390
|
-
* A standard Subject does not have this guarantee.
|
|
391
|
-
* For example, given the following code:
|
|
392
|
-
* ```typescript
|
|
393
|
-
* const subject = new Subject<string>();
|
|
394
|
-
subject.subscribe(value => {
|
|
395
|
-
if (value === 'start') subject.next('end');
|
|
396
|
-
});
|
|
397
|
-
subject.subscribe(value => { });
|
|
398
|
-
subject.next('start');
|
|
399
|
-
* ```
|
|
400
|
-
* When `subject` is a standard `Subject<T>` the second subscriber would recieve `end` and then `start`.
|
|
401
|
-
* When `subject` is a `OrderedSubject<T>` the second subscriber would recieve `start` and then `end`.
|
|
402
|
-
*/
|
|
403
|
-
class OrderedSubject extends Subject {
|
|
404
|
-
constructor() {
|
|
405
|
-
super(...arguments);
|
|
406
|
-
this._orderedNext = orderedQueueOperation((value) => super.next(value));
|
|
407
|
-
}
|
|
408
|
-
next(value) {
|
|
409
|
-
this._orderedNext(value);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Custom BehaviorSubject that ensures that subscribers are notified of values in the order that they arrived.
|
|
414
|
-
* A standard BehaviorSubject does not have this guarantee.
|
|
415
|
-
* For example, given the following code:
|
|
416
|
-
* ```typescript
|
|
417
|
-
* const subject = new BehaviorSubject<string>();
|
|
418
|
-
subject.subscribe(value => {
|
|
419
|
-
if (value === 'start') subject.next('end');
|
|
420
|
-
});
|
|
421
|
-
subject.subscribe(value => { });
|
|
422
|
-
subject.next('start');
|
|
423
|
-
* ```
|
|
424
|
-
* When `subject` is a standard `BehaviorSubject<T>` the second subscriber would recieve `end` and then `start`.
|
|
425
|
-
* When `subject` is a `OrderedBehaviorSubject<T>` the second subscriber would recieve `start` and then `end`.
|
|
426
|
-
*/
|
|
427
|
-
class OrderedBehaviorSubject extends BehaviorSubject {
|
|
428
|
-
constructor(value) {
|
|
429
|
-
super(value);
|
|
430
|
-
this._orderedNext = orderedQueueOperation((value) => super.next(value));
|
|
431
|
-
this._currentValue = value;
|
|
432
|
-
}
|
|
433
|
-
getValue() {
|
|
434
|
-
return this._currentValue;
|
|
435
|
-
}
|
|
436
|
-
next(value) {
|
|
437
|
-
this._currentValue = value;
|
|
438
|
-
this._orderedNext(value);
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
/**
|
|
443
|
-
* BehaviorSubject of the entire state.
|
|
444
|
-
* @ignore
|
|
445
|
-
*/
|
|
446
|
-
class StateStream extends OrderedBehaviorSubject {
|
|
447
|
-
constructor() {
|
|
448
|
-
super({});
|
|
449
|
-
}
|
|
450
|
-
ngOnDestroy() {
|
|
451
|
-
// The StateStream should never emit values once the root view is removed,
|
|
452
|
-
// such as when the `NgModuleRef.destroy()` method is called. This is crucial
|
|
453
|
-
// for preventing memory leaks in server-side rendered apps, where a new StateStream
|
|
454
|
-
// is created for each HTTP request. If users forget to unsubscribe from `store.select`
|
|
455
|
-
// or `store.subscribe`, it can result in significant memory leaks in SSR apps.
|
|
456
|
-
this.complete();
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
/** @nocollapse */ StateStream.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateStream, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
460
|
-
/** @nocollapse */ StateStream.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateStream, providedIn: 'root' });
|
|
461
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateStream, decorators: [{
|
|
462
|
-
type: Injectable,
|
|
463
|
-
args: [{ providedIn: 'root' }]
|
|
464
|
-
}], ctorParameters: function () { return []; } });
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* Object freeze code
|
|
468
|
-
* https://github.com/jsdf/deep-freeze
|
|
469
|
-
*/
|
|
470
|
-
const deepFreeze = (o) => {
|
|
471
|
-
Object.freeze(o);
|
|
472
|
-
const oIsFunction = typeof o === 'function';
|
|
473
|
-
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
474
|
-
Object.getOwnPropertyNames(o).forEach(function (prop) {
|
|
475
|
-
if (hasOwnProp.call(o, prop) &&
|
|
476
|
-
(oIsFunction ? prop !== 'caller' && prop !== 'callee' && prop !== 'arguments' : true) &&
|
|
477
|
-
o[prop] !== null &&
|
|
478
|
-
(typeof o[prop] === 'object' || typeof o[prop] === 'function') &&
|
|
479
|
-
!Object.isFrozen(o[prop])) {
|
|
480
|
-
deepFreeze(o[prop]);
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
return o;
|
|
484
|
-
};
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* Composes a array of functions from left to right. Example:
|
|
488
|
-
*
|
|
489
|
-
* compose([fn, final])(state, action);
|
|
490
|
-
*
|
|
491
|
-
* then the funcs have a signature like:
|
|
492
|
-
*
|
|
493
|
-
* function fn (state, action, next) {
|
|
494
|
-
* console.log('here', state, action, next);
|
|
495
|
-
* return next(state, action);
|
|
496
|
-
* }
|
|
497
|
-
*
|
|
498
|
-
* function final (state, action) {
|
|
499
|
-
* console.log('here', state, action);
|
|
500
|
-
* return state;
|
|
501
|
-
* }
|
|
502
|
-
*
|
|
503
|
-
* the last function should not call `next`.
|
|
504
|
-
*
|
|
505
|
-
* @ignore
|
|
506
|
-
*/
|
|
507
|
-
const compose = (funcs) => (...args) => {
|
|
508
|
-
const curr = funcs.shift();
|
|
509
|
-
return curr(...args, (...nextArgs) => compose(funcs)(...nextArgs));
|
|
510
|
-
};
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* This operator is used for piping the observable result
|
|
514
|
-
* from the `dispatch()`. It has a "smart" error handling
|
|
515
|
-
* strategy that allows us to decide whether we propagate
|
|
516
|
-
* errors to Angular's `ErrorHandler` or enable users to
|
|
517
|
-
* handle them manually. We consider following cases:
|
|
518
|
-
* 1) `store.dispatch()` (no subscribe) -> call `handleError()`
|
|
519
|
-
* 2) `store.dispatch().subscribe()` (no error callback) -> call `handleError()`
|
|
520
|
-
* 3) `store.dispatch().subscribe({ error: ... })` -> don't call `handleError()`
|
|
521
|
-
* 4) `toPromise()` without `catch` -> do `handleError()`
|
|
522
|
-
* 5) `toPromise()` with `catch` -> don't `handleError()`
|
|
523
|
-
*/
|
|
524
|
-
function ngxsErrorHandler(internalErrorReporter, ngxsExecutionStrategy) {
|
|
525
|
-
return (source) => {
|
|
526
|
-
let subscribed = false;
|
|
527
|
-
source.subscribe({
|
|
528
|
-
error: error => {
|
|
529
|
-
// Do not trigger change detection for a microtask. This depends on the execution
|
|
530
|
-
// strategy being used, but the default `DispatchOutsideZoneNgxsExecutionStrategy`
|
|
531
|
-
// leaves the Angular zone.
|
|
532
|
-
ngxsExecutionStrategy.enter(() => Promise.resolve().then(() => {
|
|
533
|
-
if (!subscribed) {
|
|
534
|
-
ngxsExecutionStrategy.leave(() => internalErrorReporter.reportErrorSafely(error));
|
|
535
|
-
}
|
|
536
|
-
}));
|
|
537
|
-
}
|
|
538
|
-
});
|
|
539
|
-
return new Observable(subscriber => {
|
|
540
|
-
subscribed = true;
|
|
541
|
-
return source.pipe(leaveNgxs(ngxsExecutionStrategy)).subscribe(subscriber);
|
|
542
|
-
});
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
class InternalErrorReporter {
|
|
546
|
-
constructor(_injector) {
|
|
547
|
-
this._injector = _injector;
|
|
548
|
-
/** Will be set lazily to be backward compatible. */
|
|
549
|
-
this._errorHandler = null;
|
|
550
|
-
}
|
|
551
|
-
reportErrorSafely(error) {
|
|
552
|
-
if (this._errorHandler === null) {
|
|
553
|
-
this._errorHandler = this._injector.get(ErrorHandler);
|
|
554
|
-
}
|
|
555
|
-
// The `try-catch` is used to avoid handling the error twice. Suppose we call
|
|
556
|
-
// `handleError` which re-throws the error internally. The re-thrown error will
|
|
557
|
-
// be caught by zone.js which will then get to the `zone.onError.emit()` and the
|
|
558
|
-
// `onError` subscriber will call `handleError` again.
|
|
559
|
-
try {
|
|
560
|
-
this._errorHandler.handleError(error);
|
|
561
|
-
}
|
|
562
|
-
catch (_a) { }
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
/** @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 });
|
|
566
|
-
/** @nocollapse */ InternalErrorReporter.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalErrorReporter, providedIn: 'root' });
|
|
567
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalErrorReporter, decorators: [{
|
|
568
|
-
type: Injectable,
|
|
569
|
-
args: [{ providedIn: 'root' }]
|
|
570
|
-
}], ctorParameters: function () { return [{ type: i0.Injector }]; } });
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* Returns the type from an action instance/class.
|
|
574
|
-
* @ignore
|
|
575
|
-
*/
|
|
576
|
-
function getActionTypeFromInstance(action) {
|
|
577
|
-
if (action.constructor && action.constructor.type) {
|
|
578
|
-
return action.constructor.type;
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
return action.type;
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
/**
|
|
585
|
-
* Matches a action
|
|
586
|
-
* @ignore
|
|
587
|
-
*/
|
|
588
|
-
function actionMatcher(action1) {
|
|
589
|
-
const type1 = getActionTypeFromInstance(action1);
|
|
590
|
-
return function (action2) {
|
|
591
|
-
return type1 === getActionTypeFromInstance(action2);
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
/**
|
|
595
|
-
* Set a deeply nested value. Example:
|
|
596
|
-
*
|
|
597
|
-
* setValue({ foo: { bar: { eat: false } } },
|
|
598
|
-
* 'foo.bar.eat', true) //=> { foo: { bar: { eat: true } } }
|
|
599
|
-
*
|
|
600
|
-
* While it traverses it also creates new objects from top down.
|
|
601
|
-
*
|
|
602
|
-
* @ignore
|
|
603
|
-
*/
|
|
604
|
-
const setValue = (obj, prop, val) => {
|
|
605
|
-
obj = Object.assign({}, obj);
|
|
606
|
-
const split = prop.split('.');
|
|
607
|
-
const lastIndex = split.length - 1;
|
|
608
|
-
split.reduce((acc, part, index) => {
|
|
609
|
-
if (index === lastIndex) {
|
|
610
|
-
acc[part] = val;
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
acc[part] = Array.isArray(acc[part]) ? acc[part].slice() : Object.assign({}, acc[part]);
|
|
614
|
-
}
|
|
615
|
-
return acc && acc[part];
|
|
616
|
-
}, obj);
|
|
617
|
-
return obj;
|
|
618
|
-
};
|
|
619
|
-
/**
|
|
620
|
-
* Get a deeply nested value. Example:
|
|
621
|
-
*
|
|
622
|
-
* getValue({ foo: bar: [] }, 'foo.bar') //=> []
|
|
623
|
-
*
|
|
624
|
-
* @ignore
|
|
625
|
-
*/
|
|
626
|
-
const getValue = (obj, prop) => prop.split('.').reduce((acc, part) => acc && acc[part], obj);
|
|
627
|
-
/**
|
|
628
|
-
* Simple object check.
|
|
629
|
-
*
|
|
630
|
-
* isObject({a:1}) //=> true
|
|
631
|
-
* isObject(1) //=> false
|
|
632
|
-
*
|
|
633
|
-
* @ignore
|
|
634
|
-
*/
|
|
635
|
-
const isObject = (item) => {
|
|
636
|
-
return item && typeof item === 'object' && !Array.isArray(item);
|
|
637
|
-
};
|
|
638
|
-
/**
|
|
639
|
-
* Deep merge two objects.
|
|
640
|
-
*
|
|
641
|
-
* mergeDeep({a:1, b:{x: 1, y:2}}, {b:{x: 3}, c:4}) //=> {a:1, b:{x:3, y:2}, c:4}
|
|
642
|
-
*
|
|
643
|
-
* @param base base object onto which `sources` will be applied
|
|
644
|
-
*/
|
|
645
|
-
const mergeDeep = (base, ...sources) => {
|
|
646
|
-
if (!sources.length)
|
|
647
|
-
return base;
|
|
648
|
-
const source = sources.shift();
|
|
649
|
-
if (isObject(base) && isObject(source)) {
|
|
650
|
-
for (const key in source) {
|
|
651
|
-
if (isObject(source[key])) {
|
|
652
|
-
if (!base[key])
|
|
653
|
-
Object.assign(base, { [key]: {} });
|
|
654
|
-
mergeDeep(base[key], source[key]);
|
|
655
|
-
}
|
|
656
|
-
else {
|
|
657
|
-
Object.assign(base, { [key]: source[key] });
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
return mergeDeep(base, ...sources);
|
|
662
|
-
};
|
|
663
|
-
|
|
664
|
-
class NoopNgxsExecutionStrategy {
|
|
665
|
-
enter(func) {
|
|
666
|
-
return func();
|
|
667
|
-
}
|
|
668
|
-
leave(func) {
|
|
669
|
-
return func();
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
/** @nocollapse */ NoopNgxsExecutionStrategy.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NoopNgxsExecutionStrategy, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
673
|
-
/** @nocollapse */ NoopNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NoopNgxsExecutionStrategy, providedIn: 'root' });
|
|
674
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NoopNgxsExecutionStrategy, decorators: [{
|
|
675
|
-
type: Injectable,
|
|
676
|
-
args: [{ providedIn: 'root' }]
|
|
677
|
-
}] });
|
|
678
|
-
|
|
679
|
-
function throwStateNameError(name) {
|
|
680
|
-
throw new Error(`${name} is not a valid state name. It needs to be a valid object property name.`);
|
|
681
|
-
}
|
|
682
|
-
function throwStateNamePropertyError() {
|
|
683
|
-
throw new Error(`States must register a 'name' property.`);
|
|
684
|
-
}
|
|
685
|
-
function throwStateUniqueError(current, newName, oldName) {
|
|
686
|
-
throw new Error(`State name '${current}' from ${newName} already exists in ${oldName}.`);
|
|
687
|
-
}
|
|
688
|
-
function throwStateDecoratorError(name) {
|
|
689
|
-
throw new Error(`States must be decorated with @State() decorator, but "${name}" isn't.`);
|
|
690
|
-
}
|
|
691
|
-
function throwActionDecoratorError() {
|
|
692
|
-
throw new Error('@Action() decorator cannot be used with static methods.');
|
|
693
|
-
}
|
|
694
|
-
function throwSelectorDecoratorError() {
|
|
695
|
-
throw new Error('Selectors only work on methods.');
|
|
696
|
-
}
|
|
697
|
-
function getZoneWarningMessage() {
|
|
698
|
-
return ('Your application was bootstrapped with nooped zone and your execution strategy requires an actual NgZone!\n' +
|
|
699
|
-
'Please set the value of the executionStrategy property to NoopNgxsExecutionStrategy.\n' +
|
|
700
|
-
'NgxsModule.forRoot(states, { executionStrategy: NoopNgxsExecutionStrategy })');
|
|
701
|
-
}
|
|
702
|
-
function getUndecoratedStateInIvyWarningMessage(name) {
|
|
703
|
-
return `'${name}' class should be decorated with @Injectable() right after the @State() decorator`;
|
|
704
|
-
}
|
|
705
|
-
function getInvalidInitializationOrderMessage(addedStates) {
|
|
706
|
-
let message = 'You have an invalid state initialization order. This typically occurs when `NgxsModule.forFeature`\n' +
|
|
707
|
-
'or `provideStates` is called before `NgxsModule.forRoot` or `provideStore`.\n' +
|
|
708
|
-
'One example is when `NgxsRouterPluginModule.forRoot` is called before `NgxsModule.forRoot`.';
|
|
709
|
-
if (addedStates) {
|
|
710
|
-
const stateNames = Object.keys(addedStates).map(stateName => `"${stateName}"`);
|
|
711
|
-
message +=
|
|
712
|
-
'\nFeature states added before the store initialization is complete: ' +
|
|
713
|
-
`${stateNames.join(', ')}.`;
|
|
714
|
-
}
|
|
715
|
-
return message;
|
|
716
|
-
}
|
|
717
|
-
function throwSelectFactoryNotConnectedError() {
|
|
718
|
-
throw new Error('You have forgotten to import the NGXS module!');
|
|
719
|
-
}
|
|
720
|
-
function throwPatchingArrayError() {
|
|
721
|
-
throw new Error('Patching arrays is not supported.');
|
|
722
|
-
}
|
|
723
|
-
function throwPatchingPrimitiveError() {
|
|
724
|
-
throw new Error('Patching primitives is not supported.');
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
class DispatchOutsideZoneNgxsExecutionStrategy {
|
|
728
|
-
constructor(_ngZone, _platformId) {
|
|
729
|
-
this._ngZone = _ngZone;
|
|
730
|
-
this._platformId = _platformId;
|
|
731
|
-
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
732
|
-
// creating a breaking change for projects that still use the View Engine.
|
|
733
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
734
|
-
verifyZoneIsNotNooped(_ngZone);
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
enter(func) {
|
|
738
|
-
if (isPlatformServer(this._platformId)) {
|
|
739
|
-
return this.runInsideAngular(func);
|
|
740
|
-
}
|
|
741
|
-
return this.runOutsideAngular(func);
|
|
742
|
-
}
|
|
743
|
-
leave(func) {
|
|
744
|
-
return this.runInsideAngular(func);
|
|
745
|
-
}
|
|
746
|
-
runInsideAngular(func) {
|
|
747
|
-
if (NgZone.isInAngularZone()) {
|
|
748
|
-
return func();
|
|
749
|
-
}
|
|
750
|
-
return this._ngZone.run(func);
|
|
751
|
-
}
|
|
752
|
-
runOutsideAngular(func) {
|
|
753
|
-
if (NgZone.isInAngularZone()) {
|
|
754
|
-
return this._ngZone.runOutsideAngular(func);
|
|
755
|
-
}
|
|
756
|
-
return func();
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
/** @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 });
|
|
760
|
-
/** @nocollapse */ DispatchOutsideZoneNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, providedIn: 'root' });
|
|
761
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: DispatchOutsideZoneNgxsExecutionStrategy, decorators: [{
|
|
762
|
-
type: Injectable,
|
|
763
|
-
args: [{ providedIn: 'root' }]
|
|
764
|
-
}], ctorParameters: function () {
|
|
765
|
-
return [{ type: i0.NgZone }, { type: undefined, decorators: [{
|
|
766
|
-
type: Inject,
|
|
767
|
-
args: [PLATFORM_ID]
|
|
768
|
-
}] }];
|
|
769
|
-
} });
|
|
770
|
-
// Caretaker note: this should exist as a separate function and not a class method,
|
|
771
|
-
// since class methods are not tree-shakable.
|
|
772
|
-
function verifyZoneIsNotNooped(ngZone) {
|
|
773
|
-
// `NoopNgZone` is not exposed publicly as it doesn't expect
|
|
774
|
-
// to be used outside of the core Angular code, thus we just have
|
|
775
|
-
// to check if the zone doesn't extend or instanceof `NgZone`.
|
|
776
|
-
if (ngZone instanceof NgZone) {
|
|
777
|
-
return;
|
|
778
|
-
}
|
|
779
|
-
console.warn(getZoneWarningMessage());
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
const NG_DEV_MODE$4 = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
783
|
-
/**
|
|
784
|
-
* Consumers have the option to utilize the execution strategy provided by
|
|
785
|
-
* `NgxsModule.forRoot({executionStrategy})` or `provideStore([], {executionStrategy})`.
|
|
786
|
-
*/
|
|
787
|
-
const CUSTOM_NGXS_EXECUTION_STRATEGY = new InjectionToken(NG_DEV_MODE$4 ? 'CUSTOM_NGXS_EXECUTION_STRATEGY' : '');
|
|
788
|
-
/**
|
|
789
|
-
* The injection token is used internally to resolve an instance of the execution
|
|
790
|
-
* strategy. It checks whether consumers have provided their own `executionStrategy`
|
|
791
|
-
* and also verifies if we are operating in a zone-aware environment.
|
|
792
|
-
*/
|
|
793
|
-
const NGXS_EXECUTION_STRATEGY = new InjectionToken(NG_DEV_MODE$4 ? 'NGXS_EXECUTION_STRATEGY' : '', {
|
|
794
|
-
providedIn: 'root',
|
|
795
|
-
factory: () => {
|
|
796
|
-
const injector = inject(INJECTOR);
|
|
797
|
-
const executionStrategy = injector.get(CUSTOM_NGXS_EXECUTION_STRATEGY);
|
|
798
|
-
return executionStrategy
|
|
799
|
-
? injector.get(executionStrategy)
|
|
800
|
-
: injector.get(typeof ɵglobal.Zone !== 'undefined'
|
|
801
|
-
? DispatchOutsideZoneNgxsExecutionStrategy
|
|
802
|
-
: NoopNgxsExecutionStrategy);
|
|
803
|
-
}
|
|
804
|
-
});
|
|
805
|
-
|
|
806
|
-
class InternalNgxsExecutionStrategy {
|
|
807
|
-
constructor(_executionStrategy) {
|
|
808
|
-
this._executionStrategy = _executionStrategy;
|
|
809
|
-
}
|
|
810
|
-
enter(func) {
|
|
811
|
-
return this._executionStrategy.enter(func);
|
|
812
|
-
}
|
|
813
|
-
leave(func) {
|
|
814
|
-
return this._executionStrategy.leave(func);
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
/** @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 });
|
|
818
|
-
/** @nocollapse */ InternalNgxsExecutionStrategy.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalNgxsExecutionStrategy, providedIn: 'root' });
|
|
819
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalNgxsExecutionStrategy, decorators: [{
|
|
820
|
-
type: Injectable,
|
|
821
|
-
args: [{ providedIn: 'root' }]
|
|
822
|
-
}], ctorParameters: function () {
|
|
823
|
-
return [{ type: undefined, decorators: [{
|
|
824
|
-
type: Inject,
|
|
825
|
-
args: [NGXS_EXECUTION_STRATEGY]
|
|
826
|
-
}] }];
|
|
827
|
-
} });
|
|
828
|
-
|
|
829
|
-
/**
|
|
830
|
-
* Internal Action stream that is emitted anytime an action is dispatched.
|
|
831
|
-
*/
|
|
832
|
-
class InternalActions extends OrderedSubject {
|
|
833
|
-
ngOnDestroy() {
|
|
834
|
-
this.complete();
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
/** @nocollapse */ InternalActions.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalActions, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
838
|
-
/** @nocollapse */ InternalActions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalActions, providedIn: 'root' });
|
|
839
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalActions, decorators: [{
|
|
840
|
-
type: Injectable,
|
|
841
|
-
args: [{ providedIn: 'root' }]
|
|
842
|
-
}] });
|
|
843
|
-
/**
|
|
844
|
-
* Action stream that is emitted anytime an action is dispatched.
|
|
845
|
-
*
|
|
846
|
-
* You can listen to this in services to react without stores.
|
|
847
|
-
*/
|
|
848
|
-
class Actions extends Observable {
|
|
849
|
-
constructor(internalActions$, internalExecutionStrategy) {
|
|
850
|
-
const sharedInternalActions$ = internalActions$.pipe(leaveNgxs(internalExecutionStrategy),
|
|
851
|
-
// The `InternalActions` subject emits outside of the Angular zone.
|
|
852
|
-
// We have to re-enter the Angular zone for any incoming consumer.
|
|
853
|
-
// The `share()` operator reduces the number of change detections.
|
|
854
|
-
// This would call leave only once for any stream emission across all active subscribers.
|
|
855
|
-
share());
|
|
856
|
-
super(observer => {
|
|
857
|
-
const childSubscription = sharedInternalActions$.subscribe({
|
|
858
|
-
next: ctx => observer.next(ctx),
|
|
859
|
-
error: error => observer.error(error),
|
|
860
|
-
complete: () => observer.complete()
|
|
861
|
-
});
|
|
862
|
-
observer.add(childSubscription);
|
|
863
|
-
});
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
/** @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 });
|
|
867
|
-
/** @nocollapse */ Actions.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Actions, providedIn: 'root' });
|
|
868
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Actions, decorators: [{
|
|
869
|
-
type: Injectable,
|
|
870
|
-
args: [{ providedIn: 'root' }]
|
|
871
|
-
}], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalNgxsExecutionStrategy }]; } });
|
|
872
|
-
|
|
873
|
-
const NG_DEV_MODE$3 = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
874
|
-
// The injection token is used to resolve a list of states provided at
|
|
875
|
-
// the root level through either `NgxsModule.forRoot` or `provideStore`.
|
|
876
|
-
const ROOT_STATE_TOKEN = new InjectionToken(NG_DEV_MODE$3 ? 'ROOT_STATE_TOKEN' : '');
|
|
877
|
-
// The injection token is used to resolve a list of states provided at
|
|
878
|
-
// the feature level through either `NgxsModule.forFeature` or `provideStates`.
|
|
879
|
-
// The Array<Array> is used to overload the resolved value of the token because
|
|
880
|
-
// it is a multi-provider token.
|
|
881
|
-
const FEATURE_STATE_TOKEN = new InjectionToken(NG_DEV_MODE$3 ? 'FEATURE_STATE_TOKEN' : '');
|
|
882
|
-
// The injection token is used to resolve to custom NGXS plugins provided
|
|
883
|
-
// at the root level through either `{provide}` scheme or `withNgxsPlugin`.
|
|
884
|
-
const NGXS_PLUGINS = new InjectionToken(NG_DEV_MODE$3 ? 'NGXS_PLUGINS' : '');
|
|
885
|
-
// The injection token is used to resolve to options provided at the root
|
|
886
|
-
// level through either `NgxsModule.forRoot` or `provideStore`.
|
|
887
|
-
const NGXS_OPTIONS = new InjectionToken(NG_DEV_MODE$3 ? 'NGXS_OPTIONS' : '');
|
|
888
|
-
/**
|
|
889
|
-
* The NGXS config settings.
|
|
890
|
-
*/
|
|
891
|
-
class NgxsConfig {
|
|
892
|
-
constructor() {
|
|
893
|
-
/**
|
|
894
|
-
* Defining the default state before module initialization
|
|
895
|
-
* This is convenient if we need to create a define our own set of states.
|
|
896
|
-
* @deprecated will be removed after v4
|
|
897
|
-
* (default: {})
|
|
898
|
-
*/
|
|
899
|
-
this.defaultsState = {};
|
|
900
|
-
/**
|
|
901
|
-
* Defining shared selector options
|
|
902
|
-
*/
|
|
903
|
-
this.selectorOptions = {
|
|
904
|
-
injectContainerState: true,
|
|
905
|
-
suppressErrors: true // TODO: default is true in v3, will change in v4
|
|
906
|
-
};
|
|
907
|
-
this.compatibility = {
|
|
908
|
-
strictContentSecurityPolicy: false
|
|
909
|
-
};
|
|
910
|
-
this.executionStrategy = DispatchOutsideZoneNgxsExecutionStrategy;
|
|
911
|
-
}
|
|
912
|
-
}
|
|
913
|
-
/** @nocollapse */ NgxsConfig.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsConfig, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
914
|
-
/** @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)) });
|
|
915
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsConfig, decorators: [{
|
|
916
|
-
type: Injectable,
|
|
917
|
-
args: [{
|
|
918
|
-
providedIn: 'root',
|
|
919
|
-
useFactory: () => mergeDeep(new NgxsConfig(), inject(NGXS_OPTIONS))
|
|
920
|
-
}]
|
|
921
|
-
}], ctorParameters: function () { return []; } });
|
|
922
|
-
/**
|
|
923
|
-
* Represents a basic change from a previous to a new value for a single state instance.
|
|
924
|
-
* Passed as a value in a NgxsSimpleChanges object to the ngxsOnChanges hook.
|
|
925
|
-
*/
|
|
926
|
-
class NgxsSimpleChange {
|
|
927
|
-
constructor(previousValue, currentValue, firstChange) {
|
|
928
|
-
this.previousValue = previousValue;
|
|
929
|
-
this.currentValue = currentValue;
|
|
930
|
-
this.firstChange = firstChange;
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
class PluginManager {
|
|
935
|
-
constructor(_parentManager, _pluginHandlers) {
|
|
936
|
-
this._parentManager = _parentManager;
|
|
937
|
-
this._pluginHandlers = _pluginHandlers;
|
|
938
|
-
this.plugins = [];
|
|
939
|
-
this.registerHandlers();
|
|
940
|
-
}
|
|
941
|
-
get rootPlugins() {
|
|
942
|
-
return (this._parentManager && this._parentManager.plugins) || this.plugins;
|
|
943
|
-
}
|
|
944
|
-
registerHandlers() {
|
|
945
|
-
const pluginHandlers = this.getPluginHandlers();
|
|
946
|
-
this.rootPlugins.push(...pluginHandlers);
|
|
947
|
-
}
|
|
948
|
-
getPluginHandlers() {
|
|
949
|
-
const handlers = this._pluginHandlers || [];
|
|
950
|
-
return handlers.map((plugin) => (plugin.handle ? plugin.handle.bind(plugin) : plugin));
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
/** @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 });
|
|
954
|
-
/** @nocollapse */ PluginManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: PluginManager });
|
|
955
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: PluginManager, decorators: [{
|
|
956
|
-
type: Injectable
|
|
957
|
-
}], ctorParameters: function () {
|
|
958
|
-
return [{ type: PluginManager, decorators: [{
|
|
959
|
-
type: Optional
|
|
960
|
-
}, {
|
|
961
|
-
type: SkipSelf
|
|
962
|
-
}] }, { type: undefined, decorators: [{
|
|
963
|
-
type: Inject,
|
|
964
|
-
args: [NGXS_PLUGINS]
|
|
965
|
-
}, {
|
|
966
|
-
type: Optional
|
|
967
|
-
}] }];
|
|
968
|
-
} });
|
|
969
|
-
|
|
970
|
-
/**
|
|
971
|
-
* Internal Action result stream that is emitted when an action is completed.
|
|
972
|
-
* This is used as a method of returning the action result to the dispatcher
|
|
973
|
-
* for the observable returned by the dispatch(...) call.
|
|
974
|
-
* The dispatcher then asynchronously pushes the result from this stream onto the main action stream as a result.
|
|
975
|
-
*/
|
|
976
|
-
class InternalDispatchedActionResults extends Subject {
|
|
977
|
-
}
|
|
978
|
-
/** @nocollapse */ InternalDispatchedActionResults.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatchedActionResults, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
|
979
|
-
/** @nocollapse */ InternalDispatchedActionResults.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatchedActionResults, providedIn: 'root' });
|
|
980
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatchedActionResults, decorators: [{
|
|
981
|
-
type: Injectable,
|
|
982
|
-
args: [{ providedIn: 'root' }]
|
|
983
|
-
}] });
|
|
984
|
-
class InternalDispatcher {
|
|
985
|
-
constructor(_actions, _actionResults, _pluginManager, _stateStream, _ngxsExecutionStrategy, _internalErrorReporter) {
|
|
986
|
-
this._actions = _actions;
|
|
987
|
-
this._actionResults = _actionResults;
|
|
988
|
-
this._pluginManager = _pluginManager;
|
|
989
|
-
this._stateStream = _stateStream;
|
|
990
|
-
this._ngxsExecutionStrategy = _ngxsExecutionStrategy;
|
|
991
|
-
this._internalErrorReporter = _internalErrorReporter;
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* Dispatches event(s).
|
|
995
|
-
*/
|
|
996
|
-
dispatch(actionOrActions) {
|
|
997
|
-
const result = this._ngxsExecutionStrategy.enter(() => this.dispatchByEvents(actionOrActions));
|
|
998
|
-
return result.pipe(ngxsErrorHandler(this._internalErrorReporter, this._ngxsExecutionStrategy));
|
|
999
|
-
}
|
|
1000
|
-
dispatchByEvents(actionOrActions) {
|
|
1001
|
-
if (Array.isArray(actionOrActions)) {
|
|
1002
|
-
if (actionOrActions.length === 0)
|
|
1003
|
-
return of(this._stateStream.getValue());
|
|
1004
|
-
return forkJoin(actionOrActions.map(action => this.dispatchSingle(action)));
|
|
1005
|
-
}
|
|
1006
|
-
else {
|
|
1007
|
-
return this.dispatchSingle(actionOrActions);
|
|
1008
|
-
}
|
|
1009
|
-
}
|
|
1010
|
-
dispatchSingle(action) {
|
|
1011
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
1012
|
-
const type = getActionTypeFromInstance(action);
|
|
1013
|
-
if (!type) {
|
|
1014
|
-
const error = new Error(`This action doesn't have a type property: ${action.constructor.name}`);
|
|
1015
|
-
return throwError(error);
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
const prevState = this._stateStream.getValue();
|
|
1019
|
-
const plugins = this._pluginManager.plugins;
|
|
1020
|
-
return compose([
|
|
1021
|
-
...plugins,
|
|
1022
|
-
(nextState, nextAction) => {
|
|
1023
|
-
if (nextState !== prevState) {
|
|
1024
|
-
this._stateStream.next(nextState);
|
|
1025
|
-
}
|
|
1026
|
-
const actionResult$ = this.getActionResultStream(nextAction);
|
|
1027
|
-
actionResult$.subscribe(ctx => this._actions.next(ctx));
|
|
1028
|
-
this._actions.next({ action: nextAction, status: "DISPATCHED" /* ActionStatus.Dispatched */ });
|
|
1029
|
-
return this.createDispatchObservable(actionResult$);
|
|
1030
|
-
}
|
|
1031
|
-
])(prevState, action).pipe(shareReplay());
|
|
1032
|
-
}
|
|
1033
|
-
getActionResultStream(action) {
|
|
1034
|
-
return this._actionResults.pipe(filter((ctx) => ctx.action === action && ctx.status !== "DISPATCHED" /* ActionStatus.Dispatched */), take(1), shareReplay());
|
|
1035
|
-
}
|
|
1036
|
-
createDispatchObservable(actionResult$) {
|
|
1037
|
-
return actionResult$
|
|
1038
|
-
.pipe(exhaustMap((ctx) => {
|
|
1039
|
-
switch (ctx.status) {
|
|
1040
|
-
case "SUCCESSFUL" /* ActionStatus.Successful */:
|
|
1041
|
-
return of(this._stateStream.getValue());
|
|
1042
|
-
case "ERRORED" /* ActionStatus.Errored */:
|
|
1043
|
-
return throwError(ctx.error);
|
|
1044
|
-
default:
|
|
1045
|
-
return EMPTY;
|
|
1046
|
-
}
|
|
1047
|
-
}))
|
|
1048
|
-
.pipe(shareReplay());
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
/** @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 });
|
|
1052
|
-
/** @nocollapse */ InternalDispatcher.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatcher, providedIn: 'root' });
|
|
1053
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalDispatcher, decorators: [{
|
|
1054
|
-
type: Injectable,
|
|
1055
|
-
args: [{ providedIn: 'root' }]
|
|
1056
|
-
}], ctorParameters: function () { return [{ type: InternalActions }, { type: InternalDispatchedActionResults }, { type: PluginManager }, { type: StateStream }, { type: InternalNgxsExecutionStrategy }, { type: InternalErrorReporter }]; } });
|
|
1057
|
-
|
|
1058
|
-
/**
|
|
1059
|
-
* @ignore
|
|
1060
|
-
*/
|
|
1061
|
-
class InternalStateOperations {
|
|
1062
|
-
constructor(_stateStream, _dispatcher, _config) {
|
|
1063
|
-
this._stateStream = _stateStream;
|
|
1064
|
-
this._dispatcher = _dispatcher;
|
|
1065
|
-
this._config = _config;
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* Returns the root state operators.
|
|
1069
|
-
*/
|
|
1070
|
-
getRootStateOperations() {
|
|
1071
|
-
const rootStateOperations = {
|
|
1072
|
-
getState: () => this._stateStream.getValue(),
|
|
1073
|
-
setState: (newState) => this._stateStream.next(newState),
|
|
1074
|
-
dispatch: (actionOrActions) => this._dispatcher.dispatch(actionOrActions)
|
|
1075
|
-
};
|
|
1076
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
1077
|
-
return this._config.developmentMode
|
|
1078
|
-
? ensureStateAndActionsAreImmutable(rootStateOperations)
|
|
1079
|
-
: rootStateOperations;
|
|
1080
|
-
}
|
|
1081
|
-
else {
|
|
1082
|
-
return rootStateOperations;
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
setStateToTheCurrentWithNew(results) {
|
|
1086
|
-
const stateOperations = this.getRootStateOperations();
|
|
1087
|
-
// Get our current stream
|
|
1088
|
-
const currentState = stateOperations.getState();
|
|
1089
|
-
// Set the state to the current + new
|
|
1090
|
-
stateOperations.setState(Object.assign(Object.assign({}, currentState), results.defaults));
|
|
1091
|
-
}
|
|
1092
|
-
}
|
|
1093
|
-
/** @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 });
|
|
1094
|
-
/** @nocollapse */ InternalStateOperations.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalStateOperations, providedIn: 'root' });
|
|
1095
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: InternalStateOperations, decorators: [{
|
|
1096
|
-
type: Injectable,
|
|
1097
|
-
args: [{ providedIn: 'root' }]
|
|
1098
|
-
}], ctorParameters: function () { return [{ type: StateStream }, { type: InternalDispatcher }, { type: NgxsConfig }]; } });
|
|
1099
|
-
function ensureStateAndActionsAreImmutable(root) {
|
|
1100
|
-
return {
|
|
1101
|
-
getState: () => root.getState(),
|
|
1102
|
-
setState: value => {
|
|
1103
|
-
const frozenValue = deepFreeze(value);
|
|
1104
|
-
return root.setState(frozenValue);
|
|
1105
|
-
},
|
|
1106
|
-
dispatch: actions => {
|
|
1107
|
-
return root.dispatch(actions);
|
|
1108
|
-
}
|
|
1109
|
-
};
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
/**
|
|
1113
|
-
* RxJS operator for selecting out specific actions.
|
|
1114
|
-
*
|
|
1115
|
-
* This will grab actions that have just been dispatched as well as actions that have completed
|
|
1116
|
-
*/
|
|
1117
|
-
function ofAction(...allowedTypes) {
|
|
1118
|
-
return ofActionOperator(allowedTypes);
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* RxJS operator for selecting out specific actions.
|
|
1122
|
-
*
|
|
1123
|
-
* This will ONLY grab actions that have just been dispatched
|
|
1124
|
-
*/
|
|
1125
|
-
function ofActionDispatched(...allowedTypes) {
|
|
1126
|
-
return ofActionOperator(allowedTypes, ["DISPATCHED" /* ActionStatus.Dispatched */]);
|
|
1127
|
-
}
|
|
1128
|
-
/**
|
|
1129
|
-
* RxJS operator for selecting out specific actions.
|
|
1130
|
-
*
|
|
1131
|
-
* This will ONLY grab actions that have just been successfully completed
|
|
1132
|
-
*/
|
|
1133
|
-
function ofActionSuccessful(...allowedTypes) {
|
|
1134
|
-
return ofActionOperator(allowedTypes, ["SUCCESSFUL" /* ActionStatus.Successful */]);
|
|
1135
|
-
}
|
|
1136
|
-
/**
|
|
1137
|
-
* RxJS operator for selecting out specific actions.
|
|
1138
|
-
*
|
|
1139
|
-
* This will ONLY grab actions that have just been canceled
|
|
1140
|
-
*/
|
|
1141
|
-
function ofActionCanceled(...allowedTypes) {
|
|
1142
|
-
return ofActionOperator(allowedTypes, ["CANCELED" /* ActionStatus.Canceled */]);
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* RxJS operator for selecting out specific actions.
|
|
1146
|
-
*
|
|
1147
|
-
* This will ONLY grab actions that have just been completed
|
|
1148
|
-
*/
|
|
1149
|
-
function ofActionCompleted(...allowedTypes) {
|
|
1150
|
-
const allowedStatuses = [
|
|
1151
|
-
"SUCCESSFUL" /* ActionStatus.Successful */,
|
|
1152
|
-
"CANCELED" /* ActionStatus.Canceled */,
|
|
1153
|
-
"ERRORED" /* ActionStatus.Errored */
|
|
1154
|
-
];
|
|
1155
|
-
return ofActionOperator(allowedTypes, allowedStatuses, mapActionResult);
|
|
1156
|
-
}
|
|
1157
|
-
/**
|
|
1158
|
-
* RxJS operator for selecting out specific actions.
|
|
1159
|
-
*
|
|
1160
|
-
* This will ONLY grab actions that have just thrown an error
|
|
1161
|
-
*/
|
|
1162
|
-
function ofActionErrored(...allowedTypes) {
|
|
1163
|
-
return ofActionOperator(allowedTypes, ["ERRORED" /* ActionStatus.Errored */]);
|
|
1164
|
-
}
|
|
1165
|
-
function ofActionOperator(allowedTypes, statuses,
|
|
1166
|
-
// This actually could've been `OperatorFunction<ActionContext, ActionCompletion | any>`,
|
|
1167
|
-
// since it maps either to `ctx.action` OR to `ActionCompletion`. But `ActionCompleteion | any`
|
|
1168
|
-
// defaults to `any`, thus there is no sense from union type.
|
|
1169
|
-
mapOperator = mapAction) {
|
|
1170
|
-
const allowedMap = createAllowedActionTypesMap(allowedTypes);
|
|
1171
|
-
const allowedStatusMap = statuses && createAllowedStatusesMap(statuses);
|
|
1172
|
-
return function (o) {
|
|
1173
|
-
return o.pipe(filterStatus(allowedMap, allowedStatusMap), mapOperator());
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
|
-
function filterStatus(allowedTypes, allowedStatuses) {
|
|
1177
|
-
return filter((ctx) => {
|
|
1178
|
-
const actionType = getActionTypeFromInstance(ctx.action);
|
|
1179
|
-
const typeMatch = allowedTypes[actionType];
|
|
1180
|
-
const statusMatch = allowedStatuses ? allowedStatuses[ctx.status] : true;
|
|
1181
|
-
return typeMatch && statusMatch;
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
function mapActionResult() {
|
|
1185
|
-
return map(({ action, status, error }) => {
|
|
1186
|
-
return {
|
|
1187
|
-
action,
|
|
1188
|
-
result: {
|
|
1189
|
-
successful: "SUCCESSFUL" /* ActionStatus.Successful */ === status,
|
|
1190
|
-
canceled: "CANCELED" /* ActionStatus.Canceled */ === status,
|
|
1191
|
-
error
|
|
1192
|
-
}
|
|
1193
|
-
};
|
|
1194
|
-
});
|
|
1195
|
-
}
|
|
1196
|
-
function mapAction() {
|
|
1197
|
-
return map((ctx) => ctx.action);
|
|
1198
|
-
}
|
|
1199
|
-
function createAllowedActionTypesMap(types) {
|
|
1200
|
-
return types.reduce((filterMap, klass) => {
|
|
1201
|
-
filterMap[getActionTypeFromInstance(klass)] = true;
|
|
1202
|
-
return filterMap;
|
|
1203
|
-
}, {});
|
|
1204
|
-
}
|
|
1205
|
-
function createAllowedStatusesMap(statuses) {
|
|
1206
|
-
return statuses.reduce((filterMap, status) => {
|
|
1207
|
-
filterMap[status] = true;
|
|
1208
|
-
return filterMap;
|
|
1209
|
-
}, {});
|
|
1210
|
-
}
|
|
1211
|
-
|
|
1212
|
-
const stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
|
|
1213
|
-
function ensureStateNameIsValid(name) {
|
|
1214
|
-
if (!name) {
|
|
1215
|
-
throwStateNamePropertyError();
|
|
1216
|
-
}
|
|
1217
|
-
else if (!stateNameRegex.test(name)) {
|
|
1218
|
-
throwStateNameError(name);
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
function ensureStateNameIsUnique(stateName, state, statesByName) {
|
|
1222
|
-
const existingState = statesByName[stateName];
|
|
1223
|
-
if (existingState && existingState !== state) {
|
|
1224
|
-
throwStateUniqueError(stateName, state.name, existingState.name);
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
function ensureStatesAreDecorated(stateClasses) {
|
|
1228
|
-
stateClasses.forEach((stateClass) => {
|
|
1229
|
-
if (!getStoreMetadata$1(stateClass)) {
|
|
1230
|
-
throwStateDecoratorError(stateClass.name);
|
|
1231
|
-
}
|
|
1232
|
-
});
|
|
1233
|
-
}
|
|
1234
|
-
|
|
1235
|
-
/**
|
|
1236
|
-
* All provided or injected tokens must have `@Injectable` decorator
|
|
1237
|
-
* (previously, injected tokens without `@Injectable` were allowed
|
|
1238
|
-
* if another decorator was used, e.g. pipes).
|
|
1239
|
-
*/
|
|
1240
|
-
function ensureStateClassIsInjectable(stateClass) {
|
|
1241
|
-
if (jit_hasInjectableAnnotation(stateClass) || aot_hasNgInjectableDef(stateClass)) {
|
|
1242
|
-
return;
|
|
1243
|
-
}
|
|
1244
|
-
console.warn(getUndecoratedStateInIvyWarningMessage(stateClass.name));
|
|
1245
|
-
}
|
|
1246
|
-
function aot_hasNgInjectableDef(stateClass) {
|
|
1247
|
-
// `ɵprov` is a static property added by the NGCC compiler. It always exists in
|
|
1248
|
-
// AOT mode because this property is added before runtime. If an application is running in
|
|
1249
|
-
// JIT mode then this property can be added by the `@Injectable()` decorator. The `@Injectable()`
|
|
1250
|
-
// decorator has to go after the `@State()` decorator, thus we prevent users from unwanted DI errors.
|
|
1251
|
-
return !!stateClass.ɵprov;
|
|
1252
|
-
}
|
|
1253
|
-
function jit_hasInjectableAnnotation(stateClass) {
|
|
1254
|
-
// `ɵprov` doesn't exist in JIT mode (for instance when running unit tests with Jest).
|
|
1255
|
-
const annotations = stateClass.__annotations__ || [];
|
|
1256
|
-
return annotations.some((annotation) => (annotation === null || annotation === void 0 ? void 0 : annotation.ngMetadataName) === 'Injectable');
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
/**
|
|
1260
|
-
* Init action
|
|
1261
|
-
*/
|
|
1262
|
-
class InitState {
|
|
1263
|
-
}
|
|
1264
|
-
InitState.type = '@@INIT';
|
|
1265
|
-
/**
|
|
1266
|
-
* Update action
|
|
1267
|
-
*/
|
|
1268
|
-
class UpdateState {
|
|
1269
|
-
constructor(addedStates) {
|
|
1270
|
-
this.addedStates = addedStates;
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
UpdateState.type = '@@UPDATE_STATE';
|
|
1274
|
-
|
|
1275
|
-
const NGXS_DEVELOPMENT_OPTIONS = new InjectionToken('NGXS_DEVELOPMENT_OPTIONS', {
|
|
1276
|
-
providedIn: 'root',
|
|
1277
|
-
factory: () => ({ warnOnUnhandledActions: true })
|
|
1278
|
-
});
|
|
1279
|
-
|
|
1280
|
-
class NgxsUnhandledActionsLogger {
|
|
1281
|
-
constructor(options) {
|
|
1282
|
-
/**
|
|
1283
|
-
* These actions should be ignored by default; the user can increase this
|
|
1284
|
-
* list in the future via the `ignoreActions` method.
|
|
1285
|
-
*/
|
|
1286
|
-
this._ignoredActions = new Set([InitState.type, UpdateState.type]);
|
|
1287
|
-
if (typeof options.warnOnUnhandledActions === 'object') {
|
|
1288
|
-
this.ignoreActions(...options.warnOnUnhandledActions.ignore);
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
/**
|
|
1292
|
-
* Adds actions to the internal list of actions that should be ignored.
|
|
1293
|
-
*/
|
|
1294
|
-
ignoreActions(...actions) {
|
|
1295
|
-
for (const action of actions) {
|
|
1296
|
-
this._ignoredActions.add(action.type);
|
|
1297
|
-
}
|
|
1298
|
-
}
|
|
1299
|
-
/** @internal */
|
|
1300
|
-
warn(action) {
|
|
1301
|
-
const actionShouldBeIgnored = Array.from(this._ignoredActions).some(type => type === getActionTypeFromInstance(action));
|
|
1302
|
-
if (actionShouldBeIgnored) {
|
|
1303
|
-
return;
|
|
1304
|
-
}
|
|
1305
|
-
action =
|
|
1306
|
-
action.constructor && action.constructor.name !== 'Object'
|
|
1307
|
-
? action.constructor.name
|
|
1308
|
-
: action.type;
|
|
1309
|
-
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.`);
|
|
1310
|
-
}
|
|
1311
|
-
}
|
|
1312
|
-
/** @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 });
|
|
1313
|
-
/** @nocollapse */ NgxsUnhandledActionsLogger.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsUnhandledActionsLogger });
|
|
1314
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsUnhandledActionsLogger, decorators: [{
|
|
1315
|
-
type: Injectable
|
|
1316
|
-
}], ctorParameters: function () {
|
|
1317
|
-
return [{ type: undefined, decorators: [{
|
|
1318
|
-
type: Inject,
|
|
1319
|
-
args: [NGXS_DEVELOPMENT_OPTIONS]
|
|
1320
|
-
}] }];
|
|
1321
|
-
} });
|
|
1322
|
-
|
|
1323
|
-
function simplePatch(value) {
|
|
1324
|
-
return (existingState) => {
|
|
1325
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
1326
|
-
if (Array.isArray(value)) {
|
|
1327
|
-
throwPatchingArrayError();
|
|
1328
|
-
}
|
|
1329
|
-
else if (typeof value !== 'object') {
|
|
1330
|
-
throwPatchingPrimitiveError();
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
const newState = Object.assign({}, existingState);
|
|
1334
|
-
for (const key in value) {
|
|
1335
|
-
// deep clone for patch compatibility
|
|
1336
|
-
newState[key] = value[key];
|
|
1337
|
-
}
|
|
1338
|
-
return newState;
|
|
1339
|
-
};
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
/**
|
|
1343
|
-
* State Context factory class
|
|
1344
|
-
* @ignore
|
|
1345
|
-
*/
|
|
1346
|
-
class StateContextFactory {
|
|
1347
|
-
constructor(_internalStateOperations) {
|
|
1348
|
-
this._internalStateOperations = _internalStateOperations;
|
|
1349
|
-
}
|
|
1350
|
-
/**
|
|
1351
|
-
* Create the state context
|
|
1352
|
-
*/
|
|
1353
|
-
createStateContext(mappedStore) {
|
|
1354
|
-
const root = this._internalStateOperations.getRootStateOperations();
|
|
1355
|
-
return {
|
|
1356
|
-
getState() {
|
|
1357
|
-
const currentAppState = root.getState();
|
|
1358
|
-
return getState(currentAppState, mappedStore.path);
|
|
1359
|
-
},
|
|
1360
|
-
patchState(val) {
|
|
1361
|
-
const currentAppState = root.getState();
|
|
1362
|
-
const patchOperator = simplePatch(val);
|
|
1363
|
-
return setStateFromOperator(root, currentAppState, patchOperator, mappedStore.path);
|
|
1364
|
-
},
|
|
1365
|
-
setState(val) {
|
|
1366
|
-
const currentAppState = root.getState();
|
|
1367
|
-
return isStateOperator(val)
|
|
1368
|
-
? setStateFromOperator(root, currentAppState, val, mappedStore.path)
|
|
1369
|
-
: setStateValue(root, currentAppState, val, mappedStore.path);
|
|
1370
|
-
},
|
|
1371
|
-
dispatch(actions) {
|
|
1372
|
-
return root.dispatch(actions);
|
|
1373
|
-
}
|
|
1374
|
-
};
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
/** @nocollapse */ StateContextFactory.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateContextFactory, deps: [{ token: InternalStateOperations }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
1378
|
-
/** @nocollapse */ StateContextFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateContextFactory, providedIn: 'root' });
|
|
1379
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateContextFactory, decorators: [{
|
|
1380
|
-
type: Injectable,
|
|
1381
|
-
args: [{ providedIn: 'root' }]
|
|
1382
|
-
}], ctorParameters: function () { return [{ type: InternalStateOperations }]; } });
|
|
1383
|
-
function setStateValue(root, currentAppState, newValue, path) {
|
|
1384
|
-
const newAppState = setValue(currentAppState, path, newValue);
|
|
1385
|
-
root.setState(newAppState);
|
|
1386
|
-
return newAppState;
|
|
1387
|
-
// In doing this refactoring I noticed that there is a 'bug' where the
|
|
1388
|
-
// application state is returned instead of this state slice.
|
|
1389
|
-
// This has worked this way since the beginning see:
|
|
1390
|
-
// https://github.com/ngxs/store/blame/324c667b4b7debd8eb979006c67ca0ae347d88cd/src/state-factory.ts
|
|
1391
|
-
// This needs to be fixed, but is a 'breaking' change.
|
|
1392
|
-
// I will do this fix in a subsequent PR and we can decide how to handle it.
|
|
1393
|
-
}
|
|
1394
|
-
function setStateFromOperator(root, currentAppState, stateOperator, path) {
|
|
1395
|
-
const local = getState(currentAppState, path);
|
|
1396
|
-
const newValue = stateOperator(local);
|
|
1397
|
-
return setStateValue(root, currentAppState, newValue, path);
|
|
1398
|
-
}
|
|
1399
|
-
function getState(currentAppState, path) {
|
|
1400
|
-
return getValue(currentAppState, path);
|
|
1401
|
-
}
|
|
1402
|
-
|
|
1403
|
-
const NG_DEV_MODE$2 = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
1404
|
-
/**
|
|
1405
|
-
* The `StateFactory` class adds root and feature states to the graph.
|
|
1406
|
-
* This extracts state names from state classes, checks if they already
|
|
1407
|
-
* exist in the global graph, throws errors if their names are invalid, etc.
|
|
1408
|
-
* See its constructor, state factories inject state factories that are
|
|
1409
|
-
* parent-level providers. This is required to get feature states from the
|
|
1410
|
-
* injector on the same level.
|
|
1411
|
-
*
|
|
1412
|
-
* The `NgxsModule.forFeature(...)` returns `providers: [StateFactory, ...states]`.
|
|
1413
|
-
* The `StateFactory` is initialized on the feature level and goes through `...states`
|
|
1414
|
-
* to get them from the injector through `injector.get(state)`.
|
|
1415
|
-
* @ignore
|
|
1416
|
-
*/
|
|
1417
|
-
class StateFactory {
|
|
1418
|
-
constructor(_injector, _config, _parentFactory, _actions, _actionResults, _stateContextFactory, _initialState) {
|
|
1419
|
-
this._injector = _injector;
|
|
1420
|
-
this._config = _config;
|
|
1421
|
-
this._parentFactory = _parentFactory;
|
|
1422
|
-
this._actions = _actions;
|
|
1423
|
-
this._actionResults = _actionResults;
|
|
1424
|
-
this._stateContextFactory = _stateContextFactory;
|
|
1425
|
-
this._initialState = _initialState;
|
|
1426
|
-
this._actionsSubscription = null;
|
|
1427
|
-
this._states = [];
|
|
1428
|
-
this._statesByName = {};
|
|
1429
|
-
this._statePaths = {};
|
|
1430
|
-
this.getRuntimeSelectorContext = memoize(() => {
|
|
1431
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
1432
|
-
const stateFactory = this;
|
|
1433
|
-
function resolveGetter(key) {
|
|
1434
|
-
const path = stateFactory.statePaths[key];
|
|
1435
|
-
return path ? propGetter(path.split('.'), stateFactory._config) : null;
|
|
1436
|
-
}
|
|
1437
|
-
const context = this._parentFactory
|
|
1438
|
-
? this._parentFactory.getRuntimeSelectorContext()
|
|
1439
|
-
: {
|
|
1440
|
-
getStateGetter(key) {
|
|
1441
|
-
// Use `@__INLINE__` annotation to forcely inline `resolveGetter`.
|
|
1442
|
-
// This is a Terser annotation, which will function only in the production mode.
|
|
1443
|
-
let getter = /*@__INLINE__*/ resolveGetter(key);
|
|
1444
|
-
if (getter) {
|
|
1445
|
-
return getter;
|
|
1446
|
-
}
|
|
1447
|
-
return (...args) => {
|
|
1448
|
-
// Late loaded getter
|
|
1449
|
-
if (!getter) {
|
|
1450
|
-
getter = /*@__INLINE__*/ resolveGetter(key);
|
|
1451
|
-
}
|
|
1452
|
-
return getter ? getter(...args) : undefined;
|
|
1453
|
-
};
|
|
1454
|
-
},
|
|
1455
|
-
getSelectorOptions(localOptions) {
|
|
1456
|
-
const globalSelectorOptions = stateFactory._config.selectorOptions;
|
|
1457
|
-
return Object.assign(Object.assign({}, globalSelectorOptions), (localOptions || {}));
|
|
1458
|
-
}
|
|
1459
|
-
};
|
|
1460
|
-
return context;
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1463
|
-
get states() {
|
|
1464
|
-
return this._parentFactory ? this._parentFactory.states : this._states;
|
|
1465
|
-
}
|
|
1466
|
-
get statesByName() {
|
|
1467
|
-
return this._parentFactory ? this._parentFactory.statesByName : this._statesByName;
|
|
1468
|
-
}
|
|
1469
|
-
get statePaths() {
|
|
1470
|
-
return this._parentFactory ? this._parentFactory.statePaths : this._statePaths;
|
|
1471
|
-
}
|
|
1472
|
-
static _cloneDefaults(defaults) {
|
|
1473
|
-
let value = defaults;
|
|
1474
|
-
if (Array.isArray(defaults)) {
|
|
1475
|
-
value = defaults.slice();
|
|
1476
|
-
}
|
|
1477
|
-
else if (isObject$1(defaults)) {
|
|
1478
|
-
value = Object.assign({}, defaults);
|
|
1479
|
-
}
|
|
1480
|
-
else if (defaults === undefined) {
|
|
1481
|
-
value = {};
|
|
1482
|
-
}
|
|
1483
|
-
return value;
|
|
1484
|
-
}
|
|
1485
|
-
ngOnDestroy() {
|
|
1486
|
-
var _a;
|
|
1487
|
-
(_a = this._actionsSubscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
1488
|
-
}
|
|
1489
|
-
/**
|
|
1490
|
-
* Add a new state to the global defs.
|
|
1491
|
-
*/
|
|
1492
|
-
add(stateClasses) {
|
|
1493
|
-
if (NG_DEV_MODE$2) {
|
|
1494
|
-
ensureStatesAreDecorated(stateClasses);
|
|
1495
|
-
}
|
|
1496
|
-
const { newStates } = this.addToStatesMap(stateClasses);
|
|
1497
|
-
if (!newStates.length)
|
|
1498
|
-
return [];
|
|
1499
|
-
const stateGraph = buildGraph(newStates);
|
|
1500
|
-
const sortedStates = topologicalSort(stateGraph);
|
|
1501
|
-
const paths = findFullParentPath(stateGraph);
|
|
1502
|
-
const nameGraph = nameToState(newStates);
|
|
1503
|
-
const bootstrappedStores = [];
|
|
1504
|
-
for (const name of sortedStates) {
|
|
1505
|
-
const stateClass = nameGraph[name];
|
|
1506
|
-
const path = paths[name];
|
|
1507
|
-
const meta = stateClass[ɵMETA_KEY];
|
|
1508
|
-
this.addRuntimeInfoToMeta(meta, path);
|
|
1509
|
-
// Note: previously we called `ensureStateClassIsInjectable` within the
|
|
1510
|
-
// `State` decorator. This check is moved here because the `ɵprov` property
|
|
1511
|
-
// will not exist on the class in JIT mode (because it's set asynchronously
|
|
1512
|
-
// during JIT compilation through `Object.defineProperty`).
|
|
1513
|
-
if (NG_DEV_MODE$2) {
|
|
1514
|
-
ensureStateClassIsInjectable(stateClass);
|
|
1515
|
-
}
|
|
1516
|
-
const stateMap = {
|
|
1517
|
-
name,
|
|
1518
|
-
path,
|
|
1519
|
-
isInitialised: false,
|
|
1520
|
-
actions: meta.actions,
|
|
1521
|
-
instance: this._injector.get(stateClass),
|
|
1522
|
-
defaults: StateFactory._cloneDefaults(meta.defaults)
|
|
1523
|
-
};
|
|
1524
|
-
// ensure our store hasn't already been added
|
|
1525
|
-
// but don't throw since it could be lazy
|
|
1526
|
-
// loaded from different paths
|
|
1527
|
-
if (!this.hasBeenMountedAndBootstrapped(name, path)) {
|
|
1528
|
-
bootstrappedStores.push(stateMap);
|
|
1529
|
-
}
|
|
1530
|
-
this.states.push(stateMap);
|
|
1531
|
-
}
|
|
1532
|
-
return bootstrappedStores;
|
|
1533
|
-
}
|
|
1534
|
-
/**
|
|
1535
|
-
* Add a set of states to the store and return the defaults
|
|
1536
|
-
*/
|
|
1537
|
-
addAndReturnDefaults(stateClasses) {
|
|
1538
|
-
const classes = stateClasses || [];
|
|
1539
|
-
const mappedStores = this.add(classes);
|
|
1540
|
-
const defaults = mappedStores.reduce((result, mappedStore) => setValue(result, mappedStore.path, mappedStore.defaults), {});
|
|
1541
|
-
return { defaults, states: mappedStores };
|
|
1542
|
-
}
|
|
1543
|
-
connectActionHandlers() {
|
|
1544
|
-
// Note: We have to connect actions only once when the `StateFactory`
|
|
1545
|
-
// is being created for the first time. This checks if we're in
|
|
1546
|
-
// a child state factory and the parent state factory already exists.
|
|
1547
|
-
if (this._parentFactory || this._actionsSubscription !== null) {
|
|
1548
|
-
return;
|
|
1549
|
-
}
|
|
1550
|
-
const dispatched$ = new Subject();
|
|
1551
|
-
this._actionsSubscription = this._actions
|
|
1552
|
-
.pipe(filter((ctx) => ctx.status === "DISPATCHED" /* ActionStatus.Dispatched */), mergeMap(ctx => {
|
|
1553
|
-
dispatched$.next(ctx);
|
|
1554
|
-
const action = ctx.action;
|
|
1555
|
-
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 })));
|
|
1556
|
-
}))
|
|
1557
|
-
.subscribe(ctx => this._actionResults.next(ctx));
|
|
1558
|
-
}
|
|
1559
|
-
/**
|
|
1560
|
-
* Invoke actions on the states.
|
|
1561
|
-
*/
|
|
1562
|
-
invokeActions(dispatched$, action) {
|
|
1563
|
-
const type = getActionTypeFromInstance(action);
|
|
1564
|
-
const results = [];
|
|
1565
|
-
// Determines whether the dispatched action has been handled, this is assigned
|
|
1566
|
-
// to `true` within the below `for` loop if any `actionMetas` has been found.
|
|
1567
|
-
let actionHasBeenHandled = false;
|
|
1568
|
-
for (const metadata of this.states) {
|
|
1569
|
-
const actionMetas = metadata.actions[type];
|
|
1570
|
-
if (actionMetas) {
|
|
1571
|
-
for (const actionMeta of actionMetas) {
|
|
1572
|
-
const stateContext = this._stateContextFactory.createStateContext(metadata);
|
|
1573
|
-
try {
|
|
1574
|
-
let result = metadata.instance[actionMeta.fn](stateContext, action);
|
|
1575
|
-
if (result instanceof Promise) {
|
|
1576
|
-
result = from(result);
|
|
1577
|
-
}
|
|
1578
|
-
if (isObservable(result)) {
|
|
1579
|
-
// If this observable has been completed w/o emitting
|
|
1580
|
-
// any value then we wouldn't want to complete the whole chain
|
|
1581
|
-
// of actions. Since if any observable completes then
|
|
1582
|
-
// action will be canceled.
|
|
1583
|
-
// For instance if any action handler would've had such statement:
|
|
1584
|
-
// `handler(ctx) { return EMPTY; }`
|
|
1585
|
-
// then the action will be canceled.
|
|
1586
|
-
// See https://github.com/ngxs/store/issues/1568
|
|
1587
|
-
result = result.pipe(mergeMap((value) => {
|
|
1588
|
-
if (value instanceof Promise) {
|
|
1589
|
-
return from(value);
|
|
1590
|
-
}
|
|
1591
|
-
if (isObservable(value)) {
|
|
1592
|
-
return value;
|
|
1593
|
-
}
|
|
1594
|
-
return of(value);
|
|
1595
|
-
}), defaultIfEmpty({}));
|
|
1596
|
-
if (actionMeta.options.cancelUncompleted) {
|
|
1597
|
-
// todo: ofActionDispatched should be used with action class
|
|
1598
|
-
result = result.pipe(takeUntil(dispatched$.pipe(ofActionDispatched(action))));
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
else {
|
|
1602
|
-
result = of({}).pipe(shareReplay());
|
|
1603
|
-
}
|
|
1604
|
-
results.push(result);
|
|
1605
|
-
}
|
|
1606
|
-
catch (e) {
|
|
1607
|
-
results.push(throwError(e));
|
|
1608
|
-
}
|
|
1609
|
-
actionHasBeenHandled = true;
|
|
1610
|
-
}
|
|
1611
|
-
}
|
|
1612
|
-
}
|
|
1613
|
-
// The `NgxsUnhandledActionsLogger` is a tree-shakable class which functions
|
|
1614
|
-
// only during development.
|
|
1615
|
-
if (NG_DEV_MODE$2 && !actionHasBeenHandled) {
|
|
1616
|
-
const unhandledActionsLogger = this._injector.get(NgxsUnhandledActionsLogger, null);
|
|
1617
|
-
// The `NgxsUnhandledActionsLogger` will not be resolved by the injector if the
|
|
1618
|
-
// `NgxsDevelopmentModule` is not provided. It's enough to check whether the `injector.get`
|
|
1619
|
-
// didn't return `null` so we may ensure the module has been imported.
|
|
1620
|
-
if (unhandledActionsLogger) {
|
|
1621
|
-
unhandledActionsLogger.warn(action);
|
|
1622
|
-
}
|
|
1623
|
-
}
|
|
1624
|
-
if (!results.length) {
|
|
1625
|
-
results.push(of({}));
|
|
1626
|
-
}
|
|
1627
|
-
return forkJoin(results);
|
|
1628
|
-
}
|
|
1629
|
-
addToStatesMap(stateClasses) {
|
|
1630
|
-
const newStates = [];
|
|
1631
|
-
const statesMap = this.statesByName;
|
|
1632
|
-
for (const stateClass of stateClasses) {
|
|
1633
|
-
const stateName = getStoreMetadata$1(stateClass).name;
|
|
1634
|
-
if (NG_DEV_MODE$2) {
|
|
1635
|
-
ensureStateNameIsUnique(stateName, stateClass, statesMap);
|
|
1636
|
-
}
|
|
1637
|
-
const unmountedState = !statesMap[stateName];
|
|
1638
|
-
if (unmountedState) {
|
|
1639
|
-
newStates.push(stateClass);
|
|
1640
|
-
statesMap[stateName] = stateClass;
|
|
1641
|
-
}
|
|
1642
|
-
}
|
|
1643
|
-
return { newStates };
|
|
1644
|
-
}
|
|
1645
|
-
addRuntimeInfoToMeta(meta, path) {
|
|
1646
|
-
this.statePaths[meta.name] = path;
|
|
1647
|
-
// TODO: v4 - we plan to get rid of the path property because it is non-deterministic
|
|
1648
|
-
// we can do this when we get rid of the incorrectly exposed getStoreMetadata
|
|
1649
|
-
// We will need to come up with an alternative in v4 because this is used by many plugins
|
|
1650
|
-
meta.path = path;
|
|
1651
|
-
}
|
|
1652
|
-
hasBeenMountedAndBootstrapped(name, path) {
|
|
1653
|
-
const valueIsBootstrappedInInitialState = getValue(this._initialState, path) !== undefined;
|
|
1654
|
-
// This checks whether a state has been already added to the global graph and
|
|
1655
|
-
// its lifecycle is in 'bootstrapped' state.
|
|
1656
|
-
return this.statesByName[name] && valueIsBootstrappedInInitialState;
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
/** @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 });
|
|
1660
|
-
/** @nocollapse */ StateFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateFactory });
|
|
1661
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: StateFactory, decorators: [{
|
|
1662
|
-
type: Injectable
|
|
1663
|
-
}], ctorParameters: function () {
|
|
1664
|
-
return [{ type: i0.Injector }, { type: NgxsConfig }, { type: StateFactory, decorators: [{
|
|
1665
|
-
type: Optional
|
|
1666
|
-
}, {
|
|
1667
|
-
type: SkipSelf
|
|
1668
|
-
}] }, { type: InternalActions }, { type: InternalDispatchedActionResults }, { type: StateContextFactory }, { type: undefined, decorators: [{
|
|
1669
|
-
type: Optional
|
|
1670
|
-
}, {
|
|
1671
|
-
type: Inject,
|
|
1672
|
-
args: [INITIAL_STATE_TOKEN]
|
|
1673
|
-
}] }];
|
|
1674
|
-
} });
|
|
1675
|
-
|
|
1676
|
-
// tslint:disable:unified-signatures
|
|
1677
|
-
class Store {
|
|
1678
|
-
constructor(_stateStream, _internalStateOperations, _config, _internalExecutionStrategy, _stateFactory, initialStateValue) {
|
|
1679
|
-
this._stateStream = _stateStream;
|
|
1680
|
-
this._internalStateOperations = _internalStateOperations;
|
|
1681
|
-
this._config = _config;
|
|
1682
|
-
this._internalExecutionStrategy = _internalExecutionStrategy;
|
|
1683
|
-
this._stateFactory = _stateFactory;
|
|
1684
|
-
/**
|
|
1685
|
-
* This is a derived state stream that leaves NGXS execution strategy to emit state changes within the Angular zone,
|
|
1686
|
-
* because state is being changed actually within the `<root>` zone, see `InternalDispatcher#dispatchSingle`.
|
|
1687
|
-
* All selects would use this stream, and it would call leave only once for any state change across all active selectors.
|
|
1688
|
-
*/
|
|
1689
|
-
this._selectableStateStream = this._stateStream.pipe(leaveNgxs(this._internalExecutionStrategy), shareReplay({ bufferSize: 1, refCount: true }));
|
|
1690
|
-
this.initStateStream(initialStateValue);
|
|
1691
|
-
}
|
|
1692
|
-
/**
|
|
1693
|
-
* Dispatches event(s).
|
|
1694
|
-
*/
|
|
1695
|
-
dispatch(actionOrActions) {
|
|
1696
|
-
return this._internalStateOperations.getRootStateOperations().dispatch(actionOrActions);
|
|
1697
|
-
}
|
|
1698
|
-
select(selector) {
|
|
1699
|
-
const selectorFn = this.getStoreBoundSelectorFn(selector);
|
|
1700
|
-
return this._selectableStateStream.pipe(map(selectorFn), catchError((err) => {
|
|
1701
|
-
// if error is TypeError we swallow it to prevent usual errors with property access
|
|
1702
|
-
const { suppressErrors } = this._config.selectorOptions;
|
|
1703
|
-
if (err instanceof TypeError && suppressErrors) {
|
|
1704
|
-
return of(undefined);
|
|
1705
|
-
}
|
|
1706
|
-
// rethrow other errors
|
|
1707
|
-
return throwError(err);
|
|
1708
|
-
}), distinctUntilChanged(), leaveNgxs(this._internalExecutionStrategy));
|
|
1709
|
-
}
|
|
1710
|
-
selectOnce(selector) {
|
|
1711
|
-
return this.select(selector).pipe(take(1));
|
|
1712
|
-
}
|
|
1713
|
-
selectSnapshot(selector) {
|
|
1714
|
-
const selectorFn = this.getStoreBoundSelectorFn(selector);
|
|
1715
|
-
return selectorFn(this._stateStream.getValue());
|
|
1716
|
-
}
|
|
1717
|
-
/**
|
|
1718
|
-
* Allow the user to subscribe to the root of the state
|
|
1719
|
-
*/
|
|
1720
|
-
subscribe(fn) {
|
|
1721
|
-
return this._selectableStateStream
|
|
1722
|
-
.pipe(leaveNgxs(this._internalExecutionStrategy))
|
|
1723
|
-
.subscribe(fn);
|
|
1724
|
-
}
|
|
1725
|
-
/**
|
|
1726
|
-
* Return the raw value of the state.
|
|
1727
|
-
*/
|
|
1728
|
-
snapshot() {
|
|
1729
|
-
return this._internalStateOperations.getRootStateOperations().getState();
|
|
1730
|
-
}
|
|
1731
|
-
/**
|
|
1732
|
-
* Reset the state to a specific point in time. This method is useful
|
|
1733
|
-
* for plugin's who need to modify the state directly or unit testing.
|
|
1734
|
-
*/
|
|
1735
|
-
reset(state) {
|
|
1736
|
-
return this._internalStateOperations.getRootStateOperations().setState(state);
|
|
1737
|
-
}
|
|
1738
|
-
getStoreBoundSelectorFn(selector) {
|
|
1739
|
-
const makeSelectorFn = getRootSelectorFactory(selector);
|
|
1740
|
-
const runtimeContext = this._stateFactory.getRuntimeSelectorContext();
|
|
1741
|
-
return makeSelectorFn(runtimeContext);
|
|
1742
|
-
}
|
|
1743
|
-
initStateStream(initialStateValue) {
|
|
1744
|
-
const value = this._stateStream.value;
|
|
1745
|
-
const storeIsEmpty = !value || Object.keys(value).length === 0;
|
|
1746
|
-
if (storeIsEmpty) {
|
|
1747
|
-
const defaultStateNotEmpty = Object.keys(this._config.defaultsState).length > 0;
|
|
1748
|
-
const storeValues = defaultStateNotEmpty
|
|
1749
|
-
? Object.assign(Object.assign({}, this._config.defaultsState), initialStateValue) : initialStateValue;
|
|
1750
|
-
this._stateStream.next(storeValues);
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
}
|
|
1754
|
-
/** @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 });
|
|
1755
|
-
/** @nocollapse */ Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Store, providedIn: 'root' });
|
|
1756
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: Store, decorators: [{
|
|
1757
|
-
type: Injectable,
|
|
1758
|
-
args: [{ providedIn: 'root' }]
|
|
1759
|
-
}], ctorParameters: function () {
|
|
1760
|
-
return [{ type: StateStream }, { type: InternalStateOperations }, { type: NgxsConfig }, { type: InternalNgxsExecutionStrategy }, { type: StateFactory }, { type: undefined, decorators: [{
|
|
1761
|
-
type: Optional
|
|
1762
|
-
}, {
|
|
1763
|
-
type: Inject,
|
|
1764
|
-
args: [INITIAL_STATE_TOKEN]
|
|
1765
|
-
}] }];
|
|
1766
|
-
} });
|
|
1767
|
-
|
|
1768
|
-
/**
|
|
1769
|
-
* Allows the select decorator to get access to the DI store, this is used internally
|
|
1770
|
-
* in `@Select` decorator.
|
|
1771
|
-
*/
|
|
1772
|
-
class SelectFactory {
|
|
1773
|
-
constructor(store, config) {
|
|
1774
|
-
SelectFactory.store = store;
|
|
1775
|
-
SelectFactory.config = config;
|
|
1776
|
-
}
|
|
1777
|
-
ngOnDestroy() {
|
|
1778
|
-
SelectFactory.store = null;
|
|
1779
|
-
SelectFactory.config = null;
|
|
1780
|
-
}
|
|
1781
|
-
}
|
|
1782
|
-
SelectFactory.store = null;
|
|
1783
|
-
SelectFactory.config = null;
|
|
1784
|
-
/** @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 });
|
|
1785
|
-
/** @nocollapse */ SelectFactory.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: SelectFactory, providedIn: 'root' });
|
|
1786
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: SelectFactory, decorators: [{
|
|
1787
|
-
type: Injectable,
|
|
1788
|
-
args: [{ providedIn: 'root' }]
|
|
1789
|
-
}], ctorParameters: function () { return [{ type: Store }, { type: NgxsConfig }]; } });
|
|
1790
|
-
|
|
1791
|
-
const NG_DEV_MODE$1 = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
1792
|
-
class LifecycleStateManager {
|
|
1793
|
-
constructor(_store, _internalErrorReporter, _internalStateOperations, _stateContextFactory, _bootstrapper) {
|
|
1794
|
-
this._store = _store;
|
|
1795
|
-
this._internalErrorReporter = _internalErrorReporter;
|
|
1796
|
-
this._internalStateOperations = _internalStateOperations;
|
|
1797
|
-
this._stateContextFactory = _stateContextFactory;
|
|
1798
|
-
this._bootstrapper = _bootstrapper;
|
|
1799
|
-
this._destroy$ = new ReplaySubject(1);
|
|
1800
|
-
}
|
|
1801
|
-
ngOnDestroy() {
|
|
1802
|
-
this._destroy$.next();
|
|
1803
|
-
}
|
|
1804
|
-
ngxsBootstrap(action, results) {
|
|
1805
|
-
if (NG_DEV_MODE$1) {
|
|
1806
|
-
if (action instanceof InitState) {
|
|
1807
|
-
this._initStateHasBeenDispatched = true;
|
|
1808
|
-
}
|
|
1809
|
-
else if (
|
|
1810
|
-
// This is a dev mode-only check that ensures the correct order of
|
|
1811
|
-
// state initialization. The `NgxsModule.forRoot` or `provideStore` should
|
|
1812
|
-
// always come first, followed by `forFeature` and `provideStates`. If the
|
|
1813
|
-
// `UpdateState` is dispatched before the `InitState` is dispatched, it indicates
|
|
1814
|
-
// that modules or providers are in an invalid order.
|
|
1815
|
-
action instanceof UpdateState &&
|
|
1816
|
-
!this._initStateHasBeenDispatched) {
|
|
1817
|
-
console.error(getInvalidInitializationOrderMessage(action.addedStates));
|
|
1818
|
-
}
|
|
1819
|
-
}
|
|
1820
|
-
this._internalStateOperations
|
|
1821
|
-
.getRootStateOperations()
|
|
1822
|
-
.dispatch(action)
|
|
1823
|
-
.pipe(filter(() => !!results), tap(() => this._invokeInitOnStates(results.states)), mergeMap(() => this._bootstrapper.appBootstrapped$), filter(appBootstrapped => !!appBootstrapped), catchError(error => {
|
|
1824
|
-
// The `SafeSubscriber` (which is used by most RxJS operators) re-throws
|
|
1825
|
-
// errors asynchronously (`setTimeout(() => { throw error })`). This might
|
|
1826
|
-
// break existing user's code or unit tests. We catch the error manually to
|
|
1827
|
-
// be backward compatible with the old behavior.
|
|
1828
|
-
this._internalErrorReporter.reportErrorSafely(error);
|
|
1829
|
-
return EMPTY;
|
|
1830
|
-
}), takeUntil(this._destroy$))
|
|
1831
|
-
.subscribe(() => this._invokeBootstrapOnStates(results.states));
|
|
1832
|
-
}
|
|
1833
|
-
_invokeInitOnStates(mappedStores) {
|
|
1834
|
-
for (const mappedStore of mappedStores) {
|
|
1835
|
-
const instance = mappedStore.instance;
|
|
1836
|
-
if (instance.ngxsOnChanges) {
|
|
1837
|
-
this._store
|
|
1838
|
-
.select(state => getValue(state, mappedStore.path))
|
|
1839
|
-
.pipe(startWith(undefined), pairwise(), takeUntil(this._destroy$))
|
|
1840
|
-
.subscribe(([previousValue, currentValue]) => {
|
|
1841
|
-
const change = new NgxsSimpleChange(previousValue, currentValue, !mappedStore.isInitialised);
|
|
1842
|
-
instance.ngxsOnChanges(change);
|
|
1843
|
-
});
|
|
1844
|
-
}
|
|
1845
|
-
if (instance.ngxsOnInit) {
|
|
1846
|
-
instance.ngxsOnInit(this._getStateContext(mappedStore));
|
|
1847
|
-
}
|
|
1848
|
-
mappedStore.isInitialised = true;
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
_invokeBootstrapOnStates(mappedStores) {
|
|
1852
|
-
for (const mappedStore of mappedStores) {
|
|
1853
|
-
const instance = mappedStore.instance;
|
|
1854
|
-
if (instance.ngxsAfterBootstrap) {
|
|
1855
|
-
instance.ngxsAfterBootstrap(this._getStateContext(mappedStore));
|
|
1856
|
-
}
|
|
1857
|
-
}
|
|
1858
|
-
}
|
|
1859
|
-
_getStateContext(mappedStore) {
|
|
1860
|
-
return this._stateContextFactory.createStateContext(mappedStore);
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
/** @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 });
|
|
1864
|
-
/** @nocollapse */ LifecycleStateManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: LifecycleStateManager, providedIn: 'root' });
|
|
1865
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: LifecycleStateManager, decorators: [{
|
|
1866
|
-
type: Injectable,
|
|
1867
|
-
args: [{ providedIn: 'root' }]
|
|
1868
|
-
}], ctorParameters: function () { return [{ type: Store }, { type: InternalErrorReporter }, { type: InternalStateOperations }, { type: StateContextFactory }, { type: i5.NgxsBootstrapper }]; } });
|
|
1869
|
-
|
|
1870
|
-
const NG_DEV_MODE = typeof ngDevMode === 'undefined' || ngDevMode;
|
|
1871
|
-
/**
|
|
1872
|
-
* This function is shared by both NgModule and standalone features.
|
|
1873
|
-
* When using `NgxsModule.forRoot` and `provideStore`, we can depend on the
|
|
1874
|
-
* same initialization functionality.
|
|
1875
|
-
*/
|
|
1876
|
-
function rootStoreInitializer() {
|
|
1877
|
-
const factory = inject(StateFactory);
|
|
1878
|
-
const internalStateOperations = inject(InternalStateOperations);
|
|
1879
|
-
inject(Store);
|
|
1880
|
-
inject(SelectFactory);
|
|
1881
|
-
const states = inject(ROOT_STATE_TOKEN, { optional: true }) || [];
|
|
1882
|
-
const lifecycleStateManager = inject(LifecycleStateManager);
|
|
1883
|
-
// Add stores to the state graph and return their defaults.
|
|
1884
|
-
const results = factory.addAndReturnDefaults(states);
|
|
1885
|
-
internalStateOperations.setStateToTheCurrentWithNew(results);
|
|
1886
|
-
// Connect our actions stream.
|
|
1887
|
-
factory.connectActionHandlers();
|
|
1888
|
-
// Dispatch the init action and invoke init and bootstrap functions after.
|
|
1889
|
-
lifecycleStateManager.ngxsBootstrap(new InitState(), results);
|
|
1890
|
-
}
|
|
1891
|
-
/**
|
|
1892
|
-
* This function is utilized by both NgModule and standalone features.
|
|
1893
|
-
* When using `NgxsModule.forFeature` and `provideStates`, we can depend on
|
|
1894
|
-
* the same initialization functionality.
|
|
1895
|
-
*/
|
|
1896
|
-
function featureStatesInitializer() {
|
|
1897
|
-
inject(Store);
|
|
1898
|
-
const internalStateOperations = inject(InternalStateOperations);
|
|
1899
|
-
const factory = inject(StateFactory);
|
|
1900
|
-
const states = inject(FEATURE_STATE_TOKEN, { optional: true }) || [];
|
|
1901
|
-
const lifecycleStateManager = inject(LifecycleStateManager);
|
|
1902
|
-
// Since FEATURE_STATE_TOKEN is a multi token, we need to
|
|
1903
|
-
// flatten it [[Feature1State, Feature2State], [Feature3State]].
|
|
1904
|
-
const flattenedStates = states.reduce((total, values) => total.concat(values), []);
|
|
1905
|
-
// add stores to the state graph and return their defaults.
|
|
1906
|
-
const results = factory.addAndReturnDefaults(flattenedStates);
|
|
1907
|
-
if (results.states.length) {
|
|
1908
|
-
internalStateOperations.setStateToTheCurrentWithNew(results);
|
|
1909
|
-
// Dispatch the update action and invoke init and bootstrap functions after.
|
|
1910
|
-
lifecycleStateManager.ngxsBootstrap(new UpdateState(results.defaults), results);
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
/**
|
|
1914
|
-
* InjectionToken that registers the global Store.
|
|
1915
|
-
*/
|
|
1916
|
-
const NGXS_ROOT_STORE_INITIALIZER = new InjectionToken(NG_DEV_MODE ? 'NGXS_ROOT_STORE_INITIALIZER' : '');
|
|
1917
|
-
/**
|
|
1918
|
-
* InjectionToken that registers feature states.
|
|
1919
|
-
*/
|
|
1920
|
-
const NGXS_FEATURE_STORE_INITIALIZER = new InjectionToken(NG_DEV_MODE ? 'NGXS_FEATURE_STORE_INITIALIZER' : '');
|
|
1921
|
-
const NGXS_ROOT_ENVIRONMENT_INITIALIZER = [
|
|
1922
|
-
{ provide: NGXS_ROOT_STORE_INITIALIZER, useFactory: rootStoreInitializer },
|
|
1923
|
-
{
|
|
1924
|
-
provide: ENVIRONMENT_INITIALIZER,
|
|
1925
|
-
multi: true,
|
|
1926
|
-
useFactory() {
|
|
1927
|
-
return () => inject(NGXS_ROOT_STORE_INITIALIZER);
|
|
1928
|
-
}
|
|
1929
|
-
}
|
|
1930
|
-
];
|
|
1931
|
-
/**
|
|
1932
|
-
* The `NGXS_FEATURE_ENVIRONMENT_INITIALIZER` functions as an environment initializer
|
|
1933
|
-
* at the `Route` level. Angular Router creates an environment route injector for each
|
|
1934
|
-
* matched route where navigation occurs. The injector is created once, ensuring that
|
|
1935
|
-
* the feature states initialization only happens once as well.
|
|
1936
|
-
*/
|
|
1937
|
-
const NGXS_FEATURE_ENVIRONMENT_INITIALIZER = [
|
|
1938
|
-
{ provide: NGXS_FEATURE_STORE_INITIALIZER, useFactory: featureStatesInitializer },
|
|
1939
|
-
{
|
|
1940
|
-
provide: ENVIRONMENT_INITIALIZER,
|
|
1941
|
-
multi: true,
|
|
1942
|
-
useFactory() {
|
|
1943
|
-
return () => inject(NGXS_FEATURE_STORE_INITIALIZER);
|
|
1944
|
-
}
|
|
1945
|
-
}
|
|
1946
|
-
];
|
|
1947
|
-
|
|
1948
|
-
/**
|
|
1949
|
-
* @ignore
|
|
1950
|
-
*/
|
|
1951
|
-
class NgxsRootModule {
|
|
1952
|
-
constructor() {
|
|
1953
|
-
rootStoreInitializer();
|
|
1954
|
-
}
|
|
1955
|
-
}
|
|
1956
|
-
/** @nocollapse */ NgxsRootModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1957
|
-
/** @nocollapse */ NgxsRootModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule });
|
|
1958
|
-
/** @nocollapse */ NgxsRootModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule });
|
|
1959
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsRootModule, decorators: [{
|
|
1960
|
-
type: NgModule
|
|
1961
|
-
}], ctorParameters: function () { return []; } });
|
|
1962
|
-
|
|
1963
|
-
/**
|
|
1964
|
-
* @ignore
|
|
1965
|
-
*/
|
|
1966
|
-
class NgxsFeatureModule {
|
|
1967
|
-
constructor() {
|
|
1968
|
-
featureStatesInitializer();
|
|
1969
|
-
}
|
|
1970
|
-
}
|
|
1971
|
-
/** @nocollapse */ NgxsFeatureModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
1972
|
-
/** @nocollapse */ NgxsFeatureModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule });
|
|
1973
|
-
/** @nocollapse */ NgxsFeatureModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule });
|
|
1974
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsFeatureModule, decorators: [{
|
|
1975
|
-
type: NgModule
|
|
1976
|
-
}], ctorParameters: function () { return []; } });
|
|
1977
|
-
|
|
1978
|
-
/**
|
|
1979
|
-
* This function provides the required providers when invoking `NgxsModule.forRoot`
|
|
1980
|
-
* or `provideStore`. It is shared between the NgModule and standalone APIs.
|
|
1981
|
-
*/
|
|
1982
|
-
function getRootProviders(states, options) {
|
|
1983
|
-
return [
|
|
1984
|
-
StateFactory,
|
|
1985
|
-
PluginManager,
|
|
1986
|
-
...states,
|
|
1987
|
-
{
|
|
1988
|
-
provide: ROOT_STATE_TOKEN,
|
|
1989
|
-
useValue: states
|
|
1990
|
-
},
|
|
1991
|
-
{
|
|
1992
|
-
provide: APP_BOOTSTRAP_LISTENER,
|
|
1993
|
-
useFactory: () => {
|
|
1994
|
-
const bootstrapper = inject(NgxsBootstrapper);
|
|
1995
|
-
return () => bootstrapper.bootstrap();
|
|
1996
|
-
},
|
|
1997
|
-
multi: true
|
|
1998
|
-
},
|
|
1999
|
-
{
|
|
2000
|
-
provide: NGXS_OPTIONS,
|
|
2001
|
-
useValue: options
|
|
2002
|
-
},
|
|
2003
|
-
{
|
|
2004
|
-
provide: CUSTOM_NGXS_EXECUTION_STRATEGY,
|
|
2005
|
-
useValue: options.executionStrategy
|
|
2006
|
-
},
|
|
2007
|
-
{
|
|
2008
|
-
provide: ɵNGXS_STATE_CONTEXT_FACTORY,
|
|
2009
|
-
useExisting: StateContextFactory
|
|
2010
|
-
},
|
|
2011
|
-
{
|
|
2012
|
-
provide: ɵNGXS_STATE_FACTORY,
|
|
2013
|
-
useExisting: StateFactory
|
|
2014
|
-
}
|
|
2015
|
-
];
|
|
2016
|
-
}
|
|
2017
|
-
|
|
2018
|
-
/**
|
|
2019
|
-
* This function provides the required providers when calling `NgxsModule.forFeature`
|
|
2020
|
-
* or `provideStates`. It is shared between the NgModule and standalone APIs.
|
|
2021
|
-
*/
|
|
2022
|
-
function getFeatureProviders(states) {
|
|
2023
|
-
return [
|
|
2024
|
-
StateFactory,
|
|
2025
|
-
PluginManager,
|
|
2026
|
-
...states,
|
|
2027
|
-
{
|
|
2028
|
-
provide: FEATURE_STATE_TOKEN,
|
|
2029
|
-
multi: true,
|
|
2030
|
-
useValue: states
|
|
2031
|
-
}
|
|
2032
|
-
];
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
class NgxsModule {
|
|
2036
|
-
static forRoot(states = [], options = {}) {
|
|
2037
|
-
return {
|
|
2038
|
-
ngModule: NgxsRootModule,
|
|
2039
|
-
providers: getRootProviders(states, options)
|
|
2040
|
-
};
|
|
2041
|
-
}
|
|
2042
|
-
static forFeature(states = []) {
|
|
2043
|
-
return {
|
|
2044
|
-
ngModule: NgxsFeatureModule,
|
|
2045
|
-
providers: getFeatureProviders(states)
|
|
2046
|
-
};
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
/** @nocollapse */ NgxsModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
2050
|
-
/** @nocollapse */ NgxsModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule });
|
|
2051
|
-
/** @nocollapse */ NgxsModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule });
|
|
2052
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsModule, decorators: [{
|
|
2053
|
-
type: NgModule
|
|
2054
|
-
}] });
|
|
2055
|
-
|
|
2056
|
-
/**
|
|
2057
|
-
* Decorates a method with a action information.
|
|
2058
|
-
*/
|
|
2059
|
-
function Action(actions, options) {
|
|
2060
|
-
return (target, name) => {
|
|
2061
|
-
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
2062
|
-
// creating a breaking change for projects that still use the View Engine.
|
|
2063
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2064
|
-
const isStaticMethod = target.hasOwnProperty('prototype');
|
|
2065
|
-
if (isStaticMethod) {
|
|
2066
|
-
throwActionDecoratorError();
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
const meta = ensureStoreMetadata$1(target.constructor);
|
|
2070
|
-
if (!Array.isArray(actions)) {
|
|
2071
|
-
actions = [actions];
|
|
2072
|
-
}
|
|
2073
|
-
for (const action of actions) {
|
|
2074
|
-
const type = action.type;
|
|
2075
|
-
if (!meta.actions[type]) {
|
|
2076
|
-
meta.actions[type] = [];
|
|
2077
|
-
}
|
|
2078
|
-
meta.actions[type].push({
|
|
2079
|
-
fn: name,
|
|
2080
|
-
options: options || {},
|
|
2081
|
-
type
|
|
2082
|
-
});
|
|
2083
|
-
}
|
|
2084
|
-
};
|
|
2085
|
-
}
|
|
2086
|
-
|
|
2087
|
-
/**
|
|
2088
|
-
* Decorates a class with ngxs state information.
|
|
2089
|
-
*/
|
|
2090
|
-
function State(options) {
|
|
2091
|
-
return (target) => {
|
|
2092
|
-
const stateClass = target;
|
|
2093
|
-
const meta = ensureStoreMetadata$1(stateClass);
|
|
2094
|
-
const inheritedStateClass = Object.getPrototypeOf(stateClass);
|
|
2095
|
-
const optionsWithInheritance = getStateOptions(inheritedStateClass, options);
|
|
2096
|
-
mutateMetaData({ meta, inheritedStateClass, optionsWithInheritance });
|
|
2097
|
-
stateClass[ɵMETA_OPTIONS_KEY] = optionsWithInheritance;
|
|
2098
|
-
};
|
|
2099
|
-
}
|
|
2100
|
-
function getStateOptions(inheritedStateClass, options) {
|
|
2101
|
-
const inheritanceOptions = inheritedStateClass[ɵMETA_OPTIONS_KEY] || {};
|
|
2102
|
-
return Object.assign(Object.assign({}, inheritanceOptions), options);
|
|
2103
|
-
}
|
|
2104
|
-
function mutateMetaData(params) {
|
|
2105
|
-
const { meta, inheritedStateClass, optionsWithInheritance } = params;
|
|
2106
|
-
const { children, defaults, name } = optionsWithInheritance;
|
|
2107
|
-
const stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
|
|
2108
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2109
|
-
ensureStateNameIsValid(stateName);
|
|
2110
|
-
}
|
|
2111
|
-
if (inheritedStateClass.hasOwnProperty(ɵMETA_KEY)) {
|
|
2112
|
-
const inheritedMeta = inheritedStateClass[ɵMETA_KEY] || {};
|
|
2113
|
-
meta.actions = Object.assign(Object.assign({}, meta.actions), inheritedMeta.actions);
|
|
2114
|
-
}
|
|
2115
|
-
meta.children = children;
|
|
2116
|
-
meta.defaults = defaults;
|
|
2117
|
-
meta.name = stateName;
|
|
2118
|
-
}
|
|
2119
|
-
|
|
2120
|
-
const DOLLAR_CHAR_CODE = 36;
|
|
2121
|
-
function createSelectObservable(selector) {
|
|
2122
|
-
if (!SelectFactory.store) {
|
|
2123
|
-
throwSelectFactoryNotConnectedError();
|
|
2124
|
-
}
|
|
2125
|
-
return SelectFactory.store.select(selector);
|
|
2126
|
-
}
|
|
2127
|
-
function createSelectorFn(name, rawSelector, paths = []) {
|
|
2128
|
-
rawSelector = !rawSelector ? removeDollarAtTheEnd(name) : rawSelector;
|
|
2129
|
-
if (typeof rawSelector === 'string') {
|
|
2130
|
-
const propsArray = paths.length
|
|
2131
|
-
? [rawSelector, ...paths]
|
|
2132
|
-
: rawSelector.split('.');
|
|
2133
|
-
return propGetter(propsArray, SelectFactory.config);
|
|
2134
|
-
}
|
|
2135
|
-
return rawSelector;
|
|
2136
|
-
}
|
|
2137
|
-
/**
|
|
2138
|
-
* @example If `foo$` => make it just `foo`
|
|
2139
|
-
*/
|
|
2140
|
-
function removeDollarAtTheEnd(name) {
|
|
2141
|
-
const lastCharIndex = name.length - 1;
|
|
2142
|
-
const dollarAtTheEnd = name.charCodeAt(lastCharIndex) === DOLLAR_CHAR_CODE;
|
|
2143
|
-
return dollarAtTheEnd ? name.slice(0, lastCharIndex) : name;
|
|
2144
|
-
}
|
|
2145
|
-
|
|
2146
|
-
/**
|
|
2147
|
-
* Decorator for selecting a slice of state from the store.
|
|
2148
|
-
*/
|
|
2149
|
-
function Select(rawSelector, ...paths) {
|
|
2150
|
-
return function (target, key) {
|
|
2151
|
-
const name = key.toString();
|
|
2152
|
-
const selectorId = `__${name}__selector`;
|
|
2153
|
-
const selector = createSelectorFn(name, rawSelector, paths);
|
|
2154
|
-
Object.defineProperties(target, {
|
|
2155
|
-
[selectorId]: {
|
|
2156
|
-
writable: true,
|
|
2157
|
-
enumerable: false,
|
|
2158
|
-
configurable: true
|
|
2159
|
-
},
|
|
2160
|
-
[name]: {
|
|
2161
|
-
enumerable: true,
|
|
2162
|
-
configurable: true,
|
|
2163
|
-
get() {
|
|
2164
|
-
return this[selectorId] || (this[selectorId] = createSelectObservable(selector));
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
});
|
|
2168
|
-
};
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
const SELECTOR_OPTIONS_META_KEY = 'NGXS_SELECTOR_OPTIONS_META';
|
|
2172
|
-
const selectorOptionsMetaAccessor = {
|
|
2173
|
-
getOptions: (target) => {
|
|
2174
|
-
return (target && target[SELECTOR_OPTIONS_META_KEY]) || {};
|
|
2175
|
-
},
|
|
2176
|
-
defineOptions: (target, options) => {
|
|
2177
|
-
if (!target)
|
|
2178
|
-
return;
|
|
2179
|
-
target[SELECTOR_OPTIONS_META_KEY] = options;
|
|
2180
|
-
},
|
|
2181
|
-
};
|
|
2182
|
-
function setupSelectorMetadata(originalFn, creationMetadata) {
|
|
2183
|
-
const selectorMetaData = ensureSelectorMetadata$1(originalFn);
|
|
2184
|
-
selectorMetaData.originalFn = originalFn;
|
|
2185
|
-
let getExplicitSelectorOptions = () => ({});
|
|
2186
|
-
if (creationMetadata) {
|
|
2187
|
-
selectorMetaData.containerClass = creationMetadata.containerClass;
|
|
2188
|
-
selectorMetaData.selectorName = creationMetadata.selectorName || null;
|
|
2189
|
-
getExplicitSelectorOptions =
|
|
2190
|
-
creationMetadata.getSelectorOptions || getExplicitSelectorOptions;
|
|
2191
|
-
}
|
|
2192
|
-
const selectorMetaDataClone = Object.assign({}, selectorMetaData);
|
|
2193
|
-
selectorMetaData.getSelectorOptions = () => getLocalSelectorOptions(selectorMetaDataClone, getExplicitSelectorOptions());
|
|
2194
|
-
return selectorMetaData;
|
|
2195
|
-
}
|
|
2196
|
-
function getLocalSelectorOptions(selectorMetaData, explicitOptions) {
|
|
2197
|
-
return Object.assign(Object.assign(Object.assign(Object.assign({}, (selectorOptionsMetaAccessor.getOptions(selectorMetaData.containerClass) || {})), (selectorOptionsMetaAccessor.getOptions(selectorMetaData.originalFn) || {})), (selectorMetaData.getSelectorOptions() || {})), explicitOptions);
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
/**
|
|
2201
|
-
* Decorator for setting selector options at a method or class level.
|
|
2202
|
-
*/
|
|
2203
|
-
function SelectorOptions(options) {
|
|
2204
|
-
return (function decorate(target, methodName, descriptor) {
|
|
2205
|
-
if (methodName) {
|
|
2206
|
-
descriptor || (descriptor = Object.getOwnPropertyDescriptor(target, methodName));
|
|
2207
|
-
// Method Decorator
|
|
2208
|
-
const originalFn = descriptor.value || descriptor.originalFn;
|
|
2209
|
-
if (originalFn) {
|
|
2210
|
-
selectorOptionsMetaAccessor.defineOptions(originalFn, options);
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
else {
|
|
2214
|
-
// Class Decorator
|
|
2215
|
-
selectorOptionsMetaAccessor.defineOptions(target, options);
|
|
2216
|
-
}
|
|
2217
|
-
});
|
|
2218
|
-
}
|
|
2219
|
-
|
|
2220
|
-
function ensureStoreMetadata(target) {
|
|
2221
|
-
return ensureStoreMetadata$1(target);
|
|
2222
|
-
}
|
|
2223
|
-
function getStoreMetadata(target) {
|
|
2224
|
-
return getStoreMetadata$1(target);
|
|
2225
|
-
}
|
|
2226
|
-
function ensureSelectorMetadata(target) {
|
|
2227
|
-
return ensureSelectorMetadata$1(target);
|
|
2228
|
-
}
|
|
2229
|
-
function getSelectorMetadata(target) {
|
|
2230
|
-
return getSelectorMetadata$1(target);
|
|
2231
|
-
}
|
|
2232
|
-
|
|
2233
|
-
function createSelector(selectors, projector, creationMetadata) {
|
|
2234
|
-
const memoizedFn = createMemoizedSelectorFn(projector, creationMetadata);
|
|
2235
|
-
const selectorMetaData = setupSelectorMetadata(projector, creationMetadata);
|
|
2236
|
-
selectorMetaData.makeRootSelector = createRootSelectorFactory(selectorMetaData, selectors, memoizedFn);
|
|
2237
|
-
return memoizedFn;
|
|
2238
|
-
}
|
|
2239
|
-
|
|
2240
|
-
function Selector(selectors) {
|
|
2241
|
-
return (target, key, descriptor) => {
|
|
2242
|
-
descriptor || (descriptor = Object.getOwnPropertyDescriptor(target, key));
|
|
2243
|
-
const originalFn = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value;
|
|
2244
|
-
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
2245
|
-
// creating a breaking change for projects that still use the View Engine.
|
|
2246
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2247
|
-
if (originalFn && typeof originalFn !== 'function') {
|
|
2248
|
-
throwSelectorDecoratorError();
|
|
2249
|
-
}
|
|
2250
|
-
}
|
|
2251
|
-
const memoizedFn = createSelector(selectors, originalFn, {
|
|
2252
|
-
containerClass: target,
|
|
2253
|
-
selectorName: key.toString(),
|
|
2254
|
-
getSelectorOptions() {
|
|
2255
|
-
return {};
|
|
2256
|
-
},
|
|
2257
|
-
});
|
|
2258
|
-
const newDescriptor = {
|
|
2259
|
-
configurable: true,
|
|
2260
|
-
get() {
|
|
2261
|
-
return memoizedFn;
|
|
2262
|
-
},
|
|
2263
|
-
};
|
|
2264
|
-
// Add hidden property to descriptor
|
|
2265
|
-
newDescriptor['originalFn'] = originalFn;
|
|
2266
|
-
return newDescriptor;
|
|
2267
|
-
};
|
|
2268
|
-
}
|
|
2269
|
-
|
|
2270
|
-
class StateToken {
|
|
2271
|
-
constructor(name) {
|
|
2272
|
-
this.name = name;
|
|
2273
|
-
const selectorMetadata = ensureSelectorMetadata$1(this);
|
|
2274
|
-
selectorMetadata.makeRootSelector = (runtimeContext) => {
|
|
2275
|
-
return runtimeContext.getStateGetter(this.name);
|
|
2276
|
-
};
|
|
2277
|
-
}
|
|
2278
|
-
getName() {
|
|
2279
|
-
return this.name;
|
|
2280
|
-
}
|
|
2281
|
-
toString() {
|
|
2282
|
-
return `StateToken[${this.name}]`;
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
|
|
2286
|
-
class NgxsDevelopmentModule {
|
|
2287
|
-
static forRoot(options) {
|
|
2288
|
-
return {
|
|
2289
|
-
ngModule: NgxsDevelopmentModule,
|
|
2290
|
-
providers: [
|
|
2291
|
-
NgxsUnhandledActionsLogger,
|
|
2292
|
-
{ provide: NGXS_DEVELOPMENT_OPTIONS, useValue: options }
|
|
2293
|
-
]
|
|
2294
|
-
};
|
|
2295
|
-
}
|
|
2296
|
-
}
|
|
2297
|
-
/** @nocollapse */ NgxsDevelopmentModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
2298
|
-
/** @nocollapse */ NgxsDevelopmentModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule });
|
|
2299
|
-
/** @nocollapse */ NgxsDevelopmentModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule });
|
|
2300
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.4", ngImport: i0, type: NgxsDevelopmentModule, decorators: [{
|
|
2301
|
-
type: NgModule
|
|
2302
|
-
}] });
|
|
2303
|
-
|
|
2304
|
-
function ensureValidSelector(selector, context = {}) {
|
|
2305
|
-
const noun = context.noun || 'selector';
|
|
2306
|
-
const prefix = context.prefix ? context.prefix + ': ' : '';
|
|
2307
|
-
ensureValueProvided(selector, { noun, prefix: context.prefix });
|
|
2308
|
-
const metadata = getSelectorMetadata$1(selector) || getStoreMetadata$1(selector);
|
|
2309
|
-
if (!metadata) {
|
|
2310
|
-
throw new Error(`${prefix}The value provided as the ${noun} is not a valid selector.`);
|
|
2311
|
-
}
|
|
2312
|
-
}
|
|
2313
|
-
function ensureValueProvided(value, context = {}) {
|
|
2314
|
-
const noun = context.noun || 'value';
|
|
2315
|
-
const prefix = context.prefix ? context.prefix + ': ' : '';
|
|
2316
|
-
if (!value) {
|
|
2317
|
-
throw new Error(`${prefix}A ${noun} must be provided.`);
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
|
|
2321
|
-
function createModelSelector(selectorMap) {
|
|
2322
|
-
const selectorKeys = Object.keys(selectorMap);
|
|
2323
|
-
const selectors = Object.values(selectorMap);
|
|
2324
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2325
|
-
ensureValidSelectorMap({
|
|
2326
|
-
prefix: '[createModelSelector]',
|
|
2327
|
-
selectorMap,
|
|
2328
|
-
selectorKeys,
|
|
2329
|
-
selectors
|
|
2330
|
-
});
|
|
2331
|
-
}
|
|
2332
|
-
return createSelector(selectors, (...args) => {
|
|
2333
|
-
return selectorKeys.reduce((obj, key, index) => {
|
|
2334
|
-
obj[key] = args[index];
|
|
2335
|
-
return obj;
|
|
2336
|
-
}, {});
|
|
2337
|
-
});
|
|
2338
|
-
}
|
|
2339
|
-
function ensureValidSelectorMap({ prefix, selectorMap, selectorKeys, selectors }) {
|
|
2340
|
-
ensureValueProvided(selectorMap, { prefix, noun: 'selector map' });
|
|
2341
|
-
ensureValueProvided(typeof selectorMap === 'object', { prefix, noun: 'valid selector map' });
|
|
2342
|
-
ensureValueProvided(selectorKeys.length, { prefix, noun: 'non-empty selector map' });
|
|
2343
|
-
selectors.forEach((selector, index) => ensureValidSelector(selector, {
|
|
2344
|
-
prefix,
|
|
2345
|
-
noun: `selector for the '${selectorKeys[index]}' property`
|
|
2346
|
-
}));
|
|
2347
|
-
}
|
|
2348
|
-
|
|
2349
|
-
function createPickSelector(selector, keys) {
|
|
2350
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2351
|
-
ensureValidSelector(selector, { prefix: '[createPickSelector]' });
|
|
2352
|
-
}
|
|
2353
|
-
const validKeys = keys.filter(Boolean);
|
|
2354
|
-
const selectors = validKeys.map(key => createSelector([selector], (s) => s[key]));
|
|
2355
|
-
return createSelector([...selectors], (...props) => {
|
|
2356
|
-
return validKeys.reduce((acc, key, index) => {
|
|
2357
|
-
acc[key] = props[index];
|
|
2358
|
-
return acc;
|
|
2359
|
-
}, {});
|
|
2360
|
-
});
|
|
2361
|
-
}
|
|
2362
|
-
|
|
2363
|
-
function createPropertySelectors(parentSelector) {
|
|
2364
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2365
|
-
ensureValidSelector(parentSelector, {
|
|
2366
|
-
prefix: '[createPropertySelectors]',
|
|
2367
|
-
noun: 'parent selector'
|
|
2368
|
-
});
|
|
2369
|
-
}
|
|
2370
|
-
const cache = {};
|
|
2371
|
-
return new Proxy({}, {
|
|
2372
|
-
get(_target, prop) {
|
|
2373
|
-
const selector = cache[prop] ||
|
|
2374
|
-
createSelector([parentSelector], (s) => s === null || s === void 0 ? void 0 : s[prop]);
|
|
2375
|
-
cache[prop] = selector;
|
|
2376
|
-
return selector;
|
|
2377
|
-
}
|
|
2378
|
-
});
|
|
2379
|
-
}
|
|
2380
|
-
|
|
2381
|
-
function provideStore(states = [], ...optionsAndFeatures) {
|
|
2382
|
-
const features = [];
|
|
2383
|
-
// Options are empty by default (see `forRoot`).
|
|
2384
|
-
let options = {};
|
|
2385
|
-
if (optionsAndFeatures.length > 0) {
|
|
2386
|
-
if (isEnvironmentProvider(optionsAndFeatures[0])) {
|
|
2387
|
-
features.push(...optionsAndFeatures);
|
|
2388
|
-
}
|
|
2389
|
-
else {
|
|
2390
|
-
options = optionsAndFeatures[0];
|
|
2391
|
-
features.push(...optionsAndFeatures.slice(1));
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
return makeEnvironmentProviders([
|
|
2395
|
-
...getRootProviders(states, options),
|
|
2396
|
-
features,
|
|
2397
|
-
NGXS_ROOT_ENVIRONMENT_INITIALIZER
|
|
2398
|
-
]);
|
|
2399
|
-
}
|
|
2400
|
-
function isEnvironmentProvider(target) {
|
|
2401
|
-
return !!target.ɵproviders;
|
|
2402
|
-
}
|
|
2403
|
-
|
|
2404
|
-
/**
|
|
2405
|
-
* This version serves as a standalone alternative to `NgxsModule.forFeature`.
|
|
2406
|
-
* It can be used in a similar manner to register feature states, but at the
|
|
2407
|
-
* `Route` providers level:
|
|
2408
|
-
*
|
|
2409
|
-
* ```ts
|
|
2410
|
-
* const routes: Routes = [
|
|
2411
|
-
* {
|
|
2412
|
-
* path: 'products',
|
|
2413
|
-
* loadComponent: async () => {...},
|
|
2414
|
-
* providers: [provideStates([ProductsState])]
|
|
2415
|
-
* }
|
|
2416
|
-
* ];
|
|
2417
|
-
* ```
|
|
2418
|
-
*/
|
|
2419
|
-
function provideStates(states, ...features) {
|
|
2420
|
-
return makeEnvironmentProviders([
|
|
2421
|
-
...getFeatureProviders(states),
|
|
2422
|
-
features,
|
|
2423
|
-
NGXS_FEATURE_ENVIRONMENT_INITIALIZER
|
|
2424
|
-
]);
|
|
2425
|
-
}
|
|
2426
|
-
|
|
2427
|
-
/**
|
|
2428
|
-
* This function registers a custom global plugin for the state.
|
|
2429
|
-
*
|
|
2430
|
-
* ```ts
|
|
2431
|
-
* bootstrapApplication(AppComponent, {
|
|
2432
|
-
* providers: [
|
|
2433
|
-
* provideStore(
|
|
2434
|
-
* [CountriesState],
|
|
2435
|
-
* withNgxsPlugin(logoutPlugin)
|
|
2436
|
-
* )
|
|
2437
|
-
* ]
|
|
2438
|
-
* });
|
|
2439
|
-
* ```
|
|
2440
|
-
*/
|
|
2441
|
-
function withNgxsPlugin(plugin) {
|
|
2442
|
-
return makeEnvironmentProviders([{ provide: NGXS_PLUGINS, useClass: plugin, multi: true }]);
|
|
2443
|
-
}
|
|
2444
|
-
|
|
2445
|
-
/**
|
|
2446
|
-
* The public api for consumers of @ngxs/store
|
|
2447
|
-
*/
|
|
2448
|
-
|
|
2449
|
-
/**
|
|
2450
|
-
* Generated bundle index. Do not edit.
|
|
2451
|
-
*/
|
|
2452
|
-
|
|
2453
|
-
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 };
|
|
2454
|
-
//# sourceMappingURL=ngxs-store.mjs.map
|