@ngxs/store 21.0.0-dev.master-f3cf7bf → 21.0.0-dev.master-77ed591
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.
|
@@ -159,7 +159,10 @@ class ɵNgxsAppBootstrappedState extends BehaviorSubject {
|
|
|
159
159
|
// Complete the subject once the root injector is destroyed to ensure
|
|
160
160
|
// there are no active subscribers that would receive events or perform
|
|
161
161
|
// any actions after the application is destroyed.
|
|
162
|
-
destroyRef.onDestroy(() =>
|
|
162
|
+
destroyRef.onDestroy(() => {
|
|
163
|
+
this.complete();
|
|
164
|
+
this.unsubscribe();
|
|
165
|
+
});
|
|
163
166
|
}
|
|
164
167
|
bootstrap() {
|
|
165
168
|
this.next(true);
|
|
@@ -302,7 +305,10 @@ class ɵStateStream extends ɵOrderedBehaviorSubject {
|
|
|
302
305
|
// for preventing memory leaks in server-side rendered apps, where a new `StateStream`
|
|
303
306
|
// is created for each HTTP request. If users forget to unsubscribe from `store.select`
|
|
304
307
|
// or `store.subscribe`, it can result in significant memory leaks in SSR apps.
|
|
305
|
-
inject(DestroyRef).onDestroy(() =>
|
|
308
|
+
inject(DestroyRef).onDestroy(() => {
|
|
309
|
+
this.complete();
|
|
310
|
+
this.unsubscribe();
|
|
311
|
+
});
|
|
306
312
|
}
|
|
307
313
|
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ɵStateStream, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
308
314
|
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: ɵStateStream, providedIn: 'root' });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngxs-store-internals.mjs","sources":["../../../packages/store/internals/src/symbols.ts","../../../packages/store/internals/src/object-utils.ts","../../../packages/store/internals/src/metadata.ts","../../../packages/store/internals/src/memoize.ts","../../../packages/store/internals/src/state-token.ts","../../../packages/store/internals/src/initial-state.ts","../../../packages/store/internals/src/ngxs-app-bootstrapped-state.ts","../../../packages/store/internals/src/internal-tokens.ts","../../../packages/store/internals/src/custom-rxjs-subjects.ts","../../../packages/store/internals/src/custom-rxjs-operators.ts","../../../packages/store/internals/src/state-stream.ts","../../../packages/store/internals/src/action-registry.ts","../../../packages/store/internals/src/ngxs-store-internals.ts"],"sourcesContent":["import type { StateToken } from './state-token';\n\nexport interface ɵPlainObject {\n [key: string]: any;\n}\n\nexport interface ɵPlainObjectOf<T> {\n [key: string]: T;\n}\n\nexport type ɵStateClass<T = any> = new (...args: any[]) => T;\n\n// This key is used to store metadata on state classes,\n// such as actions and other related information.\nexport const ɵMETA_KEY = 'NGXS_META';\n// This key is used to store options on state classes\n// provided through the `@State` decorator.\nexport const ɵMETA_OPTIONS_KEY = 'NGXS_OPTIONS_META';\n// This key is used to store selector metadata on selector functions,\n// such as decorated with the `@Selector` or provided through the\n// `createSelector` function.\nexport const ɵSELECTOR_META_KEY = 'NGXS_SELECTOR_META';\n\nexport interface ɵStateToken<T, U> {\n new (name: ɵTokenName<T>): U;\n getName(): string;\n toString(): string;\n}\n\ntype RequireGeneric<T, U> = T extends void ? 'You must provide a type parameter' : U;\n\nexport type ɵTokenName<T> = string & RequireGeneric<T, string>;\n\nexport type ɵExtractTokenType<P> = P extends StateToken<infer T> ? T : never;\n\n/**\n * Options that can be provided to the store.\n */\nexport interface ɵStoreOptions<T> {\n /**\n * Name of the state. Required.\n */\n name: string | StateToken<T>;\n\n /**\n * Default values for the state. If not provided, uses empty object.\n */\n defaults?: T;\n\n /**\n * Sub states for the given state.\n *\n * @deprecated\n * Read the deprecation notice at this link: https://ngxs.io/deprecations/sub-states-deprecation.\n */\n children?: ɵStateClass[];\n}\n\n// inspired from https://stackoverflow.com/a/43674389\nexport interface ɵStateClassInternal<T = any, U = any> extends ɵStateClass<T> {\n [ɵMETA_KEY]?: ɵMetaDataModel;\n [ɵMETA_OPTIONS_KEY]?: ɵStoreOptions<U>;\n}\n\nexport interface ɵMetaDataModel {\n name: string | null;\n actions: ɵPlainObjectOf<ɵActionHandlerMetaData[]>;\n defaults: any;\n path: string | null;\n makeRootSelector: ɵSelectorFactory | null;\n /** @deprecated */\n children?: ɵStateClassInternal[];\n}\n\nexport interface ɵSelectorMetaDataModel {\n makeRootSelector: ɵSelectorFactory | null;\n originalFn: Function | null;\n containerClass: any;\n selectorName: string | null;\n getSelectorOptions: () => ɵSharedSelectorOptions;\n}\n\nexport interface ɵSharedSelectorOptions {\n /**\n * @deprecated\n * Read the deprecation notice at this link: https://ngxs.io/deprecations/inject-container-state-deprecation.md.\n */\n injectContainerState?: boolean;\n suppressErrors?: boolean;\n}\n\nexport interface ɵRuntimeSelectorContext {\n getStateGetter(key: any): (state: any) => any;\n getSelectorOptions(localOptions?: ɵSharedSelectorOptions): ɵSharedSelectorOptions;\n}\n\nexport type ɵSelectFromRootState = (rootState: any) => any;\nexport type ɵSelectorFactory = (\n runtimeContext: ɵRuntimeSelectorContext\n) => ɵSelectFromRootState;\n\n/**\n * Actions that can be provided in a action decorator.\n */\nexport interface ɵActionOptions {\n /**\n * Cancel the previous uncompleted observable(s).\n */\n cancelUncompleted?: boolean;\n}\n\nexport interface ɵActionHandlerMetaData {\n fn: string | symbol;\n options: ɵActionOptions;\n type: string;\n}\n","// Property reads are not minified.\n// It's smaller to read it once and use a function.\nconst _hasOwnProperty = Object.prototype.hasOwnProperty;\nexport const ɵhasOwnProperty = (target: any, key: PropertyKey) =>\n _hasOwnProperty.call(target, key);\n\nexport const ɵdefineProperty = Object.defineProperty;\n","import { ɵdefineProperty, ɵhasOwnProperty } from './object-utils';\nimport {\n ɵMETA_KEY,\n ɵSELECTOR_META_KEY,\n ɵMetaDataModel,\n ɵStateClassInternal,\n ɵSelectorMetaDataModel,\n ɵRuntimeSelectorContext\n} from './symbols';\n\n/**\n * Ensures metadata is attached to the class and returns it.\n *\n * @ignore\n */\nexport function ɵensureStoreMetadata(target: ɵStateClassInternal): ɵMetaDataModel {\n if (!ɵhasOwnProperty(target, ɵMETA_KEY)) {\n const defaultMetadata: ɵMetaDataModel = {\n name: null,\n actions: {},\n defaults: {},\n path: null,\n makeRootSelector(context: ɵRuntimeSelectorContext) {\n return context.getStateGetter(defaultMetadata.name);\n },\n children: []\n };\n\n ɵdefineProperty(target, ɵMETA_KEY, { value: defaultMetadata });\n }\n return ɵgetStoreMetadata(target);\n}\n\n/**\n * Get the metadata attached to the state class if it exists.\n *\n * @ignore\n */\nexport function ɵgetStoreMetadata(target: ɵStateClassInternal): ɵMetaDataModel {\n return target[ɵMETA_KEY]!;\n}\n\n/**\n * Ensures metadata is attached to the selector and returns it.\n *\n * @ignore\n */\nexport function ɵensureSelectorMetadata(target: Function): ɵSelectorMetaDataModel {\n if (!ɵhasOwnProperty(target, ɵSELECTOR_META_KEY)) {\n const defaultMetadata: ɵSelectorMetaDataModel = {\n makeRootSelector: null,\n originalFn: null,\n containerClass: null,\n selectorName: null,\n getSelectorOptions: () => ({})\n };\n\n ɵdefineProperty(target, ɵSELECTOR_META_KEY, { value: defaultMetadata });\n }\n\n return ɵgetSelectorMetadata(target);\n}\n\n/**\n * Get the metadata attached to the selector if it exists.\n *\n * @ignore\n */\nexport function ɵgetSelectorMetadata(target: any): ɵSelectorMetaDataModel {\n return target[ɵSELECTOR_META_KEY];\n}\n","function areArgumentsShallowlyEqual(\n equalityCheck: (a: any, b: any) => boolean,\n prev: IArguments | null,\n next: IArguments | null\n) {\n if (prev === null || next === null || prev.length !== next.length) {\n return false;\n }\n\n // Do this in a for loop (and not a `forEach` or an `every`) so we can\n // determine equality as fast as possible.\n const length = prev.length;\n for (let i = 0; i < length; i++) {\n if (!equalityCheck(prev[i], next[i])) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Memoize a function on its last inputs only.\n * Originally from: https://github.com/reduxjs/reselect/blob/master/src/index.js\n *\n * @ignore\n */\nexport function ɵmemoize<T extends (...args: any[]) => any>(\n func: T,\n equalityCheck = Object.is\n): T {\n let lastArgs: IArguments | null = null;\n let lastResult: any = null;\n // we reference arguments instead of spreading them for performance reasons\n function memoized() {\n // eslint-disable-next-line prefer-rest-params\n if (!areArgumentsShallowlyEqual(equalityCheck, lastArgs, arguments)) {\n // apply arguments instead of spreading for performance.\n // eslint-disable-next-line prefer-rest-params, prefer-spread\n lastResult = (<Function>func).apply(null, arguments);\n }\n // eslint-disable-next-line prefer-rest-params\n lastArgs = arguments;\n return lastResult;\n }\n (<any>memoized).reset = function () {\n // The hidden (for now) ability to reset the memoization\n lastArgs = null;\n lastResult = null;\n };\n return memoized as T;\n}\n","import { ɵensureSelectorMetadata } from './metadata';\nimport type { ɵTokenName, ɵSelectFromRootState, ɵRuntimeSelectorContext } from './symbols';\n\nexport class StateToken<T = void> {\n constructor(private readonly _name: ɵTokenName<T>) {\n const selectorMetadata = ɵensureSelectorMetadata(<any>this);\n selectorMetadata.makeRootSelector = (\n runtimeContext: ɵRuntimeSelectorContext\n ): ɵSelectFromRootState => {\n return runtimeContext.getStateGetter(this._name);\n };\n }\n\n getName(): string {\n return this._name;\n }\n\n toString(): string {\n return `StateToken[${this._name}]`;\n }\n}\n","import { InjectionToken } from '@angular/core';\n\nimport { ɵPlainObject } from './symbols';\n\ndeclare const ngDevMode: boolean;\n\nexport class ɵInitialState {\n private static _value: ɵPlainObject = {};\n\n static set(state: ɵPlainObject) {\n this._value = state;\n }\n\n static pop(): ɵPlainObject {\n const state = this._value;\n this._value = {};\n return state;\n }\n}\n\nexport const ɵINITIAL_STATE_TOKEN = new InjectionToken<ɵPlainObject>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'INITIAL_STATE_TOKEN' : '',\n {\n providedIn: 'root',\n factory: () => ɵInitialState.pop()\n }\n);\n","import { DestroyRef, inject, Injectable } from '@angular/core';\nimport { BehaviorSubject } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class ɵNgxsAppBootstrappedState extends BehaviorSubject<boolean> {\n constructor() {\n super(false);\n\n const destroyRef = inject(DestroyRef);\n // Complete the subject once the root injector is destroyed to ensure\n // there are no active subscribers that would receive events or perform\n // any actions after the application is destroyed.\n destroyRef.onDestroy(() => this.complete());\n }\n\n bootstrap(): void {\n this.next(true);\n }\n}\n","import { InjectionToken } from '@angular/core';\n\ndeclare const ngDevMode: boolean;\n\n// These tokens are internal and can change at any point.\n\nexport const ɵNGXS_STATE_FACTORY = /* @__PURE__ */ new InjectionToken<any>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'ɵNGXS_STATE_FACTORY' : ''\n);\n\nexport const ɵNGXS_STATE_CONTEXT_FACTORY = /* @__PURE__ */ new InjectionToken<any>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'ɵNGXS_STATE_CONTEXT_FACTORY' : ''\n);\n","import { BehaviorSubject, Subject } from 'rxjs';\n\n/**\n * This wraps the provided function, and will enforce the following:\n * - The calls will execute in the order that they are made\n * - A call will only be initiated when the previous call has completed\n * - If there is a call currently executing then the new call will be added\n * to the queue and the function will return immediately\n *\n * NOTE: The following assumptions about the operation must hold true:\n * - The operation is synchronous in nature\n * - If any asynchronous side effects of the call exist, it should not\n * have any bearing on the correctness of the next call in the queue\n * - The operation has a void return\n * - The caller should not assume that the call has completed upon\n * return of the function\n * - The caller can assume that all the queued calls will complete\n * within the current microtask\n * - The only way that a call will encounter another call in the queue\n * would be if the call at the front of the queue initiated this call\n * as part of its synchronous execution\n */\nfunction orderedQueueOperation<TArgs extends any[]>(operation: (...args: TArgs) => void) {\n const callsQueue: TArgs[] = [];\n let busyPushingNext = false;\n return function callOperation(...args: TArgs) {\n if (busyPushingNext) {\n callsQueue.unshift(args);\n return;\n }\n busyPushingNext = true;\n operation(...args);\n while (callsQueue.length > 0) {\n const nextCallArgs = callsQueue.pop();\n nextCallArgs && operation(...nextCallArgs);\n }\n busyPushingNext = false;\n };\n}\n\n/**\n * Custom Subject that ensures that subscribers are notified of values in the order that they arrived.\n * A standard Subject does not have this guarantee.\n * For example, given the following code:\n * ```typescript\n * const subject = new Subject<string>();\n subject.subscribe(value => {\n if (value === 'start') subject.next('end');\n });\n subject.subscribe(value => { });\n subject.next('start');\n * ```\n * When `subject` is a standard `Subject<T>` the second subscriber would recieve `end` and then `start`.\n * When `subject` is a `OrderedSubject<T>` the second subscriber would recieve `start` and then `end`.\n */\nexport class ɵOrderedSubject<T> extends Subject<T> {\n private _orderedNext = orderedQueueOperation((value?: T) => super.next(<T>value));\n\n override next(value?: T): void {\n this._orderedNext(value);\n }\n}\n\n/**\n * Custom BehaviorSubject that ensures that subscribers are notified of values in the order that they arrived.\n * A standard BehaviorSubject does not have this guarantee.\n * For example, given the following code:\n * ```typescript\n * const subject = new BehaviorSubject<string>();\n subject.subscribe(value => {\n if (value === 'start') subject.next('end');\n });\n subject.subscribe(value => { });\n subject.next('start');\n * ```\n * When `subject` is a standard `BehaviorSubject<T>` the second subscriber would recieve `end` and then `start`.\n * When `subject` is a `OrderedBehaviorSubject<T>` the second subscriber would recieve `start` and then `end`.\n */\nexport class ɵOrderedBehaviorSubject<T> extends BehaviorSubject<T> {\n private _orderedNext = orderedQueueOperation((value: T) => super.next(value));\n private _currentValue: T;\n\n constructor(value: T) {\n super(value);\n this._currentValue = value;\n }\n\n override getValue(): T {\n return this._currentValue;\n }\n\n override next(value: T): void {\n this._currentValue = value;\n this._orderedNext(value);\n }\n}\n","import { type MonoTypeOperatorFunction, Observable } from 'rxjs';\n\nexport function ɵwrapObserverCalls<TValue>(\n invokeFn: (fn: () => void) => void\n): MonoTypeOperatorFunction<TValue> {\n return (source: Observable<TValue>) => {\n return new Observable<TValue>(subscriber => {\n return source.subscribe({\n next(value) {\n invokeFn(() => subscriber.next(value));\n },\n error(error) {\n invokeFn(() => subscriber.error(error));\n },\n complete() {\n invokeFn(() => subscriber.complete());\n }\n });\n });\n };\n}\n","import { DestroyRef, inject, Injectable, Signal, untracked } from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { Observable } from 'rxjs';\n\nimport { ɵwrapObserverCalls } from './custom-rxjs-operators';\nimport { ɵOrderedBehaviorSubject } from './custom-rxjs-subjects';\nimport { ɵPlainObject } from './symbols';\n\n/**\n * BehaviorSubject of the entire state.\n * @ignore\n */\n@Injectable({ providedIn: 'root' })\nexport class ɵStateStream extends ɵOrderedBehaviorSubject<ɵPlainObject> {\n readonly state: Signal<ɵPlainObject> = toSignal(this.pipe(ɵwrapObserverCalls(untracked)), {\n manualCleanup: true,\n requireSync: true\n });\n\n constructor() {\n super({});\n\n // Complete the subject once the root injector is destroyed to ensure\n // there are no active subscribers that would receive events or perform\n // any actions after the application is destroyed.\n // The `StateStream` should never emit values once the root view is removed,\n // such as when the `ApplicationRef.destroy()` method is called. This is crucial\n // for preventing memory leaks in server-side rendered apps, where a new `StateStream`\n // is created for each HTTP request. If users forget to unsubscribe from `store.select`\n // or `store.subscribe`, it can result in significant memory leaks in SSR apps.\n inject(DestroyRef).onDestroy(() => this.complete());\n }\n}\n","import { DestroyRef, inject, Injectable } from '@angular/core';\nimport type { Observable } from 'rxjs';\n\nexport type ActionHandlerFn = (action: any) => Observable<unknown>;\n\n@Injectable({ providedIn: 'root' })\nexport class ɵNgxsActionRegistry {\n // Instead of going over the states list every time an action is dispatched,\n // we are constructing a map of action types to lists of action metadata.\n // If the `@@Init` action is handled in two different states, the action\n // metadata list will contain two objects that have the state `instance` and\n // method names to be used as action handlers (decorated with `@Action(InitState)`).\n private readonly _actionTypeToHandlersMap = new Map<string, Set<ActionHandlerFn>>();\n\n constructor() {\n inject(DestroyRef).onDestroy(() => this._actionTypeToHandlersMap.clear());\n }\n\n get(type: string) {\n return this._actionTypeToHandlersMap.get(type);\n }\n\n register(type: string, handler: ActionHandlerFn) {\n const handlers = this._actionTypeToHandlersMap.get(type) ?? new Set();\n handlers.add(handler);\n this._actionTypeToHandlersMap.set(type, handlers);\n\n return () => {\n const handlers = this._actionTypeToHandlersMap.get(type)!;\n handlers.delete(handler);\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AC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAE;AACrE,QAAA,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC;QACrB,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;AAEjD,QAAA,OAAO,MAAK;YACV,MAAM,QAAQ,GAAG,IAAI,CAAC,wBAAwB,CAAC,GAAG,CAAC,IAAI,CAAE;AACzD,YAAA,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;AAC1B,SAAC;;0HAxBQ,mBAAmB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAnB,uBAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,cADN,MAAM,EAAA,CAAA;;2FACnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACLlC;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ngxs-store-internals.mjs","sources":["../../../packages/store/internals/src/symbols.ts","../../../packages/store/internals/src/object-utils.ts","../../../packages/store/internals/src/metadata.ts","../../../packages/store/internals/src/memoize.ts","../../../packages/store/internals/src/state-token.ts","../../../packages/store/internals/src/initial-state.ts","../../../packages/store/internals/src/ngxs-app-bootstrapped-state.ts","../../../packages/store/internals/src/internal-tokens.ts","../../../packages/store/internals/src/custom-rxjs-subjects.ts","../../../packages/store/internals/src/custom-rxjs-operators.ts","../../../packages/store/internals/src/state-stream.ts","../../../packages/store/internals/src/action-registry.ts","../../../packages/store/internals/src/ngxs-store-internals.ts"],"sourcesContent":["import type { StateToken } from './state-token';\n\nexport interface ɵPlainObject {\n [key: string]: any;\n}\n\nexport interface ɵPlainObjectOf<T> {\n [key: string]: T;\n}\n\nexport type ɵStateClass<T = any> = new (...args: any[]) => T;\n\n// This key is used to store metadata on state classes,\n// such as actions and other related information.\nexport const ɵMETA_KEY = 'NGXS_META';\n// This key is used to store options on state classes\n// provided through the `@State` decorator.\nexport const ɵMETA_OPTIONS_KEY = 'NGXS_OPTIONS_META';\n// This key is used to store selector metadata on selector functions,\n// such as decorated with the `@Selector` or provided through the\n// `createSelector` function.\nexport const ɵSELECTOR_META_KEY = 'NGXS_SELECTOR_META';\n\nexport interface ɵStateToken<T, U> {\n new (name: ɵTokenName<T>): U;\n getName(): string;\n toString(): string;\n}\n\ntype RequireGeneric<T, U> = T extends void ? 'You must provide a type parameter' : U;\n\nexport type ɵTokenName<T> = string & RequireGeneric<T, string>;\n\nexport type ɵExtractTokenType<P> = P extends StateToken<infer T> ? T : never;\n\n/**\n * Options that can be provided to the store.\n */\nexport interface ɵStoreOptions<T> {\n /**\n * Name of the state. Required.\n */\n name: string | StateToken<T>;\n\n /**\n * Default values for the state. If not provided, uses empty object.\n */\n defaults?: T;\n\n /**\n * Sub states for the given state.\n *\n * @deprecated\n * Read the deprecation notice at this link: https://ngxs.io/deprecations/sub-states-deprecation.\n */\n children?: ɵStateClass[];\n}\n\n// inspired from https://stackoverflow.com/a/43674389\nexport interface ɵStateClassInternal<T = any, U = any> extends ɵStateClass<T> {\n [ɵMETA_KEY]?: ɵMetaDataModel;\n [ɵMETA_OPTIONS_KEY]?: ɵStoreOptions<U>;\n}\n\nexport interface ɵMetaDataModel {\n name: string | null;\n actions: ɵPlainObjectOf<ɵActionHandlerMetaData[]>;\n defaults: any;\n path: string | null;\n makeRootSelector: ɵSelectorFactory | null;\n /** @deprecated */\n children?: ɵStateClassInternal[];\n}\n\nexport interface ɵSelectorMetaDataModel {\n makeRootSelector: ɵSelectorFactory | null;\n originalFn: Function | null;\n containerClass: any;\n selectorName: string | null;\n getSelectorOptions: () => ɵSharedSelectorOptions;\n}\n\nexport interface ɵSharedSelectorOptions {\n /**\n * @deprecated\n * Read the deprecation notice at this link: https://ngxs.io/deprecations/inject-container-state-deprecation.md.\n */\n injectContainerState?: boolean;\n suppressErrors?: boolean;\n}\n\nexport interface ɵRuntimeSelectorContext {\n getStateGetter(key: any): (state: any) => any;\n getSelectorOptions(localOptions?: ɵSharedSelectorOptions): ɵSharedSelectorOptions;\n}\n\nexport type ɵSelectFromRootState = (rootState: any) => any;\nexport type ɵSelectorFactory = (\n runtimeContext: ɵRuntimeSelectorContext\n) => ɵSelectFromRootState;\n\n/**\n * Actions that can be provided in a action decorator.\n */\nexport interface ɵActionOptions {\n /**\n * Cancel the previous uncompleted observable(s).\n */\n cancelUncompleted?: boolean;\n}\n\nexport interface ɵActionHandlerMetaData {\n fn: string | symbol;\n options: ɵActionOptions;\n type: string;\n}\n","// Property reads are not minified.\n// It's smaller to read it once and use a function.\nconst _hasOwnProperty = Object.prototype.hasOwnProperty;\nexport const ɵhasOwnProperty = (target: any, key: PropertyKey) =>\n _hasOwnProperty.call(target, key);\n\nexport const ɵdefineProperty = Object.defineProperty;\n","import { ɵdefineProperty, ɵhasOwnProperty } from './object-utils';\nimport {\n ɵMETA_KEY,\n ɵSELECTOR_META_KEY,\n ɵMetaDataModel,\n ɵStateClassInternal,\n ɵSelectorMetaDataModel,\n ɵRuntimeSelectorContext\n} from './symbols';\n\n/**\n * Ensures metadata is attached to the class and returns it.\n *\n * @ignore\n */\nexport function ɵensureStoreMetadata(target: ɵStateClassInternal): ɵMetaDataModel {\n if (!ɵhasOwnProperty(target, ɵMETA_KEY)) {\n const defaultMetadata: ɵMetaDataModel = {\n name: null,\n actions: {},\n defaults: {},\n path: null,\n makeRootSelector(context: ɵRuntimeSelectorContext) {\n return context.getStateGetter(defaultMetadata.name);\n },\n children: []\n };\n\n ɵdefineProperty(target, ɵMETA_KEY, { value: defaultMetadata });\n }\n return ɵgetStoreMetadata(target);\n}\n\n/**\n * Get the metadata attached to the state class if it exists.\n *\n * @ignore\n */\nexport function ɵgetStoreMetadata(target: ɵStateClassInternal): ɵMetaDataModel {\n return target[ɵMETA_KEY]!;\n}\n\n/**\n * Ensures metadata is attached to the selector and returns it.\n *\n * @ignore\n */\nexport function ɵensureSelectorMetadata(target: Function): ɵSelectorMetaDataModel {\n if (!ɵhasOwnProperty(target, ɵSELECTOR_META_KEY)) {\n const defaultMetadata: ɵSelectorMetaDataModel = {\n makeRootSelector: null,\n originalFn: null,\n containerClass: null,\n selectorName: null,\n getSelectorOptions: () => ({})\n };\n\n ɵdefineProperty(target, ɵSELECTOR_META_KEY, { value: defaultMetadata });\n }\n\n return ɵgetSelectorMetadata(target);\n}\n\n/**\n * Get the metadata attached to the selector if it exists.\n *\n * @ignore\n */\nexport function ɵgetSelectorMetadata(target: any): ɵSelectorMetaDataModel {\n return target[ɵSELECTOR_META_KEY];\n}\n","function areArgumentsShallowlyEqual(\n equalityCheck: (a: any, b: any) => boolean,\n prev: IArguments | null,\n next: IArguments | null\n) {\n if (prev === null || next === null || prev.length !== next.length) {\n return false;\n }\n\n // Do this in a for loop (and not a `forEach` or an `every`) so we can\n // determine equality as fast as possible.\n const length = prev.length;\n for (let i = 0; i < length; i++) {\n if (!equalityCheck(prev[i], next[i])) {\n return false;\n }\n }\n\n return true;\n}\n\n/**\n * Memoize a function on its last inputs only.\n * Originally from: https://github.com/reduxjs/reselect/blob/master/src/index.js\n *\n * @ignore\n */\nexport function ɵmemoize<T extends (...args: any[]) => any>(\n func: T,\n equalityCheck = Object.is\n): T {\n let lastArgs: IArguments | null = null;\n let lastResult: any = null;\n // we reference arguments instead of spreading them for performance reasons\n function memoized() {\n // eslint-disable-next-line prefer-rest-params\n if (!areArgumentsShallowlyEqual(equalityCheck, lastArgs, arguments)) {\n // apply arguments instead of spreading for performance.\n // eslint-disable-next-line prefer-rest-params, prefer-spread\n lastResult = (<Function>func).apply(null, arguments);\n }\n // eslint-disable-next-line prefer-rest-params\n lastArgs = arguments;\n return lastResult;\n }\n (<any>memoized).reset = function () {\n // The hidden (for now) ability to reset the memoization\n lastArgs = null;\n lastResult = null;\n };\n return memoized as T;\n}\n","import { ɵensureSelectorMetadata } from './metadata';\nimport type { ɵTokenName, ɵSelectFromRootState, ɵRuntimeSelectorContext } from './symbols';\n\nexport class StateToken<T = void> {\n constructor(private readonly _name: ɵTokenName<T>) {\n const selectorMetadata = ɵensureSelectorMetadata(<any>this);\n selectorMetadata.makeRootSelector = (\n runtimeContext: ɵRuntimeSelectorContext\n ): ɵSelectFromRootState => {\n return runtimeContext.getStateGetter(this._name);\n };\n }\n\n getName(): string {\n return this._name;\n }\n\n toString(): string {\n return `StateToken[${this._name}]`;\n }\n}\n","import { InjectionToken } from '@angular/core';\n\nimport { ɵPlainObject } from './symbols';\n\ndeclare const ngDevMode: boolean;\n\nexport class ɵInitialState {\n private static _value: ɵPlainObject = {};\n\n static set(state: ɵPlainObject) {\n this._value = state;\n }\n\n static pop(): ɵPlainObject {\n const state = this._value;\n this._value = {};\n return state;\n }\n}\n\nexport const ɵINITIAL_STATE_TOKEN = new InjectionToken<ɵPlainObject>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'INITIAL_STATE_TOKEN' : '',\n {\n providedIn: 'root',\n factory: () => ɵInitialState.pop()\n }\n);\n","import { DestroyRef, inject, Injectable } from '@angular/core';\nimport { BehaviorSubject } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class ɵNgxsAppBootstrappedState extends BehaviorSubject<boolean> {\n constructor() {\n super(false);\n\n const destroyRef = inject(DestroyRef);\n // Complete the subject once the root injector is destroyed to ensure\n // there are no active subscribers that would receive events or perform\n // any actions after the application is destroyed.\n destroyRef.onDestroy(() => {\n this.complete();\n this.unsubscribe();\n });\n }\n\n bootstrap(): void {\n this.next(true);\n }\n}\n","import { InjectionToken } from '@angular/core';\n\ndeclare const ngDevMode: boolean;\n\n// These tokens are internal and can change at any point.\n\nexport const ɵNGXS_STATE_FACTORY = /* @__PURE__ */ new InjectionToken<any>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'ɵNGXS_STATE_FACTORY' : ''\n);\n\nexport const ɵNGXS_STATE_CONTEXT_FACTORY = /* @__PURE__ */ new InjectionToken<any>(\n typeof ngDevMode !== 'undefined' && ngDevMode ? 'ɵNGXS_STATE_CONTEXT_FACTORY' : ''\n);\n","import { BehaviorSubject, Subject } from 'rxjs';\n\n/**\n * This wraps the provided function, and will enforce the following:\n * - The calls will execute in the order that they are made\n * - A call will only be initiated when the previous call has completed\n * - If there is a call currently executing then the new call will be added\n * to the queue and the function will return immediately\n *\n * NOTE: The following assumptions about the operation must hold true:\n * - The operation is synchronous in nature\n * - If any asynchronous side effects of the call exist, it should not\n * have any bearing on the correctness of the next call in the queue\n * - The operation has a void return\n * - The caller should not assume that the call has completed upon\n * return of the function\n * - The caller can assume that all the queued calls will complete\n * within the current microtask\n * - The only way that a call will encounter another call in the queue\n * would be if the call at the front of the queue initiated this call\n * as part of its synchronous execution\n */\nfunction orderedQueueOperation<TArgs extends any[]>(operation: (...args: TArgs) => void) {\n const callsQueue: TArgs[] = [];\n let busyPushingNext = false;\n return function callOperation(...args: TArgs) {\n if (busyPushingNext) {\n callsQueue.unshift(args);\n return;\n }\n busyPushingNext = true;\n operation(...args);\n while (callsQueue.length > 0) {\n const nextCallArgs = callsQueue.pop();\n nextCallArgs && operation(...nextCallArgs);\n }\n busyPushingNext = false;\n };\n}\n\n/**\n * Custom Subject that ensures that subscribers are notified of values in the order that they arrived.\n * A standard Subject does not have this guarantee.\n * For example, given the following code:\n * ```typescript\n * const subject = new Subject<string>();\n subject.subscribe(value => {\n if (value === 'start') subject.next('end');\n });\n subject.subscribe(value => { });\n subject.next('start');\n * ```\n * When `subject` is a standard `Subject<T>` the second subscriber would recieve `end` and then `start`.\n * When `subject` is a `OrderedSubject<T>` the second subscriber would recieve `start` and then `end`.\n */\nexport class ɵOrderedSubject<T> extends Subject<T> {\n private _orderedNext = orderedQueueOperation((value?: T) => super.next(<T>value));\n\n override next(value?: T): void {\n this._orderedNext(value);\n }\n}\n\n/**\n * Custom BehaviorSubject that ensures that subscribers are notified of values in the order that they arrived.\n * A standard BehaviorSubject does not have this guarantee.\n * For example, given the following code:\n * ```typescript\n * const subject = new BehaviorSubject<string>();\n subject.subscribe(value => {\n if (value === 'start') subject.next('end');\n });\n subject.subscribe(value => { });\n subject.next('start');\n * ```\n * When `subject` is a standard `BehaviorSubject<T>` the second subscriber would recieve `end` and then `start`.\n * When `subject` is a `OrderedBehaviorSubject<T>` the second subscriber would recieve `start` and then `end`.\n */\nexport class ɵOrderedBehaviorSubject<T> extends BehaviorSubject<T> {\n private _orderedNext = orderedQueueOperation((value: T) => super.next(value));\n private _currentValue: T;\n\n constructor(value: T) {\n super(value);\n this._currentValue = value;\n }\n\n override getValue(): T {\n return this._currentValue;\n }\n\n override next(value: T): void {\n this._currentValue = value;\n this._orderedNext(value);\n }\n}\n","import { type MonoTypeOperatorFunction, Observable } from 'rxjs';\n\nexport function ɵwrapObserverCalls<TValue>(\n invokeFn: (fn: () => void) => void\n): MonoTypeOperatorFunction<TValue> {\n return (source: Observable<TValue>) => {\n return new Observable<TValue>(subscriber => {\n return source.subscribe({\n next(value) {\n invokeFn(() => subscriber.next(value));\n },\n error(error) {\n invokeFn(() => subscriber.error(error));\n },\n complete() {\n invokeFn(() => subscriber.complete());\n }\n });\n });\n };\n}\n","import { DestroyRef, inject, Injectable, Signal, untracked } from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { Observable } from 'rxjs';\n\nimport { ɵwrapObserverCalls } from './custom-rxjs-operators';\nimport { ɵOrderedBehaviorSubject } from './custom-rxjs-subjects';\nimport { ɵPlainObject } from './symbols';\n\n/**\n * BehaviorSubject of the entire state.\n * @ignore\n */\n@Injectable({ providedIn: 'root' })\nexport class ɵStateStream extends ɵOrderedBehaviorSubject<ɵPlainObject> {\n readonly state: Signal<ɵPlainObject> = toSignal(this.pipe(ɵwrapObserverCalls(untracked)), {\n manualCleanup: true,\n requireSync: true\n });\n\n constructor() {\n super({});\n\n // Complete the subject once the root injector is destroyed to ensure\n // there are no active subscribers that would receive events or perform\n // any actions after the application is destroyed.\n // The `StateStream` should never emit values once the root view is removed,\n // such as when the `ApplicationRef.destroy()` method is called. This is crucial\n // for preventing memory leaks in server-side rendered apps, where a new `StateStream`\n // is created for each HTTP request. If users forget to unsubscribe from `store.select`\n // or `store.subscribe`, it can result in significant memory leaks in SSR apps.\n inject(DestroyRef).onDestroy(() => {\n this.complete();\n this.unsubscribe();\n });\n }\n}\n","import { DestroyRef, inject, Injectable } from '@angular/core';\nimport type { Observable } from 'rxjs';\n\nexport type ActionHandlerFn = (action: any) => Observable<unknown>;\n\n@Injectable({ providedIn: 'root' })\nexport class ɵNgxsActionRegistry {\n // Instead of going over the states list every time an action is dispatched,\n // we are constructing a map of action types to lists of action metadata.\n // If the `@@Init` action is handled in two different states, the action\n // metadata list will contain two objects that have the state `instance` and\n // method names to be used as action handlers (decorated with `@Action(InitState)`).\n private readonly _actionTypeToHandlersMap = new Map<string, Set<ActionHandlerFn>>();\n\n constructor() {\n inject(DestroyRef).onDestroy(() => this._actionTypeToHandlersMap.clear());\n }\n\n get(type: string) {\n return this._actionTypeToHandlersMap.get(type);\n }\n\n register(type: string, handler: ActionHandlerFn) {\n const handlers = this._actionTypeToHandlersMap.get(type) ?? new Set();\n handlers.add(handler);\n this._actionTypeToHandlersMap.set(type, handlers);\n\n return () => {\n const handlers = this._actionTypeToHandlersMap.get(type)!;\n handlers.delete(handler);\n };\n }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;AAYA;AACA;AACO,MAAM,SAAS,GAAG;AACzB;AACA;AACO,MAAM,iBAAiB,GAAG;AACjC;AACA;AACA;AACO,MAAM,kBAAkB,GAAG;;ACrBlC;AACA;AACA,MAAM,eAAe,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc;AAC1C,MAAA,eAAe,GAAG,CAAC,MAAW,EAAE,GAAgB,KAC3D,eAAe,CAAC,IAAI,C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,GAAG,CAAC,IAAI,CAAE;AACzD,YAAA,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;AAC1B,SAAC;;0HAxBQ,mBAAmB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAAnB,uBAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,mBAAmB,cADN,MAAM,EAAA,CAAA;;2FACnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAD/B,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACLlC;;AAEG;;;;"}
|
package/fesm2022/ngxs-store.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { inject, Injectable, DestroyRef, NgZone, Injector, runInInjectionContext, InjectionToken, ErrorHandler, ɵisPromise as _isPromise, computed, makeEnvironmentProviders, provideEnvironmentInitializer,
|
|
2
|
+
import { inject, Injectable, DestroyRef, NgZone, Injector, runInInjectionContext, InjectionToken, ErrorHandler, ɵisPromise as _isPromise, computed, makeEnvironmentProviders, provideEnvironmentInitializer, assertInInjectionContext, createEnvironmentInjector, EnvironmentInjector, NgModule, APP_BOOTSTRAP_LISTENER, PendingTasks, ApplicationRef } from '@angular/core';
|
|
3
3
|
import { config, Observable, Subject, of, forkJoin, map, shareReplay, filter, take, mergeMap, EMPTY, from, isObservable, defaultIfEmpty, takeUntil, finalize, catchError, distinctUntilChanged, startWith, skip, buffer, debounceTime } from 'rxjs';
|
|
4
4
|
import { ɵwrapObserverCalls as _wrapObserverCalls, ɵOrderedSubject as _OrderedSubject, ɵStateStream as _StateStream, ɵhasOwnProperty as _hasOwnProperty, ɵmemoize as _memoize, ɵgetStoreMetadata as _getStoreMetadata, ɵgetSelectorMetadata as _getSelectorMetadata, ɵMETA_KEY as _META_KEY, ɵINITIAL_STATE_TOKEN as _INITIAL_STATE_TOKEN, ɵNgxsActionRegistry as _NgxsActionRegistry, ɵNgxsAppBootstrappedState as _NgxsAppBootstrappedState, ɵensureStoreMetadata as _ensureStoreMetadata, ɵMETA_OPTIONS_KEY as _META_OPTIONS_KEY, ɵensureSelectorMetadata as _ensureSelectorMetadata, ɵNGXS_STATE_CONTEXT_FACTORY as _NGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY as _NGXS_STATE_FACTORY } from '@ngxs/store/internals';
|
|
5
5
|
export { StateToken } from '@ngxs/store/internals';
|
|
@@ -131,7 +131,10 @@ class InternalDispatchedActionResults extends Subject {
|
|
|
131
131
|
// Complete the subject once the root injector is destroyed to ensure
|
|
132
132
|
// there are no active subscribers that would receive events or perform
|
|
133
133
|
// any actions after the application is destroyed.
|
|
134
|
-
inject(DestroyRef).onDestroy(() =>
|
|
134
|
+
inject(DestroyRef).onDestroy(() => {
|
|
135
|
+
this.complete();
|
|
136
|
+
this.unsubscribe();
|
|
137
|
+
});
|
|
135
138
|
}
|
|
136
139
|
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: InternalDispatchedActionResults, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
137
140
|
/** @nocollapse */ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: InternalDispatchedActionResults, providedIn: 'root' });
|
|
@@ -202,7 +205,9 @@ class InternalActions extends _OrderedSubject {
|
|
|
202
205
|
// there are no active subscribers that would receive events or perform
|
|
203
206
|
// any actions after the application is destroyed.
|
|
204
207
|
this.complete();
|
|
208
|
+
this.unsubscribe();
|
|
205
209
|
this.dispatched$.complete();
|
|
210
|
+
this.dispatched$.unsubscribe();
|
|
206
211
|
});
|
|
207
212
|
}
|
|
208
213
|
/** @nocollapse */ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.2", ngImport: i0, type: InternalActions, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
@@ -1570,6 +1575,125 @@ function withNgxsPreboot(prebootFn) {
|
|
|
1570
1575
|
]);
|
|
1571
1576
|
}
|
|
1572
1577
|
|
|
1578
|
+
/**
|
|
1579
|
+
* This function registers a custom global plugin for the state.
|
|
1580
|
+
*
|
|
1581
|
+
* ```ts
|
|
1582
|
+
* bootstrapApplication(AppComponent, {
|
|
1583
|
+
* providers: [
|
|
1584
|
+
* provideStore(
|
|
1585
|
+
* [CountriesState],
|
|
1586
|
+
* withNgxsPlugin(LogoutPlugin)
|
|
1587
|
+
* )
|
|
1588
|
+
* ]
|
|
1589
|
+
* });
|
|
1590
|
+
* ```
|
|
1591
|
+
*/
|
|
1592
|
+
function withNgxsPlugin(plugin) {
|
|
1593
|
+
return makeEnvironmentProviders([
|
|
1594
|
+
_isPluginClass(plugin)
|
|
1595
|
+
? { provide: NGXS_PLUGINS, useClass: plugin, multi: true }
|
|
1596
|
+
: { provide: NGXS_PLUGINS, useValue: plugin, multi: true },
|
|
1597
|
+
// We should inject the `PluginManager` to retrieve `NGXS_PLUGINS` and
|
|
1598
|
+
// register those plugins. The plugin can be added from inside the child
|
|
1599
|
+
// route, so the plugin manager should be re-injected.
|
|
1600
|
+
provideEnvironmentInitializer(() => inject(PluginManager))
|
|
1601
|
+
]);
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
const REGISTERED_PLUGINS = /* @__PURE__ */ new InjectionToken('', {
|
|
1605
|
+
factory: () => {
|
|
1606
|
+
const plugins = new Set();
|
|
1607
|
+
inject(DestroyRef).onDestroy(() => plugins.clear());
|
|
1608
|
+
return plugins;
|
|
1609
|
+
}
|
|
1610
|
+
});
|
|
1611
|
+
/**
|
|
1612
|
+
* Dynamically registers an NGXS plugin in the current injection context.
|
|
1613
|
+
*
|
|
1614
|
+
* This function allows you to register NGXS plugins at runtime, creating an isolated
|
|
1615
|
+
* environment injector for the plugin. The plugin is automatically cleaned up when
|
|
1616
|
+
* the injection context is destroyed. In development mode, the function validates
|
|
1617
|
+
* that the same plugin is not registered multiple times.
|
|
1618
|
+
*
|
|
1619
|
+
* @param plugin - The NGXS plugin to register. Can be either a class type implementing
|
|
1620
|
+
* `NgxsPlugin` or a plugin function (`NgxsPluginFn`).
|
|
1621
|
+
*
|
|
1622
|
+
* @throws {Error} Throws an error if called outside of an injection context.
|
|
1623
|
+
* @throws {Error} In development mode, throws an error if the plugin has already been registered.
|
|
1624
|
+
*
|
|
1625
|
+
* @remarks
|
|
1626
|
+
* - Must be called within an injection context (e.g., constructor, field initializer, or `runInInjectionContext`).
|
|
1627
|
+
* - The created environment injector is automatically destroyed when the parent context is destroyed.
|
|
1628
|
+
* - Duplicate plugin registration is only checked in development mode for performance reasons.
|
|
1629
|
+
*
|
|
1630
|
+
* @example
|
|
1631
|
+
* ```ts
|
|
1632
|
+
* // Register a plugin class
|
|
1633
|
+
* import { MyThirdPartyIntegrationPlugin } from './plugins/third-party.plugin';
|
|
1634
|
+
*
|
|
1635
|
+
* @Component({
|
|
1636
|
+
* selector: 'app-root',
|
|
1637
|
+
* template: '...'
|
|
1638
|
+
* })
|
|
1639
|
+
* export class AppComponent {
|
|
1640
|
+
* constructor() {
|
|
1641
|
+
* registerNgxsPlugin(MyThirdPartyIntegrationPlugin);
|
|
1642
|
+
* }
|
|
1643
|
+
* }
|
|
1644
|
+
* ```
|
|
1645
|
+
*
|
|
1646
|
+
* @example
|
|
1647
|
+
* ```ts
|
|
1648
|
+
* // Register a plugin function
|
|
1649
|
+
* import { myThirdPartyIntegrationPluginFn } from './plugins/third-party.plugin';
|
|
1650
|
+
*
|
|
1651
|
+
* @Component({
|
|
1652
|
+
* selector: 'app-feature',
|
|
1653
|
+
* template: '...'
|
|
1654
|
+
* })
|
|
1655
|
+
* export class FeatureComponent {
|
|
1656
|
+
* constructor() {
|
|
1657
|
+
* registerNgxsPlugin(myThirdPartyIntegrationPluginFn);
|
|
1658
|
+
* }
|
|
1659
|
+
* }
|
|
1660
|
+
* ```
|
|
1661
|
+
*
|
|
1662
|
+
* @example
|
|
1663
|
+
* ```ts
|
|
1664
|
+
* // Register conditionally based on environment
|
|
1665
|
+
* import { MyDevtoolsPlugin } from './plugins/devtools.plugin';
|
|
1666
|
+
*
|
|
1667
|
+
* @Component({
|
|
1668
|
+
* selector: 'app-root',
|
|
1669
|
+
* template: '...'
|
|
1670
|
+
* })
|
|
1671
|
+
* export class AppComponent {
|
|
1672
|
+
* constructor() {
|
|
1673
|
+
* if (ngDevMode) {
|
|
1674
|
+
* registerNgxsPlugin(MyDevtoolsPlugin);
|
|
1675
|
+
* }
|
|
1676
|
+
* }
|
|
1677
|
+
* }
|
|
1678
|
+
* ```
|
|
1679
|
+
*/
|
|
1680
|
+
function registerNgxsPlugin(plugin) {
|
|
1681
|
+
ngDevMode && assertInInjectionContext(registerNgxsPlugin);
|
|
1682
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode) {
|
|
1683
|
+
const registeredPlugins = inject(REGISTERED_PLUGINS);
|
|
1684
|
+
if (registeredPlugins.has(plugin)) {
|
|
1685
|
+
throw new Error('Plugin has already been registered. Each plugin should only be registered once to avoid unexpected behavior.');
|
|
1686
|
+
}
|
|
1687
|
+
registeredPlugins.add(plugin);
|
|
1688
|
+
}
|
|
1689
|
+
// Create a new environment injector with the plugin configuration.
|
|
1690
|
+
// This isolates the plugin's dependencies and providers.
|
|
1691
|
+
const injector = createEnvironmentInjector([PluginManager, withNgxsPlugin(plugin)], inject(EnvironmentInjector));
|
|
1692
|
+
// Ensure the created injector is destroyed when the injection context is destroyed.
|
|
1693
|
+
// This prevents memory leaks and ensures proper cleanup.
|
|
1694
|
+
inject(DestroyRef).onDestroy(() => injector.destroy());
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1573
1697
|
const ROOT_STORE_GUARD = /* @__PURE__ */ new InjectionToken('ROOT_STORE_GUARD', {
|
|
1574
1698
|
providedIn: 'root',
|
|
1575
1699
|
factory: () => ({ initialized: false })
|
|
@@ -2376,32 +2500,6 @@ function provideStates(states, ...features) {
|
|
|
2376
2500
|
]);
|
|
2377
2501
|
}
|
|
2378
2502
|
|
|
2379
|
-
/**
|
|
2380
|
-
* This function registers a custom global plugin for the state.
|
|
2381
|
-
*
|
|
2382
|
-
* ```ts
|
|
2383
|
-
* bootstrapApplication(AppComponent, {
|
|
2384
|
-
* providers: [
|
|
2385
|
-
* provideStore(
|
|
2386
|
-
* [CountriesState],
|
|
2387
|
-
* withNgxsPlugin(LogoutPlugin)
|
|
2388
|
-
* )
|
|
2389
|
-
* ]
|
|
2390
|
-
* });
|
|
2391
|
-
* ```
|
|
2392
|
-
*/
|
|
2393
|
-
function withNgxsPlugin(plugin) {
|
|
2394
|
-
return makeEnvironmentProviders([
|
|
2395
|
-
_isPluginClass(plugin)
|
|
2396
|
-
? { provide: NGXS_PLUGINS, useClass: plugin, multi: true }
|
|
2397
|
-
: { provide: NGXS_PLUGINS, useValue: plugin, multi: true },
|
|
2398
|
-
// We should inject the `PluginManager` to retrieve `NGXS_PLUGINS` and
|
|
2399
|
-
// register those plugins. The plugin can be added from inside the child
|
|
2400
|
-
// route, so the plugin manager should be re-injected.
|
|
2401
|
-
provideEnvironmentInitializer(() => inject(PluginManager))
|
|
2402
|
-
]);
|
|
2403
|
-
}
|
|
2404
|
-
|
|
2405
2503
|
/**
|
|
2406
2504
|
* This function serves as a utility and has multiple purposes.
|
|
2407
2505
|
* Firstly, it allows you to select properties from the state class
|
|
@@ -2419,9 +2517,39 @@ function select(selector) {
|
|
|
2419
2517
|
return inject(Store).selectSignal(selector);
|
|
2420
2518
|
}
|
|
2421
2519
|
|
|
2520
|
+
// Extends Observable so callers can subscribe to emission updates (e.g. progress, intermediate states),
|
|
2521
|
+
// while implementing PromiseLike so the JS engine treats it as a thenable when `await` is used —
|
|
2522
|
+
// without this dual nature, callers would have to choose upfront between async/await and reactive patterns.
|
|
2523
|
+
class AsyncReturnType extends Observable {
|
|
2524
|
+
dispatchResult$;
|
|
2525
|
+
constructor(dispatchResult$) {
|
|
2526
|
+
super(subscriber => dispatchResult$.subscribe(subscriber));
|
|
2527
|
+
this.dispatchResult$ = dispatchResult$;
|
|
2528
|
+
}
|
|
2529
|
+
// Called automatically by the JS engine when `await dispatch(...)` is used.
|
|
2530
|
+
// The PromiseLike contract requires full generics on TResult1/TResult2 to support
|
|
2531
|
+
// promise chaining (e.g. `await dispatch(...).then(x => transform(x))`).
|
|
2532
|
+
then(onfulfilled, onrejected) {
|
|
2533
|
+
return new Promise((resolve, reject) => {
|
|
2534
|
+
this.dispatchResult$.subscribe({
|
|
2535
|
+
// Propagate observable errors into the promise rejection path so
|
|
2536
|
+
// `try/catch` around `await dispatch(...)` works as expected.
|
|
2537
|
+
error: reject,
|
|
2538
|
+
// Resolve on complete rather than on next emission — dispatch returns void,
|
|
2539
|
+
// so the caller cares about the action finishing, not any intermediate values.
|
|
2540
|
+
complete: resolve
|
|
2541
|
+
});
|
|
2542
|
+
}).then(
|
|
2543
|
+
// Bridge void → undefined because PromiseLike<void> resolves with no value,
|
|
2544
|
+
// but `onfulfilled` still needs to be invoked to continue the chain correctly.
|
|
2545
|
+
onfulfilled ? () => onfulfilled(undefined) : undefined,
|
|
2546
|
+
// Normalize null to undefined since Promise.then doesn't accept null for rejection handler.
|
|
2547
|
+
onrejected ?? undefined);
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2422
2550
|
function dispatch(ActionType) {
|
|
2423
2551
|
const store = inject(Store);
|
|
2424
|
-
return (...args) => store.dispatch(new ActionType(...args));
|
|
2552
|
+
return (...args) => new AsyncReturnType(store.dispatch(new ActionType(...args)));
|
|
2425
2553
|
}
|
|
2426
2554
|
|
|
2427
2555
|
function createSelectMap(selectorMap) {
|
|
@@ -2524,5 +2652,5 @@ function ɵprovideNgxsInternalStateTokens() {
|
|
|
2524
2652
|
* Generated bundle index. Do not edit.
|
|
2525
2653
|
*/
|
|
2526
2654
|
|
|
2527
|
-
export { Action, ActionDirector, ActionStatus, Actions, NgxsConfig, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NgxsUnhandledErrorHandler, Select, Selector, SelectorOptions, State, Store, createDispatchMap, createModelSelector, createPickSelector, createPropertySelectors, createSelectMap, createSelector, dispatch, lazyProvider, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, select, withNgxsDevelopmentOptions, withNgxsNoopExecutionStrategy, withNgxsPendingTasks, withNgxsPlugin, withNgxsPreboot, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule, ɵprovideNgxsInternalStateTokens };
|
|
2655
|
+
export { Action, ActionDirector, ActionStatus, Actions, NgxsConfig, NgxsDevelopmentModule, NgxsModule, NgxsSimpleChange, NgxsUnhandledActionsLogger, NgxsUnhandledErrorHandler, Select, Selector, SelectorOptions, State, Store, createDispatchMap, createModelSelector, createPickSelector, createPropertySelectors, createSelectMap, createSelector, dispatch, lazyProvider, ofAction, ofActionCanceled, ofActionCompleted, ofActionDispatched, ofActionErrored, ofActionSuccessful, provideStates, provideStore, registerNgxsPlugin, select, withNgxsDevelopmentOptions, withNgxsNoopExecutionStrategy, withNgxsPendingTasks, withNgxsPlugin, withNgxsPreboot, NgxsFeatureModule as ɵNgxsFeatureModule, NgxsRootModule as ɵNgxsRootModule, ɵprovideNgxsInternalStateTokens };
|
|
2528
2656
|
//# sourceMappingURL=ngxs-store.mjs.map
|