@ngxs/store 3.8.1 → 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 +664 -527
- package/bundles/ngxs-store-internals-testing.umd.js.map +1 -1
- package/bundles/ngxs-store-internals.umd.js +0 -14
- package/bundles/ngxs-store-internals.umd.js.map +1 -1
- package/bundles/ngxs-store-operators.umd.js +1 -1
- package/bundles/ngxs-store-operators.umd.js.map +1 -1
- package/bundles/ngxs-store.umd.js +3014 -2898
- package/bundles/ngxs-store.umd.js.map +1 -1
- package/esm2015/internals/index.js +1 -2
- package/esm2015/operators/patch.js +2 -2
- package/esm2015/src/actions/actions.js +3 -9
- package/esm2015/src/decorators/state.js +23 -25
- package/esm2015/src/internal/custom-rxjs-subjects.js +2 -2
- package/esm2015/src/internal/state-context-factory.js +25 -27
- package/esm2015/src/internal/state-factory.js +8 -11
- package/esm2015/src/selectors/create-model-selector.js +11 -9
- package/esm2015/src/selectors/create-pick-selector.js +5 -3
- package/esm2015/src/selectors/create-property-selectors.js +8 -6
- package/esm2015/src/utils/store-validators.js +19 -21
- package/fesm2015/ngxs-store-internals.js +1 -14
- package/fesm2015/ngxs-store-internals.js.map +1 -1
- package/fesm2015/ngxs-store-operators.js +1 -1
- package/fesm2015/ngxs-store-operators.js.map +1 -1
- package/fesm2015/ngxs-store.js +91 -100
- package/fesm2015/ngxs-store.js.map +1 -1
- package/internals/index.d.ts +0 -1
- package/package.json +2 -2
- package/src/actions/actions.d.ts +2 -2
- package/src/internal/custom-rxjs-subjects.d.ts +1 -1
- package/src/internal/state-factory.d.ts +1 -1
- package/src/utils/store-validators.d.ts +3 -6
- package/esm2015/internals/angular.js +0 -13
- package/internals/angular.d.ts +0 -1
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { createSelector } from './create-selector';
|
|
2
2
|
import { ensureValidSelector } from './selector-checks.util';
|
|
3
3
|
export function createPropertySelectors(parentSelector) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
5
|
+
ensureValidSelector(parentSelector, {
|
|
6
|
+
prefix: '[createPropertySelectors]',
|
|
7
|
+
noun: 'parent selector'
|
|
8
|
+
});
|
|
9
|
+
}
|
|
8
10
|
const cache = {};
|
|
9
11
|
return new Proxy({}, {
|
|
10
12
|
get(_target, prop) {
|
|
@@ -12,7 +14,7 @@ export function createPropertySelectors(parentSelector) {
|
|
|
12
14
|
createSelector([parentSelector], (s) => s === null || s === void 0 ? void 0 : s[prop]);
|
|
13
15
|
cache[prop] = selector;
|
|
14
16
|
return selector;
|
|
15
|
-
}
|
|
17
|
+
}
|
|
16
18
|
});
|
|
17
19
|
}
|
|
18
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
20
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY3JlYXRlLXByb3BlcnR5LXNlbGVjdG9ycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3N0b3JlL3NyYy9zZWxlY3RvcnMvY3JlYXRlLXByb3BlcnR5LXNlbGVjdG9ycy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sbUJBQW1CLENBQUM7QUFDbkQsT0FBTyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sd0JBQXdCLENBQUM7QUFTN0QsTUFBTSxVQUFVLHVCQUF1QixDQUNyQyxjQUFtQztJQUVuQyxJQUFJLE9BQU8sU0FBUyxLQUFLLFdBQVcsSUFBSSxTQUFTLEVBQUU7UUFDakQsbUJBQW1CLENBQUMsY0FBYyxFQUFFO1lBQ2xDLE1BQU0sRUFBRSwyQkFBMkI7WUFDbkMsSUFBSSxFQUFFLGlCQUFpQjtT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
|
|
@@ -1,27 +1,25 @@
|
|
|
1
1
|
import { getStoreMetadata } from '../internal/internals';
|
|
2
2
|
import { throwStateDecoratorError, throwStateNameError, throwStateNamePropertyError, throwStateUniqueError } from '../configs/messages.config';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
else if (!this.stateNameRegex.test(name)) {
|
|
9
|
-
throwStateNameError(name);
|
|
10
|
-
}
|
|
3
|
+
const stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
|
|
4
|
+
export function ensureStateNameIsValid(name) {
|
|
5
|
+
if (!name) {
|
|
6
|
+
throwStateNamePropertyError();
|
|
11
7
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (existingState && existingState !== state) {
|
|
15
|
-
throwStateUniqueError(stateName, state.name, existingState.name);
|
|
16
|
-
}
|
|
8
|
+
else if (!stateNameRegex.test(name)) {
|
|
9
|
+
throwStateNameError(name);
|
|
17
10
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
11
|
+
}
|
|
12
|
+
export function ensureStateNameIsUnique(stateName, state, statesByName) {
|
|
13
|
+
const existingState = statesByName[stateName];
|
|
14
|
+
if (existingState && existingState !== state) {
|
|
15
|
+
throwStateUniqueError(stateName, state.name, existingState.name);
|
|
24
16
|
}
|
|
25
17
|
}
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
export function ensureStatesAreDecorated(stateClasses) {
|
|
19
|
+
stateClasses.forEach((stateClass) => {
|
|
20
|
+
if (!getStoreMetadata(stateClass)) {
|
|
21
|
+
throwStateDecoratorError(stateClass.name);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmUtdmFsaWRhdG9ycy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2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lciB7XG4gIGNvbnN0IGV4aXN0aW5nU3RhdGUgPSBzdGF0ZXNCeU5hbWVbc3RhdGVOYW1lXTtcbiAgaWYgKGV4aXN0aW5nU3RhdGUgJiYgZXhpc3RpbmdTdGF0ZSAhPT0gc3RhdGUpIHtcbiAgICB0aHJvd1N0YXRlVW5pcXVlRXJyb3Ioc3RhdGVOYW1lLCBzdGF0ZS5uYW1lLCBleGlzdGluZ1N0YXRlLm5hbWUpO1xuICB9XG59XG5cbmV4cG9ydCBmdW5jdGlvbiBlbnN1cmVTdGF0ZXNBcmVEZWNvcmF0ZWQoc3RhdGVDbGFzc2VzOiBTdGF0ZUNsYXNzSW50ZXJuYWxbXSk6IHZvaWQgfCBuZXZlciB7XG4gIHN0YXRlQ2xhc3Nlcy5mb3JFYWNoKChzdGF0ZUNsYXNzOiBTdGF0ZUNsYXNzSW50ZXJuYWwpID0+IHtcbiAgICBpZiAoIWdldFN0b3JlTWV0YWRhdGEoc3RhdGVDbGFzcykpIHtcbiAgICAgIHRocm93U3RhdGVEZWNvcmF0b3JFcnJvcihzdGF0ZUNsYXNzLm5hbWUpO1xuICAgIH1cbiAgfSk7XG59XG4iXX0=
|
|
@@ -2,19 +2,6 @@ import * as i0 from '@angular/core';
|
|
|
2
2
|
import { Injectable, InjectionToken } from '@angular/core';
|
|
3
3
|
import { ReplaySubject } from 'rxjs';
|
|
4
4
|
|
|
5
|
-
function isAngularInTestMode() {
|
|
6
|
-
// This is safe to check for these properties in the following way since `typeof` does not
|
|
7
|
-
// throw an exception if the value does not exist in the scope.
|
|
8
|
-
// We should not try to read these values from the global scope (e.g. `ɵglobal` from the `@angular/core`).
|
|
9
|
-
// This is related to how these frameworks compile and execute modules. E.g. Jest wraps the module into
|
|
10
|
-
// its internal code where `jest` variable exists in the scope. It cannot be read from the global scope, e.g.
|
|
11
|
-
// this will return undefined `global.jest`, but `jest` will not equal undefined.
|
|
12
|
-
return (typeof __karma__ !== 'undefined' ||
|
|
13
|
-
typeof jasmine !== 'undefined' ||
|
|
14
|
-
typeof jest !== 'undefined' ||
|
|
15
|
-
typeof Mocha !== 'undefined');
|
|
16
|
-
}
|
|
17
|
-
|
|
18
5
|
class NgxsBootstrapper {
|
|
19
6
|
constructor() {
|
|
20
7
|
/**
|
|
@@ -110,5 +97,5 @@ const ɵNGXS_STATE_CONTEXT_FACTORY = new InjectionToken('ɵNGXS_STATE_CONTEXT_FA
|
|
|
110
97
|
* Generated bundle index. Do not edit.
|
|
111
98
|
*/
|
|
112
99
|
|
|
113
|
-
export { INITIAL_STATE_TOKEN, InitialState, NgxsBootstrapper,
|
|
100
|
+
export { INITIAL_STATE_TOKEN, InitialState, NgxsBootstrapper, memoize, ɵNGXS_STATE_CONTEXT_FACTORY, ɵNGXS_STATE_FACTORY };
|
|
114
101
|
//# sourceMappingURL=ngxs-store-internals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngxs-store-internals.js","sources":["../../../packages/store/internals/src/
|
|
1
|
+
{"version":3,"file":"ngxs-store-internals.js","sources":["../../../packages/store/internals/src/ngxs-bootstrapper.ts","../../../packages/store/internals/src/memoize.ts","../../../packages/store/internals/src/initial-state.ts","../../../packages/store/internals/src/internal-tokens.ts","../../../packages/store/internals/src/ngxs-store-internals.ts"],"sourcesContent":["import { Injectable } from '@angular/core';\nimport { Observable, ReplaySubject } from 'rxjs';\n\n@Injectable({ providedIn: 'root' })\nexport class NgxsBootstrapper {\n /**\n * Use `ReplaySubject`, thus we can get cached value even if the stream is completed\n */\n private bootstrap$ = new ReplaySubject<boolean>(1);\n\n get appBootstrapped$(): Observable<boolean> {\n return this.bootstrap$.asObservable();\n }\n\n /**\n * This event will be emitted after attaching `ComponentRef` of the root component\n * to the tree of views, that's a signal that application has been fully rendered\n */\n bootstrap(): void {\n this.bootstrap$.next(true);\n this.bootstrap$.complete();\n }\n}\n","function defaultEqualityCheck(a: any, b: any) {\n return a === b;\n}\n\nfunction 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 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 = defaultEqualityCheck\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 { InjectionToken } from '@angular/core';\nimport { PlainObject } from './symbols';\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<any>('INITIAL_STATE_TOKEN', {\n providedIn: 'root',\n factory: () => InitialState.pop()\n});\n","import { InjectionToken } from '@angular/core';\n\n// These tokens are internal and can change at any point.\n\nexport const ɵNGXS_STATE_FACTORY = new InjectionToken<any>('ɵNGXS_STATE_FACTORY');\n\nexport const ɵNGXS_STATE_CONTEXT_FACTORY = new InjectionToken<any>(\n 'ɵNGXS_STATE_CONTEXT_FACTORY'\n);\n","/**\n * Generated bundle index. Do not edit.\n */\n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M;AAClB,IAAA,OAAO,EAAE,MAAM,YAAY,CAAC,GAAG,EAAE;AAClC,CAAA;;AClBD;MAEa,mBAAmB,GAAG,IAAI,cAAc,CAAM,qBAAqB,EAAE;MAErE,2BAA2B,GAAG,IAAI,cAAc,CAC3D,6BAA6B;;ACP/B;;AAEG;;;;"}
|
|
@@ -113,7 +113,7 @@ function patch(patchObject) {
|
|
|
113
113
|
let clone = null;
|
|
114
114
|
for (const k in patchObject) {
|
|
115
115
|
const newValue = patchObject[k];
|
|
116
|
-
const existingPropValue = existing[k];
|
|
116
|
+
const existingPropValue = existing === null || existing === void 0 ? void 0 : existing[k];
|
|
117
117
|
const newPropValue = isStateOperator(newValue)
|
|
118
118
|
? newValue(existingPropValue)
|
|
119
119
|
: newValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngxs-store-operators.js","sources":["../../../packages/store/operators/src/append.ts","../../../packages/store/operators/src/compose.ts","../../../packages/store/operators/src/utils.ts","../../../packages/store/operators/src/iif.ts","../../../packages/store/operators/src/insert-item.ts","../../../packages/store/operators/src/patch.ts","../../../packages/store/operators/src/update-item.ts","../../../packages/store/operators/src/remove-item.ts","../../../packages/store/operators/src/index.ts","../../../packages/store/operators/src/ngxs-store-operators.ts"],"sourcesContent":["import { ExistingState, NoInfer, StateOperator } from './types';\n\n/**\n * @param items - Specific items to append to the end of an array\n */\nexport function append<T>(items: NoInfer<T[]>): StateOperator<T[]> {\n return function appendOperator(existing: ExistingState<T[]>): T[] {\n // If `items` is `undefined` or `null` or `[]` but `existing` is provided\n // just return `existing`\n const itemsNotProvidedButExistingIs = (!items || !items.length) && existing;\n if (itemsNotProvidedButExistingIs) {\n return (existing as unknown) as T[];\n }\n\n if (Array.isArray(existing)) {\n return existing.concat((items as unknown) as ExistingState<T[]>);\n }\n\n // For example if some property is added dynamically\n // and didn't exist before thus it's not `ArrayLike`\n return (items as unknown) as T[];\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\n\nexport function compose<T>(...operators: NoInfer<StateOperator<T>[]>): StateOperator<T> {\n return function composeOperator(existing: ExistingState<T>): T {\n return operators.reduce(\n (accumulator, operator) => operator(accumulator as ExistingState<T>),\n existing as T\n );\n };\n}\n","import { StateOperator } from './types';\n\nexport type Predicate<T = any> = (value: T | Readonly<T>) => boolean;\n\nexport function isStateOperator<T>(value: T | StateOperator<T>): value is StateOperator<T> {\n return typeof value === 'function';\n}\n\nexport function isUndefined(value: any): value is undefined {\n return typeof value === 'undefined';\n}\n\nexport function isPredicate<T>(value: Predicate<T> | boolean | number): value is Predicate<T> {\n return typeof value === 'function';\n}\n\nexport function isNumber(value: any): value is number {\n return typeof value === 'number';\n}\n\nexport function invalidIndex(index: number): boolean {\n return Number.isNaN(index) || index === -1;\n}\n\nexport function isNil<T>(value: T | null | undefined): value is null | undefined {\n return value === null || isUndefined(value);\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\n\nimport { isStateOperator, isUndefined, isPredicate, Predicate } from './utils';\n\nfunction retrieveValue<T>(\n operatorOrValue: StateOperator<T> | T,\n existing: ExistingState<T>\n): T {\n // If state operator is a function\n // then call it with an original value\n if (isStateOperator(operatorOrValue)) {\n const value = operatorOrValue(existing);\n return value as T;\n }\n\n // If operator or value was not provided\n // e.g. `elseOperatorOrValue` is `undefined`\n // then we just return an original value\n if (isUndefined(operatorOrValue)) {\n return existing as T;\n }\n\n return operatorOrValue as T;\n}\n\n/**\n * @param condition - Condition can be a plain boolean value or a function,\n * that returns boolean, also this function can take a value as an argument\n * to which this state operator applies\n * @param trueOperatorOrValue - Any value or a state operator\n * @param elseOperatorOrValue - Any value or a state operator\n */\nexport function iif<T>(\n condition: NoInfer<Predicate<T>> | boolean,\n trueOperatorOrValue: NoInfer<StateOperator<T> | T>,\n elseOperatorOrValue?: NoInfer<StateOperator<T> | T>\n): StateOperator<T> {\n return function iifOperator(existing: ExistingState<T>): T {\n // Convert the value to a boolean\n let result = !!condition;\n // but if it is a function then run it to get the result\n if (isPredicate(condition)) {\n result = condition(existing as T);\n }\n\n if (result) {\n return retrieveValue<T>(trueOperatorOrValue as StateOperator<T> | T, existing);\n }\n\n return retrieveValue<T>(elseOperatorOrValue! as StateOperator<T> | T, existing);\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isNil } from './utils';\n\n/**\n * @param value - Value to insert\n * @param [beforePosition] - Specified index to insert value before, optional\n */\nexport function insertItem<T>(value: NoInfer<T>, beforePosition?: number): StateOperator<T[]> {\n return function insertItemOperator(existing: ExistingState<T[]>): T[] {\n // Have to check explicitly for `null` and `undefined`\n // because `value` can be `0`, thus `!value` will return `true`\n if (isNil(value) && existing) {\n return existing as T[];\n }\n\n // Property may be dynamic and might not existed before\n if (!Array.isArray(existing)) {\n return [(value as unknown) as T];\n }\n\n const clone = existing.slice();\n\n let index = 0;\n\n // No need to call `isNumber`\n // as we are checking `> 0` not `>= 0`\n // everything except number will return false here\n if (beforePosition! > 0) {\n index = beforePosition!;\n }\n\n clone.splice(index, 0, (value as unknown) as T);\n return clone;\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isStateOperator } from './utils';\n\ntype NotUndefined<T> = T extends undefined ? never : T;\n\nexport type ɵPatchSpec<T> = { [P in keyof T]?: T[P] | StateOperator<NotUndefined<T[P]>> };\n\nexport function patch<T extends Record<string, any>>(\n patchObject: NoInfer<ɵPatchSpec<T>>\n): StateOperator<T> {\n return function patchStateOperator(existing: ExistingState<T>): T {\n let clone = null;\n for (const k in patchObject) {\n const newValue = patchObject[k];\n const existingPropValue = existing[k];\n const newPropValue = isStateOperator(newValue)\n ? newValue(<any>existingPropValue)\n : newValue;\n if (newPropValue !== existingPropValue) {\n if (!clone) {\n clone = { ...(<any>existing) };\n }\n clone[k] = newPropValue;\n }\n }\n return clone || existing;\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\n\nimport { isStateOperator, isPredicate, isNumber, invalidIndex, Predicate } from './utils';\n\n/**\n * @param selector - Index of item in the array or a predicate function\n * that can be provided in `Array.prototype.findIndex`\n * @param operatorOrValue - New value under the `selector` index or a\n * function that can be applied to an existing value\n */\nexport function updateItem<T>(\n selector: number | NoInfer<Predicate<T>>,\n operatorOrValue: NoInfer<T> | NoInfer<StateOperator<T>>\n): StateOperator<T[]> {\n return function updateItemOperator(existing: ExistingState<T[]>): T[] {\n let index = -1;\n\n if (isPredicate(selector)) {\n index = existing.findIndex(selector as Predicate<T>);\n } else if (isNumber(selector)) {\n index = selector;\n }\n\n if (invalidIndex(index)) {\n return existing as T[];\n }\n\n let value: T = null!;\n // Need to check if the new item value will change the existing item value\n // then, only if it will change it then clone the array and set the item\n const theOperatorOrValue = operatorOrValue as T | StateOperator<T>;\n if (isStateOperator(theOperatorOrValue)) {\n value = theOperatorOrValue(existing[index] as ExistingState<T>);\n } else {\n value = theOperatorOrValue;\n }\n\n // If the value hasn't been mutated\n // then we just return `existing` array\n if (value === existing[index]) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n clone[index] = value as T;\n return clone;\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isPredicate, isNumber, invalidIndex, Predicate } from './utils';\n\n/**\n * @param selector - index or predicate to remove an item from an array by\n */\nexport function removeItem<T>(selector: number | NoInfer<Predicate<T>>): StateOperator<T[]> {\n return function removeItemOperator(existing: ExistingState<T[]>): T[] {\n let index = -1;\n\n if (isPredicate(selector)) {\n index = existing.findIndex(selector);\n } else if (isNumber(selector)) {\n index = selector;\n }\n\n if (invalidIndex(index)) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n clone.splice(index, 1);\n return clone;\n };\n}\n","/**\n * @module\n * @description\n * Entry point for all public APIs of this package.\n */\nexport { append } from './append';\nexport { compose } from './compose';\nexport { iif } from './iif';\nexport { insertItem } from './insert-item';\nexport { patch, ɵPatchSpec } from './patch';\nexport { isStateOperator, isPredicate, Predicate } from './utils';\nexport { updateItem } from './update-item';\nexport { removeItem } from './remove-item';\nexport { ExistingState, NoInfer, StateO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AQ,CAAC,EAAE;YAC7B,KAAK,GAAG,QAAQ,CAAC;AAClB,SAAA;AAED,QAAA,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;AACvB,YAAA,OAAO,QAAe,CAAC;AACxB,SAAA;AAED,QAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;AAC/B,QAAA,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;AACvB,QAAA,OAAO,KAAK,CAAC;AACf,KAAC,CAAC;AACJ;;ACxBA;;;;AAIG;;ACJH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ngxs-store-operators.js","sources":["../../../packages/store/operators/src/append.ts","../../../packages/store/operators/src/compose.ts","../../../packages/store/operators/src/utils.ts","../../../packages/store/operators/src/iif.ts","../../../packages/store/operators/src/insert-item.ts","../../../packages/store/operators/src/patch.ts","../../../packages/store/operators/src/update-item.ts","../../../packages/store/operators/src/remove-item.ts","../../../packages/store/operators/src/index.ts","../../../packages/store/operators/src/ngxs-store-operators.ts"],"sourcesContent":["import { ExistingState, NoInfer, StateOperator } from './types';\n\n/**\n * @param items - Specific items to append to the end of an array\n */\nexport function append<T>(items: NoInfer<T[]>): StateOperator<T[]> {\n return function appendOperator(existing: ExistingState<T[]>): T[] {\n // If `items` is `undefined` or `null` or `[]` but `existing` is provided\n // just return `existing`\n const itemsNotProvidedButExistingIs = (!items || !items.length) && existing;\n if (itemsNotProvidedButExistingIs) {\n return (existing as unknown) as T[];\n }\n\n if (Array.isArray(existing)) {\n return existing.concat((items as unknown) as ExistingState<T[]>);\n }\n\n // For example if some property is added dynamically\n // and didn't exist before thus it's not `ArrayLike`\n return (items as unknown) as T[];\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\n\nexport function compose<T>(...operators: NoInfer<StateOperator<T>[]>): StateOperator<T> {\n return function composeOperator(existing: ExistingState<T>): T {\n return operators.reduce(\n (accumulator, operator) => operator(accumulator as ExistingState<T>),\n existing as T\n );\n };\n}\n","import { StateOperator } from './types';\n\nexport type Predicate<T = any> = (value: T | Readonly<T>) => boolean;\n\nexport function isStateOperator<T>(value: T | StateOperator<T>): value is StateOperator<T> {\n return typeof value === 'function';\n}\n\nexport function isUndefined(value: any): value is undefined {\n return typeof value === 'undefined';\n}\n\nexport function isPredicate<T>(value: Predicate<T> | boolean | number): value is Predicate<T> {\n return typeof value === 'function';\n}\n\nexport function isNumber(value: any): value is number {\n return typeof value === 'number';\n}\n\nexport function invalidIndex(index: number): boolean {\n return Number.isNaN(index) || index === -1;\n}\n\nexport function isNil<T>(value: T | null | undefined): value is null | undefined {\n return value === null || isUndefined(value);\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\n\nimport { isStateOperator, isUndefined, isPredicate, Predicate } from './utils';\n\nfunction retrieveValue<T>(\n operatorOrValue: StateOperator<T> | T,\n existing: ExistingState<T>\n): T {\n // If state operator is a function\n // then call it with an original value\n if (isStateOperator(operatorOrValue)) {\n const value = operatorOrValue(existing);\n return value as T;\n }\n\n // If operator or value was not provided\n // e.g. `elseOperatorOrValue` is `undefined`\n // then we just return an original value\n if (isUndefined(operatorOrValue)) {\n return existing as T;\n }\n\n return operatorOrValue as T;\n}\n\n/**\n * @param condition - Condition can be a plain boolean value or a function,\n * that returns boolean, also this function can take a value as an argument\n * to which this state operator applies\n * @param trueOperatorOrValue - Any value or a state operator\n * @param elseOperatorOrValue - Any value or a state operator\n */\nexport function iif<T>(\n condition: NoInfer<Predicate<T>> | boolean,\n trueOperatorOrValue: NoInfer<StateOperator<T> | T>,\n elseOperatorOrValue?: NoInfer<StateOperator<T> | T>\n): StateOperator<T> {\n return function iifOperator(existing: ExistingState<T>): T {\n // Convert the value to a boolean\n let result = !!condition;\n // but if it is a function then run it to get the result\n if (isPredicate(condition)) {\n result = condition(existing as T);\n }\n\n if (result) {\n return retrieveValue<T>(trueOperatorOrValue as StateOperator<T> | T, existing);\n }\n\n return retrieveValue<T>(elseOperatorOrValue! as StateOperator<T> | T, existing);\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isNil } from './utils';\n\n/**\n * @param value - Value to insert\n * @param [beforePosition] - Specified index to insert value before, optional\n */\nexport function insertItem<T>(value: NoInfer<T>, beforePosition?: number): StateOperator<T[]> {\n return function insertItemOperator(existing: ExistingState<T[]>): T[] {\n // Have to check explicitly for `null` and `undefined`\n // because `value` can be `0`, thus `!value` will return `true`\n if (isNil(value) && existing) {\n return existing as T[];\n }\n\n // Property may be dynamic and might not existed before\n if (!Array.isArray(existing)) {\n return [(value as unknown) as T];\n }\n\n const clone = existing.slice();\n\n let index = 0;\n\n // No need to call `isNumber`\n // as we are checking `> 0` not `>= 0`\n // everything except number will return false here\n if (beforePosition! > 0) {\n index = beforePosition!;\n }\n\n clone.splice(index, 0, (value as unknown) as T);\n return clone;\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isStateOperator } from './utils';\n\ntype NotUndefined<T> = T extends undefined ? never : T;\n\nexport type ɵPatchSpec<T> = { [P in keyof T]?: T[P] | StateOperator<NotUndefined<T[P]>> };\n\nexport function patch<T extends Record<string, any>>(\n patchObject: NoInfer<ɵPatchSpec<T>>\n): StateOperator<T> {\n return function patchStateOperator(existing: ExistingState<T>): T {\n let clone = null;\n for (const k in patchObject) {\n const newValue = patchObject[k];\n const existingPropValue = existing?.[k];\n const newPropValue = isStateOperator(newValue)\n ? newValue(<any>existingPropValue)\n : newValue;\n if (newPropValue !== existingPropValue) {\n if (!clone) {\n clone = { ...(<any>existing) };\n }\n clone[k] = newPropValue;\n }\n }\n return clone || existing;\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\n\nimport { isStateOperator, isPredicate, isNumber, invalidIndex, Predicate } from './utils';\n\n/**\n * @param selector - Index of item in the array or a predicate function\n * that can be provided in `Array.prototype.findIndex`\n * @param operatorOrValue - New value under the `selector` index or a\n * function that can be applied to an existing value\n */\nexport function updateItem<T>(\n selector: number | NoInfer<Predicate<T>>,\n operatorOrValue: NoInfer<T> | NoInfer<StateOperator<T>>\n): StateOperator<T[]> {\n return function updateItemOperator(existing: ExistingState<T[]>): T[] {\n let index = -1;\n\n if (isPredicate(selector)) {\n index = existing.findIndex(selector as Predicate<T>);\n } else if (isNumber(selector)) {\n index = selector;\n }\n\n if (invalidIndex(index)) {\n return existing as T[];\n }\n\n let value: T = null!;\n // Need to check if the new item value will change the existing item value\n // then, only if it will change it then clone the array and set the item\n const theOperatorOrValue = operatorOrValue as T | StateOperator<T>;\n if (isStateOperator(theOperatorOrValue)) {\n value = theOperatorOrValue(existing[index] as ExistingState<T>);\n } else {\n value = theOperatorOrValue;\n }\n\n // If the value hasn't been mutated\n // then we just return `existing` array\n if (value === existing[index]) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n clone[index] = value as T;\n return clone;\n };\n}\n","import { ExistingState, NoInfer, StateOperator } from './types';\nimport { isPredicate, isNumber, invalidIndex, Predicate } from './utils';\n\n/**\n * @param selector - index or predicate to remove an item from an array by\n */\nexport function removeItem<T>(selector: number | NoInfer<Predicate<T>>): StateOperator<T[]> {\n return function removeItemOperator(existing: ExistingState<T[]>): T[] {\n let index = -1;\n\n if (isPredicate(selector)) {\n index = existing.findIndex(selector);\n } else if (isNumber(selector)) {\n index = selector;\n }\n\n if (invalidIndex(index)) {\n return existing as T[];\n }\n\n const clone = existing.slice();\n clone.splice(index, 1);\n return clone;\n };\n}\n","/**\n * @module\n * @description\n * Entry point for all public APIs of this package.\n */\nexport { append } from './append';\nexport { compose } from './compose';\nexport { iif } from './iif';\nexport { insertItem } from './insert-item';\nexport { patch, ɵPatchSpec } from './patch';\nexport { isStateOperator, isPredicate, Predicate } from './utils';\nexport { updateItem } from './update-item';\nexport { removeItem } from './remove-item';\nexport { ExistingState, NoInfer, StateOperator } from './types';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":"AAEA;;AAEG;AACG,SAAU,MAAM,CAAI,KAAmB,EAAA;IAC3C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AAK,CAAC,EAAE;AACvB,YAAA,OAAO,QAAe,CAAC;AACxB,SAAA;AAED,QAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAC;AAC/B,QAAA,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;AACvB,QAAA,OAAO,KAAK,CAAC;AACf,KAAC,CAAC;AACJ;;ACxBA;;;;AAIG;;ACJH;;AAEG;;;;"}
|
package/fesm2015/ngxs-store.js
CHANGED
|
@@ -5,6 +5,7 @@ import { memoize, INITIAL_STATE_TOKEN, NgxsBootstrapper, ɵNGXS_STATE_CONTEXT_FA
|
|
|
5
5
|
import { isPlatformServer } from '@angular/common';
|
|
6
6
|
import { Observable, Subject, BehaviorSubject, of, forkJoin, throwError, EMPTY, from, isObservable } from 'rxjs';
|
|
7
7
|
import { filter, map, share, shareReplay, take, exhaustMap, mergeMap, defaultIfEmpty, catchError, takeUntil, distinctUntilChanged, tap, startWith, pairwise } from 'rxjs/operators';
|
|
8
|
+
import { isStateOperator } from '@ngxs/store/operators';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Returns the type from an action instance/class.
|
|
@@ -1137,43 +1138,21 @@ class StateContextFactory {
|
|
|
1137
1138
|
*/
|
|
1138
1139
|
createStateContext(mappedStore) {
|
|
1139
1140
|
const root = this._internalStateOperations.getRootStateOperations();
|
|
1140
|
-
function getState(currentAppState) {
|
|
1141
|
-
return getValue(currentAppState, mappedStore.path);
|
|
1142
|
-
}
|
|
1143
|
-
function setStateValue(currentAppState, newValue) {
|
|
1144
|
-
const newAppState = setValue(currentAppState, mappedStore.path, newValue);
|
|
1145
|
-
root.setState(newAppState);
|
|
1146
|
-
return newAppState;
|
|
1147
|
-
// In doing this refactoring I noticed that there is a 'bug' where the
|
|
1148
|
-
// application state is returned instead of this state slice.
|
|
1149
|
-
// This has worked this way since the beginning see:
|
|
1150
|
-
// https://github.com/ngxs/store/blame/324c667b4b7debd8eb979006c67ca0ae347d88cd/src/state-factory.ts
|
|
1151
|
-
// This needs to be fixed, but is a 'breaking' change.
|
|
1152
|
-
// I will do this fix in a subsequent PR and we can decide how to handle it.
|
|
1153
|
-
}
|
|
1154
|
-
function setStateFromOperator(currentAppState, stateOperator) {
|
|
1155
|
-
const local = getState(currentAppState);
|
|
1156
|
-
const newValue = stateOperator(local);
|
|
1157
|
-
return setStateValue(currentAppState, newValue);
|
|
1158
|
-
}
|
|
1159
|
-
function isStateOperator(value) {
|
|
1160
|
-
return typeof value === 'function';
|
|
1161
|
-
}
|
|
1162
1141
|
return {
|
|
1163
1142
|
getState() {
|
|
1164
1143
|
const currentAppState = root.getState();
|
|
1165
|
-
return getState(currentAppState);
|
|
1144
|
+
return getState(currentAppState, mappedStore.path);
|
|
1166
1145
|
},
|
|
1167
1146
|
patchState(val) {
|
|
1168
1147
|
const currentAppState = root.getState();
|
|
1169
1148
|
const patchOperator = simplePatch(val);
|
|
1170
|
-
return setStateFromOperator(currentAppState, patchOperator);
|
|
1149
|
+
return setStateFromOperator(root, currentAppState, patchOperator, mappedStore.path);
|
|
1171
1150
|
},
|
|
1172
1151
|
setState(val) {
|
|
1173
1152
|
const currentAppState = root.getState();
|
|
1174
1153
|
return isStateOperator(val)
|
|
1175
|
-
? setStateFromOperator(currentAppState, val)
|
|
1176
|
-
: setStateValue(currentAppState, val);
|
|
1154
|
+
? setStateFromOperator(root, currentAppState, val, mappedStore.path)
|
|
1155
|
+
: setStateValue(root, currentAppState, val, mappedStore.path);
|
|
1177
1156
|
},
|
|
1178
1157
|
dispatch(actions) {
|
|
1179
1158
|
return root.dispatch(actions);
|
|
@@ -1187,31 +1166,48 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.2.17", ngImpo
|
|
|
1187
1166
|
type: Injectable,
|
|
1188
1167
|
args: [{ providedIn: 'root' }]
|
|
1189
1168
|
}], ctorParameters: function () { return [{ type: InternalStateOperations }]; } });
|
|
1169
|
+
function setStateValue(root, currentAppState, newValue, path) {
|
|
1170
|
+
const newAppState = setValue(currentAppState, path, newValue);
|
|
1171
|
+
root.setState(newAppState);
|
|
1172
|
+
return newAppState;
|
|
1173
|
+
// In doing this refactoring I noticed that there is a 'bug' where the
|
|
1174
|
+
// application state is returned instead of this state slice.
|
|
1175
|
+
// This has worked this way since the beginning see:
|
|
1176
|
+
// https://github.com/ngxs/store/blame/324c667b4b7debd8eb979006c67ca0ae347d88cd/src/state-factory.ts
|
|
1177
|
+
// This needs to be fixed, but is a 'breaking' change.
|
|
1178
|
+
// I will do this fix in a subsequent PR and we can decide how to handle it.
|
|
1179
|
+
}
|
|
1180
|
+
function setStateFromOperator(root, currentAppState, stateOperator, path) {
|
|
1181
|
+
const local = getState(currentAppState, path);
|
|
1182
|
+
const newValue = stateOperator(local);
|
|
1183
|
+
return setStateValue(root, currentAppState, newValue, path);
|
|
1184
|
+
}
|
|
1185
|
+
function getState(currentAppState, path) {
|
|
1186
|
+
return getValue(currentAppState, path);
|
|
1187
|
+
}
|
|
1190
1188
|
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
}
|
|
1196
|
-
else if (!this.stateNameRegex.test(name)) {
|
|
1197
|
-
throwStateNameError(name);
|
|
1198
|
-
}
|
|
1189
|
+
const stateNameRegex = new RegExp('^[a-zA-Z0-9_]+$');
|
|
1190
|
+
function ensureStateNameIsValid(name) {
|
|
1191
|
+
if (!name) {
|
|
1192
|
+
throwStateNamePropertyError();
|
|
1199
1193
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
if (existingState && existingState !== state) {
|
|
1203
|
-
throwStateUniqueError(stateName, state.name, existingState.name);
|
|
1204
|
-
}
|
|
1194
|
+
else if (!stateNameRegex.test(name)) {
|
|
1195
|
+
throwStateNameError(name);
|
|
1205
1196
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
});
|
|
1197
|
+
}
|
|
1198
|
+
function ensureStateNameIsUnique(stateName, state, statesByName) {
|
|
1199
|
+
const existingState = statesByName[stateName];
|
|
1200
|
+
if (existingState && existingState !== state) {
|
|
1201
|
+
throwStateUniqueError(stateName, state.name, existingState.name);
|
|
1212
1202
|
}
|
|
1213
1203
|
}
|
|
1214
|
-
|
|
1204
|
+
function ensureStatesAreDecorated(stateClasses) {
|
|
1205
|
+
stateClasses.forEach((stateClass) => {
|
|
1206
|
+
if (!getStoreMetadata$1(stateClass)) {
|
|
1207
|
+
throwStateDecoratorError(stateClass.name);
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1215
1211
|
|
|
1216
1212
|
/**
|
|
1217
1213
|
* All provided or injected tokens must have `@Injectable` decorator
|
|
@@ -1241,11 +1237,8 @@ function jit_hasInjectableAnnotation(stateClass) {
|
|
|
1241
1237
|
* Init action
|
|
1242
1238
|
*/
|
|
1243
1239
|
class InitState {
|
|
1244
|
-
static get type() {
|
|
1245
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
1246
|
-
return '@@INIT';
|
|
1247
|
-
}
|
|
1248
1240
|
}
|
|
1241
|
+
InitState.type = '@@INIT';
|
|
1249
1242
|
/**
|
|
1250
1243
|
* Update action
|
|
1251
1244
|
*/
|
|
@@ -1253,11 +1246,8 @@ class UpdateState {
|
|
|
1253
1246
|
constructor(addedStates) {
|
|
1254
1247
|
this.addedStates = addedStates;
|
|
1255
1248
|
}
|
|
1256
|
-
static get type() {
|
|
1257
|
-
// NOTE: Not necessary to declare the type in this way in your code. See https://github.com/ngxs/store/pull/644#issuecomment-436003138
|
|
1258
|
-
return '@@UPDATE_STATE';
|
|
1259
|
-
}
|
|
1260
1249
|
}
|
|
1250
|
+
UpdateState.type = '@@UPDATE_STATE';
|
|
1261
1251
|
|
|
1262
1252
|
const NGXS_DEVELOPMENT_OPTIONS = new InjectionToken('NGXS_DEVELOPMENT_OPTIONS', {
|
|
1263
1253
|
providedIn: 'root',
|
|
@@ -1372,8 +1362,8 @@ class StateFactory {
|
|
|
1372
1362
|
get statePaths() {
|
|
1373
1363
|
return this._parentFactory ? this._parentFactory.statePaths : this._statePaths;
|
|
1374
1364
|
}
|
|
1375
|
-
static
|
|
1376
|
-
let value =
|
|
1365
|
+
static _cloneDefaults(defaults) {
|
|
1366
|
+
let value = defaults;
|
|
1377
1367
|
if (Array.isArray(defaults)) {
|
|
1378
1368
|
value = defaults.slice();
|
|
1379
1369
|
}
|
|
@@ -1383,9 +1373,6 @@ class StateFactory {
|
|
|
1383
1373
|
else if (defaults === undefined) {
|
|
1384
1374
|
value = {};
|
|
1385
1375
|
}
|
|
1386
|
-
else {
|
|
1387
|
-
value = defaults;
|
|
1388
|
-
}
|
|
1389
1376
|
return value;
|
|
1390
1377
|
}
|
|
1391
1378
|
ngOnDestroy() {
|
|
@@ -1397,7 +1384,7 @@ class StateFactory {
|
|
|
1397
1384
|
*/
|
|
1398
1385
|
add(stateClasses) {
|
|
1399
1386
|
if (NG_DEV_MODE) {
|
|
1400
|
-
|
|
1387
|
+
ensureStatesAreDecorated(stateClasses);
|
|
1401
1388
|
}
|
|
1402
1389
|
const { newStates } = this.addToStatesMap(stateClasses);
|
|
1403
1390
|
if (!newStates.length)
|
|
@@ -1416,7 +1403,7 @@ class StateFactory {
|
|
|
1416
1403
|
// `State` decorator. This check is moved here because the `ɵprov` property
|
|
1417
1404
|
// will not exist on the class in JIT mode (because it's set asynchronously
|
|
1418
1405
|
// during JIT compilation through `Object.defineProperty`).
|
|
1419
|
-
if (
|
|
1406
|
+
if (NG_DEV_MODE) {
|
|
1420
1407
|
ensureStateClassIsInjectable(stateClass);
|
|
1421
1408
|
}
|
|
1422
1409
|
const stateMap = {
|
|
@@ -1425,7 +1412,7 @@ class StateFactory {
|
|
|
1425
1412
|
isInitialised: false,
|
|
1426
1413
|
actions: meta.actions,
|
|
1427
1414
|
instance: this._injector.get(stateClass),
|
|
1428
|
-
defaults: StateFactory.
|
|
1415
|
+
defaults: StateFactory._cloneDefaults(meta.defaults)
|
|
1429
1416
|
};
|
|
1430
1417
|
// ensure our store hasn't already been added
|
|
1431
1418
|
// but don't throw since it could be lazy
|
|
@@ -1538,7 +1525,7 @@ class StateFactory {
|
|
|
1538
1525
|
for (const stateClass of stateClasses) {
|
|
1539
1526
|
const stateName = getStoreMetadata$1(stateClass).name;
|
|
1540
1527
|
if (NG_DEV_MODE) {
|
|
1541
|
-
|
|
1528
|
+
ensureStateNameIsUnique(stateName, stateClass, statesMap);
|
|
1542
1529
|
}
|
|
1543
1530
|
const unmountedState = !statesMap[stateName];
|
|
1544
1531
|
if (unmountedState) {
|
|
@@ -1998,36 +1985,34 @@ function Action(actions, options) {
|
|
|
1998
1985
|
* Decorates a class with ngxs state information.
|
|
1999
1986
|
*/
|
|
2000
1987
|
function State(options) {
|
|
2001
|
-
function getStateOptions(inheritedStateClass) {
|
|
2002
|
-
const inheritanceOptions = inheritedStateClass[META_OPTIONS_KEY] || {};
|
|
2003
|
-
return Object.assign(Object.assign({}, inheritanceOptions), options);
|
|
2004
|
-
}
|
|
2005
|
-
function mutateMetaData(params) {
|
|
2006
|
-
const { meta, inheritedStateClass, optionsWithInheritance } = params;
|
|
2007
|
-
const { children, defaults, name } = optionsWithInheritance;
|
|
2008
|
-
const stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
|
|
2009
|
-
// Caretaker note: we have still left the `typeof` condition in order to avoid
|
|
2010
|
-
// creating a breaking change for projects that still use the View Engine.
|
|
2011
|
-
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2012
|
-
StoreValidators.checkThatStateIsNamedCorrectly(stateName);
|
|
2013
|
-
}
|
|
2014
|
-
if (inheritedStateClass.hasOwnProperty(META_KEY)) {
|
|
2015
|
-
const inheritedMeta = inheritedStateClass[META_KEY] || {};
|
|
2016
|
-
meta.actions = Object.assign(Object.assign({}, meta.actions), inheritedMeta.actions);
|
|
2017
|
-
}
|
|
2018
|
-
meta.children = children;
|
|
2019
|
-
meta.defaults = defaults;
|
|
2020
|
-
meta.name = stateName;
|
|
2021
|
-
}
|
|
2022
1988
|
return (target) => {
|
|
2023
1989
|
const stateClass = target;
|
|
2024
1990
|
const meta = ensureStoreMetadata$1(stateClass);
|
|
2025
1991
|
const inheritedStateClass = Object.getPrototypeOf(stateClass);
|
|
2026
|
-
const optionsWithInheritance = getStateOptions(inheritedStateClass);
|
|
1992
|
+
const optionsWithInheritance = getStateOptions(inheritedStateClass, options);
|
|
2027
1993
|
mutateMetaData({ meta, inheritedStateClass, optionsWithInheritance });
|
|
2028
1994
|
stateClass[META_OPTIONS_KEY] = optionsWithInheritance;
|
|
2029
1995
|
};
|
|
2030
1996
|
}
|
|
1997
|
+
function getStateOptions(inheritedStateClass, options) {
|
|
1998
|
+
const inheritanceOptions = inheritedStateClass[META_OPTIONS_KEY] || {};
|
|
1999
|
+
return Object.assign(Object.assign({}, inheritanceOptions), options);
|
|
2000
|
+
}
|
|
2001
|
+
function mutateMetaData(params) {
|
|
2002
|
+
const { meta, inheritedStateClass, optionsWithInheritance } = params;
|
|
2003
|
+
const { children, defaults, name } = optionsWithInheritance;
|
|
2004
|
+
const stateName = typeof name === 'string' ? name : (name && name.getName()) || null;
|
|
2005
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2006
|
+
ensureStateNameIsValid(stateName);
|
|
2007
|
+
}
|
|
2008
|
+
if (inheritedStateClass.hasOwnProperty(META_KEY)) {
|
|
2009
|
+
const inheritedMeta = inheritedStateClass[META_KEY] || {};
|
|
2010
|
+
meta.actions = Object.assign(Object.assign({}, meta.actions), inheritedMeta.actions);
|
|
2011
|
+
}
|
|
2012
|
+
meta.children = children;
|
|
2013
|
+
meta.defaults = defaults;
|
|
2014
|
+
meta.name = stateName;
|
|
2015
|
+
}
|
|
2031
2016
|
|
|
2032
2017
|
const DOLLAR_CHAR_CODE = 36;
|
|
2033
2018
|
function createSelectObservable(selector) {
|
|
@@ -2233,12 +2218,14 @@ function ensureValueProvided(value, context = {}) {
|
|
|
2233
2218
|
function createModelSelector(selectorMap) {
|
|
2234
2219
|
const selectorKeys = Object.keys(selectorMap);
|
|
2235
2220
|
const selectors = Object.values(selectorMap);
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2221
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2222
|
+
ensureValidSelectorMap({
|
|
2223
|
+
prefix: '[createModelSelector]',
|
|
2224
|
+
selectorMap,
|
|
2225
|
+
selectorKeys,
|
|
2226
|
+
selectors
|
|
2227
|
+
});
|
|
2228
|
+
}
|
|
2242
2229
|
return createSelector(selectors, (...args) => {
|
|
2243
2230
|
return selectorKeys.reduce((obj, key, index) => {
|
|
2244
2231
|
obj[key] = args[index];
|
|
@@ -2246,20 +2233,22 @@ function createModelSelector(selectorMap) {
|
|
|
2246
2233
|
}, {});
|
|
2247
2234
|
});
|
|
2248
2235
|
}
|
|
2249
|
-
function ensureValidSelectorMap({ prefix, selectorMap, selectorKeys, selectors
|
|
2236
|
+
function ensureValidSelectorMap({ prefix, selectorMap, selectorKeys, selectors }) {
|
|
2250
2237
|
ensureValueProvided(selectorMap, { prefix, noun: 'selector map' });
|
|
2251
2238
|
ensureValueProvided(typeof selectorMap === 'object', { prefix, noun: 'valid selector map' });
|
|
2252
2239
|
ensureValueProvided(selectorKeys.length, { prefix, noun: 'non-empty selector map' });
|
|
2253
2240
|
selectors.forEach((selector, index) => ensureValidSelector(selector, {
|
|
2254
2241
|
prefix,
|
|
2255
|
-
noun: `selector for the '${selectorKeys[index]}' property
|
|
2242
|
+
noun: `selector for the '${selectorKeys[index]}' property`
|
|
2256
2243
|
}));
|
|
2257
2244
|
}
|
|
2258
2245
|
|
|
2259
2246
|
function createPickSelector(selector, keys) {
|
|
2260
|
-
|
|
2247
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2248
|
+
ensureValidSelector(selector, { prefix: '[createPickSelector]' });
|
|
2249
|
+
}
|
|
2261
2250
|
const validKeys = keys.filter(Boolean);
|
|
2262
|
-
const selectors = validKeys.map(
|
|
2251
|
+
const selectors = validKeys.map(key => createSelector([selector], (s) => s[key]));
|
|
2263
2252
|
return createSelector([...selectors], (...props) => {
|
|
2264
2253
|
return validKeys.reduce((acc, key, index) => {
|
|
2265
2254
|
acc[key] = props[index];
|
|
@@ -2269,10 +2258,12 @@ function createPickSelector(selector, keys) {
|
|
|
2269
2258
|
}
|
|
2270
2259
|
|
|
2271
2260
|
function createPropertySelectors(parentSelector) {
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2261
|
+
if (typeof ngDevMode === 'undefined' || ngDevMode) {
|
|
2262
|
+
ensureValidSelector(parentSelector, {
|
|
2263
|
+
prefix: '[createPropertySelectors]',
|
|
2264
|
+
noun: 'parent selector'
|
|
2265
|
+
});
|
|
2266
|
+
}
|
|
2276
2267
|
const cache = {};
|
|
2277
2268
|
return new Proxy({}, {
|
|
2278
2269
|
get(_target, prop) {
|
|
@@ -2280,7 +2271,7 @@ function createPropertySelectors(parentSelector) {
|
|
|
2280
2271
|
createSelector([parentSelector], (s) => s === null || s === void 0 ? void 0 : s[prop]);
|
|
2281
2272
|
cache[prop] = selector;
|
|
2282
2273
|
return selector;
|
|
2283
|
-
}
|
|
2274
|
+
}
|
|
2284
2275
|
});
|
|
2285
2276
|
}
|
|
2286
2277
|
|