@ngxs/store 3.7.6-dev.master-2df2f65 → 3.7.6-dev.master-7c829a7
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-operators.umd.js +11 -11
- package/bundles/ngxs-store-operators.umd.js.map +1 -1
- package/bundles/ngxs-store-operators.umd.min.js.map +1 -1
- package/bundles/ngxs-store.umd.js +1 -1
- package/bundles/ngxs-store.umd.js.map +1 -1
- package/bundles/ngxs-store.umd.min.js.map +1 -1
- package/esm2015/operators/append.js +2 -2
- package/esm2015/operators/compose.js +2 -2
- package/esm2015/operators/iif.js +7 -7
- package/esm2015/operators/index.js +1 -1
- package/esm2015/operators/insert-item.js +1 -1
- package/esm2015/operators/patch.js +4 -4
- package/esm2015/operators/remove-item.js +1 -1
- package/esm2015/operators/types.js +5 -0
- package/esm2015/operators/update-item.js +1 -1
- package/esm2015/operators/utils.js +1 -1
- package/esm2015/src/internal/state-context-factory.js +2 -2
- package/esm2015/src/internal/state-operators.js +1 -1
- package/esm2015/src/symbols.js +1 -1
- package/esm5/operators/append.js +2 -2
- package/esm5/operators/compose.js +2 -2
- package/esm5/operators/iif.js +7 -7
- package/esm5/operators/index.js +1 -1
- package/esm5/operators/insert-item.js +1 -1
- package/esm5/operators/patch.js +4 -4
- package/esm5/operators/remove-item.js +1 -1
- package/esm5/operators/types.js +5 -0
- package/esm5/operators/update-item.js +1 -1
- package/esm5/operators/utils.js +1 -1
- package/esm5/src/internal/state-context-factory.js +2 -2
- package/esm5/src/internal/state-operators.js +1 -1
- package/esm5/src/symbols.js +1 -1
- package/fesm2015/ngxs-store-operators.js +11 -11
- package/fesm2015/ngxs-store-operators.js.map +1 -1
- package/fesm2015/ngxs-store.js +1 -1
- package/fesm2015/ngxs-store.js.map +1 -1
- package/fesm5/ngxs-store-operators.js +11 -11
- package/fesm5/ngxs-store-operators.js.map +1 -1
- package/fesm5/ngxs-store.js +1 -1
- package/fesm5/ngxs-store.js.map +1 -1
- package/ngxs-store.metadata.json +1 -1
- package/operators/append.d.ts +2 -3
- package/operators/compose.d.ts +1 -2
- package/operators/iif.d.ts +3 -4
- package/operators/index.d.ts +2 -1
- package/operators/insert-item.d.ts +2 -3
- package/operators/ngxs-store-operators.metadata.json +1 -1
- package/operators/patch.d.ts +5 -4
- package/operators/remove-item.d.ts +3 -4
- package/operators/types.d.ts +53 -0
- package/operators/update-item.d.ts +3 -4
- package/operators/utils.d.ts +2 -4
- package/package.json +1 -1
- package/src/internal/state-operators.d.ts +1 -1
- package/src/symbols.d.ts +3 -2
- package/esm2015/operators/internals.js +0 -5
- package/esm5/operators/internals.js +0 -5
- package/operators/internals.d.ts +0 -2
|
@@ -20,7 +20,7 @@ function append(items) {
|
|
|
20
20
|
/** @type {?} */
|
|
21
21
|
var itemsNotProvidedButExistingIs = (!items || !items.length) && existing;
|
|
22
22
|
if (itemsNotProvidedButExistingIs) {
|
|
23
|
-
return (/** @type {?} */ (existing));
|
|
23
|
+
return (/** @type {?} */ (((/** @type {?} */ (existing)))));
|
|
24
24
|
}
|
|
25
25
|
if (Array.isArray(existing)) {
|
|
26
26
|
return existing.concat((/** @type {?} */ (((/** @type {?} */ (items))))));
|
|
@@ -55,7 +55,7 @@ function compose() {
|
|
|
55
55
|
* @param {?} operator
|
|
56
56
|
* @return {?}
|
|
57
57
|
*/
|
|
58
|
-
function (accumulator, operator) { return operator(accumulator); }), existing);
|
|
58
|
+
function (accumulator, operator) { return operator((/** @type {?} */ (accumulator))); }), (/** @type {?} */ (existing)));
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -116,7 +116,7 @@ function isNil(value) {
|
|
|
116
116
|
/**
|
|
117
117
|
* @template T
|
|
118
118
|
* @param {?} operatorOrValue
|
|
119
|
-
* @param {
|
|
119
|
+
* @param {?} existing
|
|
120
120
|
* @return {?}
|
|
121
121
|
*/
|
|
122
122
|
function retrieveValue(operatorOrValue, existing) {
|
|
@@ -124,14 +124,14 @@ function retrieveValue(operatorOrValue, existing) {
|
|
|
124
124
|
// then call it with an original value
|
|
125
125
|
if (isStateOperator(operatorOrValue)) {
|
|
126
126
|
/** @type {?} */
|
|
127
|
-
var value = operatorOrValue(
|
|
127
|
+
var value = operatorOrValue(existing);
|
|
128
128
|
return (/** @type {?} */ (value));
|
|
129
129
|
}
|
|
130
130
|
// If operator or value was not provided
|
|
131
131
|
// e.g. `elseOperatorOrValue` is `undefined`
|
|
132
132
|
// then we just return an original value
|
|
133
133
|
if (isUndefined(operatorOrValue)) {
|
|
134
|
-
return (/** @type {?} */ (
|
|
134
|
+
return (/** @type {?} */ (existing));
|
|
135
135
|
}
|
|
136
136
|
return (/** @type {?} */ (operatorOrValue));
|
|
137
137
|
}
|
|
@@ -155,12 +155,12 @@ function iif(condition, trueOperatorOrValue, elseOperatorOrValue) {
|
|
|
155
155
|
var result = !!condition;
|
|
156
156
|
// but if it is a function then run it to get the result
|
|
157
157
|
if (isPredicate(condition)) {
|
|
158
|
-
result = condition(existing);
|
|
158
|
+
result = condition((/** @type {?} */ (existing)));
|
|
159
159
|
}
|
|
160
160
|
if (result) {
|
|
161
|
-
return retrieveValue(
|
|
161
|
+
return retrieveValue((/** @type {?} */ (trueOperatorOrValue)), existing);
|
|
162
162
|
}
|
|
163
|
-
return retrieveValue((/** @type {?} */ (
|
|
163
|
+
return retrieveValue((/** @type {?} */ ((/** @type {?} */ (elseOperatorOrValue)))), existing);
|
|
164
164
|
});
|
|
165
165
|
}
|
|
166
166
|
|
|
@@ -214,7 +214,7 @@ function insertItem(value, beforePosition) {
|
|
|
214
214
|
* @return {?}
|
|
215
215
|
*/
|
|
216
216
|
function patch(patchObject) {
|
|
217
|
-
return (/**
|
|
217
|
+
return (/**
|
|
218
218
|
* @param {?} existing
|
|
219
219
|
* @return {?}
|
|
220
220
|
*/
|
|
@@ -225,7 +225,7 @@ function patch(patchObject) {
|
|
|
225
225
|
/** @type {?} */
|
|
226
226
|
var newValue = patchObject[k];
|
|
227
227
|
/** @type {?} */
|
|
228
|
-
var existingPropValue = existing[
|
|
228
|
+
var existingPropValue = existing[k];
|
|
229
229
|
/** @type {?} */
|
|
230
230
|
var newPropValue = isStateOperator(newValue)
|
|
231
231
|
? newValue((/** @type {?} */ (existingPropValue)))
|
|
@@ -238,7 +238,7 @@ function patch(patchObject) {
|
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
return clone || existing;
|
|
241
|
-
})
|
|
241
|
+
});
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngxs-store-operators.js","sources":["ng://@ngxs/store/operators/append.ts","ng://@ngxs/store/operators/compose.ts","ng://@ngxs/store/operators/utils.ts","ng://@ngxs/store/operators/iif.ts","ng://@ngxs/store/operators/insert-item.ts","ng://@ngxs/store/operators/patch.ts","ng://@ngxs/store/operators/update-item.ts","ng://@ngxs/store/operators/remove-item.ts"],"sourcesContent":["import { StateOperator } from '@ngxs/store';\nimport { RepairType, NoInfer } from './utils';\n\n/**\n * @param items - Specific items to append to the end of an array\n */\nexport function append<T>(items: NoInfer<T>[]): StateOperator<RepairType<T>[]> {\n return function appendOperator(existing: Readonly<RepairType<T>[]>): RepairType<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 RepairType<T>[];\n }\n\n if (Array.isArray(existing)) {\n return existing.concat((items as unknown) as RepairType<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 RepairType<T>[];\n };\n}\n","import { StateOperator } from '@ngxs/store';\nimport { NoInfer } from './utils';\n\nexport function compose<T>(...operators: NoInfer<StateOperator<T>[]>): StateOperator<T> {\n return function composeOperator(existing: Readonly<T>): T {\n return operators.reduce((accumulator, operator) => operator(accumulator), existing);\n };\n}\n","import { StateOperator } from '@ngxs/store';\n\nimport { Predicate } from './internals';\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\nexport type RepairType<T> = T extends true ? boolean : T extends false ? boolean : T;\n\nexport type NoInfer<T> = T extends infer S ? S : never;\n","import { StateOperator } from '@ngxs/store';\n\nimport { isStateOperator, isUndefined, isPredicate, RepairType, NoInfer } from './utils';\nimport { Predicate } from './internals';\n\nfunction retrieveValue<T>(\n operatorOrValue: StateOperator<T> | T,\n existing?: Readonly<RepairType<T>>\n): RepairType<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! as Readonly<T>);\n return value as RepairType<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 (<any>existing)! as RepairType<T>;\n }\n\n return operatorOrValue as RepairType<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<RepairType<T>> {\n return function iifOperator(existing: Readonly<RepairType<T>>): RepairType<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);\n }\n\n if (result) {\n return retrieveValue<T>(trueOperatorOrValue, existing as RepairType<T>);\n }\n\n return retrieveValue<T>(elseOperatorOrValue!, existing as RepairType<T>);\n };\n}\n","import { StateOperator } from '@ngxs/store';\nimport { isNil, RepairType, NoInfer } 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>(\n value: NoInfer<T>,\n beforePosition?: number\n): StateOperator<RepairType<T>[]> {\n return function insertItemOperator(existing: Readonly<RepairType<T>[]>): RepairType<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 RepairType<T>[];\n }\n\n // Property may be dynamic and might not existed before\n if (!Array.isArray(existing)) {\n return [(value as unknown) as RepairType<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 RepairType<T>);\n return clone;\n };\n}\n","import { StateOperator } from '@ngxs/store';\nimport { isStateOperator, NoInfer } from './utils';\n\nexport type PatchSpec<T> = { [P in keyof T]?: T[P] | StateOperator<NonNullable<T[P]>> };\n\ntype PatchValues<T> = {\n readonly [P in keyof T]?: T[P] extends (...args: any[]) => infer R ? R : T[P];\n};\n\nexport function patch<T>(patchObject: NoInfer<PatchSpec<T>>): StateOperator<NonNullable<T>> {\n return (function patchStateOperator(existing: Readonly<PatchValues<T>>): NonNullable<T> {\n let clone = null;\n for (const k in patchObject) {\n const newValue = patchObject[k];\n const existingPropValue = existing[k as Extract<keyof T, string>];\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 } as unknown) as StateOperator<NonNullable<T>>;\n}\n","import { StateOperator } from '@ngxs/store';\n\nimport {\n isStateOperator,\n isPredicate,\n isNumber,\n invalidIndex,\n RepairType,\n NoInfer\n} from './utils';\nimport { Predicate } from './internals';\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<RepairType<T>[]> {\n return function updateItemOperator(existing: Readonly<RepairType<T>[]>): RepairType<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 RepairType<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 Readonly<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 RepairType<T>[];\n }\n\n const clone = existing.slice();\n clone[index] = value as RepairType<T>;\n return clone;\n };\n}\n","import { StateOperator } from '@ngxs/store';\nimport { Predicate } from './internals';\nimport { isPredicate, isNumber, invalidIndex, RepairType } from './utils';\n\n/**\n * @param selector - index or predicate to remove an item from an array by\n */\nexport function removeItem<T>(\n selector: number | Predicate<T>\n): StateOperator<RepairType<T>[]> {\n return function removeItemOperator(existing: Readonly<RepairType<T>[]>): RepairType<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 RepairType<T>[];\n }\n\n const clone = existing.slice();\n clone.splice(index, 1);\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AAwB;QAClE,IAAI,eAAe,CAAC,kBAAkB,CAAC,EAAE;YACvC,KAAK,GAAG,kBAAkB,oBAAC,QAAQ,CAAC,KAAK,CAAC,GAAgB,CAAC;SAC5D;aAAM;YACL,KAAK,GAAG,kBAAkB,CAAC;SAC5B;;;QAID,IAAI,KAAK,KAAK,QAAQ,CAAC,KAAK,CAAC,EAAE;YAC7B,0BAAO,QAAQ,GAAoB;SACpC;;YAEK,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE;QAC9B,KAAK,CAAC,KAAK,CAAC,sBAAG,KAAK,EAAiB,CAAC;QACtC,OAAO,KAAK,CAAC;KACd,EAAC;CACH;;;;;;ACrDD;;;;;AAKA,SAAgB,UAAU,CACxB,QAA+B;IAE/B;;;;IAAO,SAAS,kBAAkB,CAAC,QAAmC;;YAChE,KAAK,GAAG,CAAC,CAAC;QAEd,IAAI,WAAW,CAAC,QAAQ,CAAC,EAAE;YACzB,KAAK,GAAG,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;SACtC;aAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE;YAC7B,KAAK,GAAG,QAAQ,CAAC;SAClB;QAED,IAAI,YAAY,CAAC,KAAK,CAAC,EAAE;YACvB,0BAAO,QAAQ,GAAoB;SACpC;;YAEK,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE;QAC9B,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QACvB,OAAO,KAAK,CAAC;KACd,EAAC;CACH;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"ngxs-store-operators.js","sources":["ng://@ngxs/store/operators/append.ts","ng://@ngxs/store/operators/compose.ts","ng://@ngxs/store/operators/utils.ts","ng://@ngxs/store/operators/iif.ts","ng://@ngxs/store/operators/insert-item.ts","ng://@ngxs/store/operators/patch.ts","ng://@ngxs/store/operators/update-item.ts","ng://@ngxs/store/operators/remove-item.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"],"names":[],"mappings":";;;;;;;;;;;AAKA,SAAgB,MAAM,CAAI,KAAmB;IAC3C;;;;IAAO,SAAS,cAAc,CAAC,QAA4B;;;;YAGnD,6BAA6B,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ;QAC3E,IAAI,6BAA6B,EAAE;YACjC,8CAAQ,QAAQ,MAAoB;SACrC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC3B,OAAO,QAAQ,CAAC,MAAM,wCAAE,KAAK,MAAmC,CAAC;SAClE;;;QAID,8CAAQ,KAAK,MAAoB;KAClC,EAAC;CACH;;;;;;;;;;;ACpBD,SAAgB,OAAO;IAAI,mBAAyC;SAAzC,UAAyC,EAAzC,qBAAyC,EAAzC,IAAyC;QAAzC,8BAAyC;;IAClE;;;;IAAO,SAAS,eAAe,CAAC,QAA0B;QACxD,OAAO,SAAS,CAAC,MAAM;;;;;QACrB,UAAC,WAAW,EAAE,QAAQ,IAAK,OAAA,QAAQ,oBAAC,WAAW,GAAqB,GAAA,sBACpE,QAAQ,GACT,CAAC;KACH,EAAC;CACH;;;;;;;;;;;ACLD,SAAgB,eAAe,CAAI,KAA2B;IAC5D,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;CACpC;;;;;AAED,SAAgB,WAAW,CAAC,KAAU;IACpC,OAAO,OAAO,KAAK,KAAK,WAAW,CAAC;CACrC;;;;;;AAED,SAAgB,WAAW,CAAI,KAAsC;IACnE,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;CACpC;;;;;AAED,SAAgB,QAAQ,CAAC,KAAU;IACjC,OAAO,OAAO,KAAK,K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2396
|
var local = getState(currentAppState);
|
|
2397
2397
|
/** @type {?} */
|
|
2398
|
-
var newValue = stateOperator(local);
|
|
2398
|
+
var newValue = stateOperator((/** @type {?} */ (local)));
|
|
2399
2399
|
return setStateValue(currentAppState, newValue);
|
|
2400
2400
|
}
|
|
2401
2401
|
/**
|