@ngxs/store 3.7.6 → 3.8.0-dev.master-c341c15
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 +409 -420
- package/bundles/ngxs-store-internals-testing.umd.js.map +1 -1
- package/bundles/ngxs-store-internals.umd.js +48 -117
- package/bundles/ngxs-store-internals.umd.js.map +1 -1
- package/bundles/ngxs-store-operators.umd.js +62 -402
- package/bundles/ngxs-store-operators.umd.js.map +1 -1
- package/bundles/ngxs-store.umd.js +1296 -3219
- package/bundles/ngxs-store.umd.js.map +1 -1
- package/esm2015/index.js +7 -7
- package/esm2015/internals/angular.js +1 -8
- package/esm2015/internals/index.js +2 -6
- package/esm2015/internals/initial-state.js +1 -21
- package/esm2015/internals/internal-tokens.js +4 -15
- package/esm2015/internals/memoize.js +8 -33
- package/esm2015/internals/ngxs-bootstrapper.js +7 -20
- package/esm2015/internals/ngxs-store-internals.js +2 -6
- package/esm2015/internals/src/symbols.js +2 -14
- package/esm2015/internals/symbols.js +2 -14
- package/esm2015/internals/testing/fresh-platform.js +13 -53
- package/esm2015/internals/testing/helpers/ngxs-test.component.js +11 -17
- package/esm2015/internals/testing/helpers/ngxs-test.module.js +13 -16
- package/esm2015/internals/testing/index.js +1 -5
- package/esm2015/internals/testing/ngxs-store-internals-testing.js +2 -6
- package/esm2015/internals/testing/ngxs.setup.js +1 -31
- package/esm2015/internals/testing/skip-console-logging.js +7 -42
- package/esm2015/internals/testing/symbol.js +2 -29
- package/esm2015/ngxs-store.js +2 -22
- package/esm2015/operators/append.js +7 -18
- package/esm2015/operators/compose.js +4 -22
- package/esm2015/operators/iif.js +12 -30
- package/esm2015/operators/index.js +2 -6
- package/esm2015/operators/insert-item.js +10 -22
- package/esm2015/operators/ngxs-store-operators.js +2 -6
- package/esm2015/operators/patch.js +5 -23
- package/esm2015/operators/remove-item.js +5 -17
- package/esm2015/operators/types.js +2 -0
- package/esm2015/operators/update-item.js +13 -25
- package/esm2015/operators/utils.js +1 -32
- package/esm2015/src/actions/actions.js +1 -18
- package/esm2015/src/actions/symbols.js +2 -39
- package/esm2015/src/actions-stream.js +20 -122
- package/esm2015/src/configs/messages.config.js +1 -44
- package/esm2015/src/decorators/action.js +3 -18
- package/esm2015/src/decorators/select/select-factory.js +10 -27
- package/esm2015/src/decorators/select/select.js +3 -22
- package/esm2015/src/decorators/select/symbols.js +4 -25
- package/esm2015/src/decorators/selector/selector.js +11 -38
- package/esm2015/src/decorators/selector/symbols.js +2 -5
- package/esm2015/src/decorators/selector-options.js +6 -19
- package/esm2015/src/decorators/state.js +5 -44
- package/esm2015/src/dev-features/ngxs-development.module.js +22 -0
- package/esm2015/src/dev-features/ngxs-unhandled-actions-logger.js +46 -0
- package/esm2015/src/dev-features/symbols.js +6 -0
- package/esm2015/src/execution/dispatch-outside-zone-ngxs-execution-strategy.js +10 -56
- package/esm2015/src/execution/internal-ngxs-execution-strategy.js +10 -32
- package/esm2015/src/execution/noop-ngxs-execution-strategy.js +7 -19
- package/esm2015/src/execution/symbols.js +3 -32
- package/esm2015/src/internal/custom-rxjs-subjects.js +81 -0
- package/esm2015/src/internal/dispatcher.js +26 -121
- package/esm2015/src/internal/error-handler.js +18 -72
- package/esm2015/src/internal/internals.js +24 -244
- package/esm2015/src/internal/lifecycle-state-manager.js +19 -117
- package/esm2015/src/internal/state-context-factory.js +8 -66
- package/esm2015/src/internal/state-factory.js +60 -227
- package/esm2015/src/internal/state-operations.js +19 -80
- package/esm2015/src/internal/state-operators.js +15 -28
- package/esm2015/src/internal/state-stream.js +9 -15
- package/esm2015/src/ivy/ivy-enabled-in-dev-mode.js +7 -17
- package/esm2015/src/module.js +12 -47
- package/esm2015/src/modules/ngxs-feature.module.js +18 -36
- package/esm2015/src/modules/ngxs-root.module.js +18 -26
- package/esm2015/src/operators/leave-ngxs.js +8 -43
- package/esm2015/src/operators/of-action.js +16 -105
- package/esm2015/src/plugin-manager.js +17 -50
- package/esm2015/src/plugin_api.js +1 -5
- package/esm2015/src/private_api.js +3 -0
- package/esm2015/src/public_api.js +7 -9
- package/esm2015/src/public_to_deprecate.js +1 -51
- package/esm2015/src/selectors/create-model-selector.js +28 -0
- package/esm2015/src/selectors/create-pick-selector.js +14 -0
- package/esm2015/src/selectors/create-property-selectors.js +18 -0
- package/esm2015/src/selectors/create-selector.js +9 -0
- package/esm2015/src/selectors/index.js +6 -0
- package/esm2015/src/selectors/selector-checks.util.js +18 -0
- package/esm2015/src/selectors/selector-metadata.js +30 -0
- package/esm2015/src/selectors/selector-models.js +2 -0
- package/esm2015/src/selectors/selector-types.util.js +2 -0
- package/esm2015/src/selectors/selector-utils.js +74 -0
- package/esm2015/src/state-token/state-token.js +4 -32
- package/esm2015/src/state-token/symbols.js +2 -5
- package/esm2015/src/store.js +24 -108
- package/esm2015/src/symbols.js +7 -177
- package/esm2015/src/utils/compose.js +5 -23
- package/esm2015/src/utils/freeze.js +5 -20
- package/esm2015/src/utils/store-validators.js +3 -36
- package/esm2015/src/utils/utils.js +13 -64
- package/fesm2015/ngxs-store-internals-testing.js +38 -159
- package/fesm2015/ngxs-store-internals-testing.js.map +1 -1
- package/fesm2015/ngxs-store-internals.js +18 -100
- package/fesm2015/ngxs-store-internals.js.map +1 -1
- package/fesm2015/ngxs-store-operators.js +54 -186
- package/fesm2015/ngxs-store-operators.js.map +1 -1
- package/fesm2015/ngxs-store.js +662 -2488
- package/fesm2015/ngxs-store.js.map +1 -1
- package/index.d.ts +4 -0
- package/internals/index.d.ts +1 -1
- package/internals/internal-tokens.d.ts +2 -8
- package/internals/ngxs-bootstrapper.d.ts +4 -1
- package/internals/ngxs-store-internals.d.ts +1 -0
- package/internals/package.json +2 -5
- package/internals/testing/helpers/ngxs-test.component.d.ts +3 -0
- package/internals/testing/helpers/ngxs-test.module.d.ts +6 -0
- package/internals/testing/ngxs-store-internals-testing.d.ts +1 -0
- package/internals/testing/package.json +2 -5
- package/ngxs-store.d.ts +1 -17
- package/operators/append.d.ts +2 -3
- package/operators/compose.d.ts +2 -2
- package/operators/iif.d.ts +3 -4
- package/operators/index.d.ts +3 -2
- package/operators/insert-item.d.ts +2 -3
- package/operators/ngxs-store-operators.d.ts +1 -0
- package/operators/package.json +2 -5
- package/operators/patch.d.ts +5 -8
- package/operators/remove-item.d.ts +3 -4
- package/operators/types.d.ts +56 -0
- package/operators/update-item.d.ts +3 -4
- package/operators/utils.d.ts +2 -3
- package/package.json +4 -7
- package/src/actions/actions.d.ts +2 -2
- package/src/actions-stream.d.ts +8 -22
- package/src/decorators/select/select-factory.d.ts +3 -0
- package/src/decorators/selector/selector.d.ts +7 -2
- package/src/decorators/state.d.ts +1 -1
- package/src/dev-features/ngxs-development.module.d.ts +9 -0
- package/src/dev-features/ngxs-unhandled-actions-logger.d.ts +17 -0
- package/src/dev-features/symbols.d.ts +8 -0
- package/src/execution/dispatch-outside-zone-ngxs-execution-strategy.d.ts +3 -0
- package/src/execution/internal-ngxs-execution-strategy.d.ts +3 -0
- package/src/execution/noop-ngxs-execution-strategy.d.ts +3 -0
- package/src/internal/custom-rxjs-subjects.d.ts +37 -0
- package/src/internal/dispatcher.d.ts +5 -0
- package/src/internal/error-handler.d.ts +4 -1
- package/src/internal/lifecycle-state-manager.d.ts +3 -0
- package/src/internal/state-context-factory.d.ts +3 -0
- package/src/internal/state-factory.d.ts +7 -4
- package/src/internal/state-operations.d.ts +3 -0
- package/src/internal/state-operators.d.ts +2 -2
- package/src/internal/state-stream.d.ts +5 -2
- package/src/module.d.ts +4 -0
- package/src/modules/ngxs-feature.module.d.ts +4 -0
- package/src/modules/ngxs-root.module.d.ts +4 -0
- package/src/operators/of-action.d.ts +20 -7
- package/src/plugin-manager.d.ts +4 -1
- package/src/private_api.d.ts +2 -0
- package/src/public_api.d.ts +8 -5
- package/src/selectors/create-model-selector.d.ts +10 -0
- package/src/selectors/create-pick-selector.d.ts +6 -0
- package/src/selectors/create-property-selectors.d.ts +5 -0
- package/src/selectors/create-selector.d.ts +19 -0
- package/src/selectors/index.d.ts +5 -0
- package/src/selectors/selector-checks.util.d.ts +9 -0
- package/src/selectors/selector-metadata.d.ts +7 -0
- package/src/selectors/selector-models.d.ts +10 -0
- package/src/selectors/selector-types.util.d.ts +7 -0
- package/src/selectors/selector-utils.d.ts +9 -0
- package/src/store.d.ts +3 -0
- package/src/symbols.d.ts +7 -3
- package/src/utils/utils.d.ts +1 -1
- package/bundles/ngxs-store-internals-testing.umd.min.js +0 -16
- package/bundles/ngxs-store-internals-testing.umd.min.js.map +0 -1
- package/bundles/ngxs-store-internals.umd.min.js +0 -2
- package/bundles/ngxs-store-internals.umd.min.js.map +0 -1
- package/bundles/ngxs-store-operators.umd.min.js +0 -16
- package/bundles/ngxs-store-operators.umd.min.js.map +0 -1
- package/bundles/ngxs-store.umd.min.js +0 -16
- package/bundles/ngxs-store.umd.min.js.map +0 -1
- package/esm2015/operators/internals.js +0 -5
- package/esm2015/src/utils/selector-utils.js +0 -221
- package/esm5/index.js +0 -13
- package/esm5/internals/angular.js +0 -20
- package/esm5/internals/index.js +0 -10
- package/esm5/internals/initial-state.js +0 -45
- package/esm5/internals/internal-tokens.js +0 -16
- package/esm5/internals/memoize.js +0 -71
- package/esm5/internals/ngxs-bootstrapper.js +0 -56
- package/esm5/internals/ngxs-store-internals.js +0 -9
- package/esm5/internals/src/symbols.js +0 -14
- package/esm5/internals/symbols.js +0 -14
- package/esm5/internals/testing/fresh-platform.js +0 -121
- package/esm5/internals/testing/helpers/ngxs-test.component.js +0 -32
- package/esm5/internals/testing/helpers/ngxs-test.module.js +0 -32
- package/esm5/internals/testing/index.js +0 -8
- package/esm5/internals/testing/ngxs-store-internals-testing.js +0 -9
- package/esm5/internals/testing/ngxs.setup.js +0 -98
- package/esm5/internals/testing/skip-console-logging.js +0 -62
- package/esm5/internals/testing/symbol.js +0 -29
- package/esm5/ngxs-store.js +0 -25
- package/esm5/operators/append.js +0 -31
- package/esm5/operators/compose.js +0 -28
- package/esm5/operators/iif.js +0 -56
- package/esm5/operators/index.js +0 -18
- package/esm5/operators/insert-item.js +0 -41
- package/esm5/operators/internals.js +0 -5
- package/esm5/operators/ngxs-store-operators.js +0 -9
- package/esm5/operators/patch.js +0 -40
- package/esm5/operators/remove-item.js +0 -34
- package/esm5/operators/update-item.js +0 -52
- package/esm5/operators/utils.js +0 -50
- package/esm5/src/actions/actions.js +0 -62
- package/esm5/src/actions/symbols.js +0 -39
- package/esm5/src/actions-stream.js +0 -203
- package/esm5/src/configs/messages.config.js +0 -79
- package/esm5/src/decorators/action.js +0 -60
- package/esm5/src/decorators/select/select-factory.js +0 -46
- package/esm5/src/decorators/select/select.js +0 -50
- package/esm5/src/decorators/select/symbols.js +0 -51
- package/esm5/src/decorators/selector/selector.js +0 -59
- package/esm5/src/decorators/selector/symbols.js +0 -5
- package/esm5/src/decorators/selector-options.js +0 -34
- package/esm5/src/decorators/state.js +0 -78
- package/esm5/src/execution/dispatch-outside-zone-ngxs-execution-strategy.js +0 -123
- package/esm5/src/execution/internal-ngxs-execution-strategy.js +0 -54
- package/esm5/src/execution/noop-ngxs-execution-strategy.js +0 -43
- package/esm5/src/execution/symbols.js +0 -52
- package/esm5/src/internal/dispatcher.js +0 -231
- package/esm5/src/internal/error-handler.js +0 -125
- package/esm5/src/internal/internals.js +0 -470
- package/esm5/src/internal/lifecycle-state-manager.js +0 -224
- package/esm5/src/internal/state-context-factory.js +0 -135
- package/esm5/src/internal/state-factory.js +0 -583
- package/esm5/src/internal/state-operations.js +0 -134
- package/esm5/src/internal/state-operators.js +0 -34
- package/esm5/src/internal/state-stream.js +0 -37
- package/esm5/src/ivy/ivy-enabled-in-dev-mode.js +0 -28
- package/esm5/src/module.js +0 -202
- package/esm5/src/modules/ngxs-feature.module.js +0 -65
- package/esm5/src/modules/ngxs-root.module.js +0 -44
- package/esm5/src/operators/leave-ngxs.js +0 -58
- package/esm5/src/operators/of-action.js +0 -217
- package/esm5/src/plugin-manager.js +0 -82
- package/esm5/src/plugin_api.js +0 -10
- package/esm5/src/public_api.js +0 -29
- package/esm5/src/public_to_deprecate.js +0 -64
- package/esm5/src/state-token/state-token.js +0 -57
- package/esm5/src/state-token/symbols.js +0 -5
- package/esm5/src/store.js +0 -241
- package/esm5/src/symbols.js +0 -230
- package/esm5/src/utils/compose.js +0 -55
- package/esm5/src/utils/freeze.js +0 -35
- package/esm5/src/utils/selector-utils.js +0 -230
- package/esm5/src/utils/store-validators.js +0 -78
- package/esm5/src/utils/utils.js +0 -151
- package/fesm5/ngxs-store-internals-testing.js +0 -345
- package/fesm5/ngxs-store-internals-testing.js.map +0 -1
- package/fesm5/ngxs-store-internals.js +0 -217
- package/fesm5/ngxs-store-internals.js.map +0 -1
- package/fesm5/ngxs-store-operators.js +0 -340
- package/fesm5/ngxs-store-operators.js.map +0 -1
- package/fesm5/ngxs-store.js +0 -4619
- package/fesm5/ngxs-store.js.map +0 -1
- package/internals/ngxs-store-internals.metadata.json +0 -1
- package/internals/testing/ngxs-store-internals-testing.metadata.json +0 -1
- package/ngxs-store.metadata.json +0 -1
- package/operators/internals.d.ts +0 -2
- package/operators/ngxs-store-operators.metadata.json +0 -1
- package/src/utils/selector-utils.d.ts +0 -23
- package/types/index.d.ts +0 -2
|
@@ -1,260 +1,141 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
3
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* @template T
|
|
7
|
-
* @param {?} items - Specific items to append to the end of an array
|
|
8
|
-
* @return {?}
|
|
2
|
+
* @param items - Specific items to append to the end of an array
|
|
9
3
|
*/
|
|
10
4
|
function append(items) {
|
|
11
|
-
return (
|
|
12
|
-
* @param {?} existing
|
|
13
|
-
* @return {?}
|
|
14
|
-
*/
|
|
15
|
-
function appendOperator(existing) {
|
|
5
|
+
return function appendOperator(existing) {
|
|
16
6
|
// If `items` is `undefined` or `null` or `[]` but `existing` is provided
|
|
17
7
|
// just return `existing`
|
|
18
|
-
/** @type {?} */
|
|
19
8
|
const itemsNotProvidedButExistingIs = (!items || !items.length) && existing;
|
|
20
9
|
if (itemsNotProvidedButExistingIs) {
|
|
21
|
-
return
|
|
10
|
+
return existing;
|
|
22
11
|
}
|
|
23
12
|
if (Array.isArray(existing)) {
|
|
24
|
-
return existing.concat(
|
|
13
|
+
return existing.concat(items);
|
|
25
14
|
}
|
|
26
15
|
// For example if some property is added dynamically
|
|
27
16
|
// and didn't exist before thus it's not `ArrayLike`
|
|
28
|
-
return
|
|
29
|
-
}
|
|
17
|
+
return items;
|
|
18
|
+
};
|
|
30
19
|
}
|
|
31
20
|
|
|
32
|
-
/**
|
|
33
|
-
* @fileoverview added by tsickle
|
|
34
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
35
|
-
*/
|
|
36
|
-
/**
|
|
37
|
-
* @template T
|
|
38
|
-
* @param {...?} operators
|
|
39
|
-
* @return {?}
|
|
40
|
-
*/
|
|
41
21
|
function compose(...operators) {
|
|
42
|
-
return (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
*/
|
|
46
|
-
function composeOperator(existing) {
|
|
47
|
-
return operators.reduce((/**
|
|
48
|
-
* @param {?} accumulator
|
|
49
|
-
* @param {?} operator
|
|
50
|
-
* @return {?}
|
|
51
|
-
*/
|
|
52
|
-
(accumulator, operator) => operator(accumulator)), existing);
|
|
53
|
-
});
|
|
22
|
+
return function composeOperator(existing) {
|
|
23
|
+
return operators.reduce((accumulator, operator) => operator(accumulator), existing);
|
|
24
|
+
};
|
|
54
25
|
}
|
|
55
26
|
|
|
56
|
-
/**
|
|
57
|
-
* @fileoverview added by tsickle
|
|
58
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
59
|
-
*/
|
|
60
|
-
/**
|
|
61
|
-
* @template T
|
|
62
|
-
* @param {?} value
|
|
63
|
-
* @return {?}
|
|
64
|
-
*/
|
|
65
27
|
function isStateOperator(value) {
|
|
66
28
|
return typeof value === 'function';
|
|
67
29
|
}
|
|
68
|
-
/**
|
|
69
|
-
* @param {?} value
|
|
70
|
-
* @return {?}
|
|
71
|
-
*/
|
|
72
30
|
function isUndefined(value) {
|
|
73
31
|
return typeof value === 'undefined';
|
|
74
32
|
}
|
|
75
|
-
/**
|
|
76
|
-
* @template T
|
|
77
|
-
* @param {?} value
|
|
78
|
-
* @return {?}
|
|
79
|
-
*/
|
|
80
33
|
function isPredicate(value) {
|
|
81
34
|
return typeof value === 'function';
|
|
82
35
|
}
|
|
83
|
-
/**
|
|
84
|
-
* @param {?} value
|
|
85
|
-
* @return {?}
|
|
86
|
-
*/
|
|
87
36
|
function isNumber(value) {
|
|
88
37
|
return typeof value === 'number';
|
|
89
38
|
}
|
|
90
|
-
/**
|
|
91
|
-
* @param {?} index
|
|
92
|
-
* @return {?}
|
|
93
|
-
*/
|
|
94
39
|
function invalidIndex(index) {
|
|
95
40
|
return Number.isNaN(index) || index === -1;
|
|
96
41
|
}
|
|
97
|
-
/**
|
|
98
|
-
* @template T
|
|
99
|
-
* @param {?} value
|
|
100
|
-
* @return {?}
|
|
101
|
-
*/
|
|
102
42
|
function isNil(value) {
|
|
103
43
|
return value === null || isUndefined(value);
|
|
104
44
|
}
|
|
105
45
|
|
|
106
|
-
/**
|
|
107
|
-
* @fileoverview added by tsickle
|
|
108
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
109
|
-
*/
|
|
110
|
-
/**
|
|
111
|
-
* @template T
|
|
112
|
-
* @param {?} operatorOrValue
|
|
113
|
-
* @param {?=} existing
|
|
114
|
-
* @return {?}
|
|
115
|
-
*/
|
|
116
46
|
function retrieveValue(operatorOrValue, existing) {
|
|
117
47
|
// If state operator is a function
|
|
118
48
|
// then call it with an original value
|
|
119
49
|
if (isStateOperator(operatorOrValue)) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
return (/** @type {?} */ (value));
|
|
50
|
+
const value = operatorOrValue(existing);
|
|
51
|
+
return value;
|
|
123
52
|
}
|
|
124
53
|
// If operator or value was not provided
|
|
125
54
|
// e.g. `elseOperatorOrValue` is `undefined`
|
|
126
55
|
// then we just return an original value
|
|
127
56
|
if (isUndefined(operatorOrValue)) {
|
|
128
|
-
return
|
|
57
|
+
return existing;
|
|
129
58
|
}
|
|
130
|
-
return
|
|
59
|
+
return operatorOrValue;
|
|
131
60
|
}
|
|
132
61
|
/**
|
|
133
|
-
* @
|
|
134
|
-
* @param {?} condition - Condition can be a plain boolean value or a function,
|
|
62
|
+
* @param condition - Condition can be a plain boolean value or a function,
|
|
135
63
|
* that returns boolean, also this function can take a value as an argument
|
|
136
64
|
* to which this state operator applies
|
|
137
|
-
* @param
|
|
138
|
-
* @param
|
|
139
|
-
* @return {?}
|
|
65
|
+
* @param trueOperatorOrValue - Any value or a state operator
|
|
66
|
+
* @param elseOperatorOrValue - Any value or a state operator
|
|
140
67
|
*/
|
|
141
68
|
function iif(condition, trueOperatorOrValue, elseOperatorOrValue) {
|
|
142
|
-
return (
|
|
143
|
-
* @param {?} existing
|
|
144
|
-
* @return {?}
|
|
145
|
-
*/
|
|
146
|
-
function iifOperator(existing) {
|
|
69
|
+
return function iifOperator(existing) {
|
|
147
70
|
// Convert the value to a boolean
|
|
148
|
-
/** @type {?} */
|
|
149
71
|
let result = !!condition;
|
|
150
72
|
// but if it is a function then run it to get the result
|
|
151
73
|
if (isPredicate(condition)) {
|
|
152
74
|
result = condition(existing);
|
|
153
75
|
}
|
|
154
76
|
if (result) {
|
|
155
|
-
return retrieveValue(trueOperatorOrValue,
|
|
77
|
+
return retrieveValue(trueOperatorOrValue, existing);
|
|
156
78
|
}
|
|
157
|
-
return retrieveValue(
|
|
158
|
-
}
|
|
79
|
+
return retrieveValue(elseOperatorOrValue, existing);
|
|
80
|
+
};
|
|
159
81
|
}
|
|
160
82
|
|
|
161
83
|
/**
|
|
162
|
-
* @
|
|
163
|
-
* @
|
|
164
|
-
*/
|
|
165
|
-
/**
|
|
166
|
-
* @template T
|
|
167
|
-
* @param {?} value - Value to insert
|
|
168
|
-
* @param {?=} beforePosition
|
|
169
|
-
* @return {?}
|
|
84
|
+
* @param value - Value to insert
|
|
85
|
+
* @param [beforePosition] - Specified index to insert value before, optional
|
|
170
86
|
*/
|
|
171
87
|
function insertItem(value, beforePosition) {
|
|
172
|
-
return (
|
|
173
|
-
* @param {?} existing
|
|
174
|
-
* @return {?}
|
|
175
|
-
*/
|
|
176
|
-
function insertItemOperator(existing) {
|
|
88
|
+
return function insertItemOperator(existing) {
|
|
177
89
|
// Have to check explicitly for `null` and `undefined`
|
|
178
90
|
// because `value` can be `0`, thus `!value` will return `true`
|
|
179
91
|
if (isNil(value) && existing) {
|
|
180
|
-
return
|
|
92
|
+
return existing;
|
|
181
93
|
}
|
|
182
94
|
// Property may be dynamic and might not existed before
|
|
183
95
|
if (!Array.isArray(existing)) {
|
|
184
|
-
return [
|
|
96
|
+
return [value];
|
|
185
97
|
}
|
|
186
|
-
/** @type {?} */
|
|
187
98
|
const clone = existing.slice();
|
|
188
|
-
/** @type {?} */
|
|
189
99
|
let index = 0;
|
|
190
100
|
// No need to call `isNumber`
|
|
191
101
|
// as we are checking `> 0` not `>= 0`
|
|
192
102
|
// everything except number will return false here
|
|
193
|
-
if (
|
|
194
|
-
index =
|
|
103
|
+
if (beforePosition > 0) {
|
|
104
|
+
index = beforePosition;
|
|
195
105
|
}
|
|
196
|
-
clone.splice(index, 0,
|
|
106
|
+
clone.splice(index, 0, value);
|
|
197
107
|
return clone;
|
|
198
|
-
}
|
|
108
|
+
};
|
|
199
109
|
}
|
|
200
110
|
|
|
201
|
-
/**
|
|
202
|
-
* @fileoverview added by tsickle
|
|
203
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
204
|
-
*/
|
|
205
|
-
/**
|
|
206
|
-
* @template T
|
|
207
|
-
* @param {?} patchObject
|
|
208
|
-
* @return {?}
|
|
209
|
-
*/
|
|
210
111
|
function patch(patchObject) {
|
|
211
|
-
return (
|
|
212
|
-
* @template U
|
|
213
|
-
* @param {?} existing
|
|
214
|
-
* @return {?}
|
|
215
|
-
*/
|
|
216
|
-
function patchStateOperator(existing) {
|
|
217
|
-
/** @type {?} */
|
|
112
|
+
return function patchStateOperator(existing) {
|
|
218
113
|
let clone = null;
|
|
219
114
|
for (const k in patchObject) {
|
|
220
|
-
/** @type {?} */
|
|
221
115
|
const newValue = patchObject[k];
|
|
222
|
-
/** @type {?} */
|
|
223
116
|
const existingPropValue = existing[k];
|
|
224
|
-
/** @type {?} */
|
|
225
117
|
const newPropValue = isStateOperator(newValue)
|
|
226
|
-
? newValue(
|
|
118
|
+
? newValue(existingPropValue)
|
|
227
119
|
: newValue;
|
|
228
120
|
if (newPropValue !== existingPropValue) {
|
|
229
121
|
if (!clone) {
|
|
230
|
-
clone = Object.assign({},
|
|
122
|
+
clone = Object.assign({}, existing);
|
|
231
123
|
}
|
|
232
124
|
clone[k] = newPropValue;
|
|
233
125
|
}
|
|
234
126
|
}
|
|
235
127
|
return clone || existing;
|
|
236
|
-
}
|
|
128
|
+
};
|
|
237
129
|
}
|
|
238
130
|
|
|
239
131
|
/**
|
|
240
|
-
* @
|
|
241
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
242
|
-
*/
|
|
243
|
-
/**
|
|
244
|
-
* @template T
|
|
245
|
-
* @param {?} selector - Index of item in the array or a predicate function
|
|
132
|
+
* @param selector - Index of item in the array or a predicate function
|
|
246
133
|
* that can be provided in `Array.prototype.findIndex`
|
|
247
|
-
* @param
|
|
134
|
+
* @param operatorOrValue - New value under the `selector` index or a
|
|
248
135
|
* function that can be applied to an existing value
|
|
249
|
-
* @return {?}
|
|
250
136
|
*/
|
|
251
137
|
function updateItem(selector, operatorOrValue) {
|
|
252
|
-
return (
|
|
253
|
-
* @param {?} existing
|
|
254
|
-
* @return {?}
|
|
255
|
-
*/
|
|
256
|
-
function updateItemOperator(existing) {
|
|
257
|
-
/** @type {?} */
|
|
138
|
+
return function updateItemOperator(existing) {
|
|
258
139
|
let index = -1;
|
|
259
140
|
if (isPredicate(selector)) {
|
|
260
141
|
index = existing.findIndex(selector);
|
|
@@ -263,46 +144,34 @@ function updateItem(selector, operatorOrValue) {
|
|
|
263
144
|
index = selector;
|
|
264
145
|
}
|
|
265
146
|
if (invalidIndex(index)) {
|
|
266
|
-
return
|
|
147
|
+
return existing;
|
|
267
148
|
}
|
|
268
|
-
|
|
269
|
-
let value = (/** @type {?} */ (null));
|
|
149
|
+
let value = null;
|
|
270
150
|
// Need to check if the new item value will change the existing item value
|
|
271
151
|
// then, only if it will change it then clone the array and set the item
|
|
272
|
-
|
|
273
|
-
|
|
152
|
+
const theOperatorOrValue = operatorOrValue;
|
|
153
|
+
if (isStateOperator(theOperatorOrValue)) {
|
|
154
|
+
value = theOperatorOrValue(existing[index]);
|
|
274
155
|
}
|
|
275
156
|
else {
|
|
276
|
-
value =
|
|
157
|
+
value = theOperatorOrValue;
|
|
277
158
|
}
|
|
278
159
|
// If the value hasn't been mutated
|
|
279
160
|
// then we just return `existing` array
|
|
280
161
|
if (value === existing[index]) {
|
|
281
|
-
return
|
|
162
|
+
return existing;
|
|
282
163
|
}
|
|
283
|
-
/** @type {?} */
|
|
284
164
|
const clone = existing.slice();
|
|
285
|
-
clone[index] =
|
|
165
|
+
clone[index] = value;
|
|
286
166
|
return clone;
|
|
287
|
-
}
|
|
167
|
+
};
|
|
288
168
|
}
|
|
289
169
|
|
|
290
170
|
/**
|
|
291
|
-
* @
|
|
292
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
293
|
-
*/
|
|
294
|
-
/**
|
|
295
|
-
* @template T
|
|
296
|
-
* @param {?} selector - index or predicate to remove an item from an array by
|
|
297
|
-
* @return {?}
|
|
171
|
+
* @param selector - index or predicate to remove an item from an array by
|
|
298
172
|
*/
|
|
299
173
|
function removeItem(selector) {
|
|
300
|
-
return (
|
|
301
|
-
* @param {?} existing
|
|
302
|
-
* @return {?}
|
|
303
|
-
*/
|
|
304
|
-
function removeItemOperator(existing) {
|
|
305
|
-
/** @type {?} */
|
|
174
|
+
return function removeItemOperator(existing) {
|
|
306
175
|
let index = -1;
|
|
307
176
|
if (isPredicate(selector)) {
|
|
308
177
|
index = existing.findIndex(selector);
|
|
@@ -311,24 +180,23 @@ function removeItem(selector) {
|
|
|
311
180
|
index = selector;
|
|
312
181
|
}
|
|
313
182
|
if (invalidIndex(index)) {
|
|
314
|
-
return
|
|
183
|
+
return existing;
|
|
315
184
|
}
|
|
316
|
-
/** @type {?} */
|
|
317
185
|
const clone = existing.slice();
|
|
318
186
|
clone.splice(index, 1);
|
|
319
187
|
return clone;
|
|
320
|
-
}
|
|
188
|
+
};
|
|
321
189
|
}
|
|
322
190
|
|
|
323
191
|
/**
|
|
324
|
-
* @
|
|
325
|
-
* @
|
|
192
|
+
* @module
|
|
193
|
+
* @description
|
|
194
|
+
* Entry point for all public APIs of this package.
|
|
326
195
|
*/
|
|
327
196
|
|
|
328
197
|
/**
|
|
329
|
-
*
|
|
330
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
198
|
+
* Generated bundle index. Do not edit.
|
|
331
199
|
*/
|
|
332
200
|
|
|
333
|
-
export { append, compose, iif, insertItem, isStateOperator, patch, removeItem, updateItem };
|
|
201
|
+
export { append, compose, iif, insertItem, isPredicate, isStateOperator, patch, removeItem, updateItem };
|
|
334
202
|
//# sourceMappingURL=ngxs-store-operators.js.map
|
|
@@ -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 } from './utils';\n\n/**\n * @param items - Specific items to append to the end of an array\n */\nexport function append<T>(items: 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 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 RepairType<T>[];\n };\n}\n","import { StateOperator } from '@ngxs/store';\n\nexport function compose<T>(...operators: 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","import { StateOperator } from '@ngxs/store';\n\nimport { isStateOperator, isUndefined, isPredicate, RepairType } 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: Predicate<T> | boolean,\n trueOperatorOrValue: StateOperator<T> | T,\n elseOperatorOrValue?: 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 } 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: 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 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 RepairType<T>);\n return clone;\n };\n}\n","import { StateOperator } from '@ngxs/store';\nimport { isStateOperator } 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\ntype PatchOperator<T> = <U extends PatchValues<T>>(existing: Readonly<U>) => U;\n\nexport function patch<T>(patchObject: PatchSpec<T>): PatchOperator<T> {\n return function patchStateOperator<U extends PatchValues<T>>(existing: Readonly<U>): U {\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 { StateOperator } from '@ngxs/store';\n\nimport { isStateOperator, isPredicate, isNumber, invalidIndex, RepairType } 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 | Predicate<T>,\n operatorOrValue: T | 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);\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 if (isStateOperator(operatorOrValue)) {\n value = operatorOrValue(existing[index] as Readonly<T>);\n } else {\n value = operatorOrValue;\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);\n return clone;\n };\n}\n"],"names":[],"mappings":";;;;;;;;;AAMA,SAAgB,MAAM,CAAI,KAAU;IAClC;;;;IAAO,SAAS,cAAc,CAAC,QAAmC;;;;cAG1D,6BAA6B,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ;QAC3E,IAAI,6BAA6B,EAAE;YACjC,0BAAO,QAAQ,GAAoB;SACpC;QAED,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;YAC3B,OAAO,QAAQ,CAAC,MAAM,oBAAC,KAAK,GAAoB,CAAC;SAClD;;;QAID,0BAAO,KAAK,GAAoB;KACjC,EAAC;CACH;;;;;;;;;;;ACrBD,SAAgB,OAAO,CAAI,GAAG,SAA6B;IACzD;;;;IAAO,SAAS,eAAe,CAAC,QAAqB;QACnD,OAAO,SAAS,CAAC,MAAM;;;;;QAAC,CAAC,WAAW,EAAE,QAAQ,KAAK,QAAQ,CAAC,WAAW,CAAC,GAAE,QAAQ,CAAC,CAAC;KACrF,EAAC;CACH;;;;;;;;;;;ACFD,SAAgB,eAAe,CAAI,KAA2B;IAC5D,OAA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K,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":["../../../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,OAAO,SAAS,cAAc,CAAC,QAA4B,EAAA;;;AAGzD,QAAA,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC;AAC5E,QAAA,IAAI,6BAA6B,EAAE;AACjC,YAAA,OAAQ,QAA2B,CAAC;AACrC,SAAA;AAED,QAAA,IAAI,KAAK,C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