@ngxs/store 3.7.6-dev.master-fb318b1 → 3.7.6-dev.master-dcdd391
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 +60 -402
- package/bundles/ngxs-store-operators.umd.js.map +1 -1
- package/bundles/ngxs-store.umd.js +1041 -3269
- 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 -23
- 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 +1 -5
- package/esm2015/operators/insert-item.js +10 -22
- package/esm2015/operators/ngxs-store-operators.js +2 -6
- package/esm2015/operators/patch.js +5 -22
- package/esm2015/operators/remove-item.js +5 -17
- package/esm2015/operators/types.js +2 -5
- package/esm2015/operators/update-item.js +12 -26
- 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 +24 -90
- 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 +5 -29
- package/esm2015/src/decorators/selector/symbols.js +2 -5
- package/esm2015/src/decorators/selector-options.js +4 -18
- package/esm2015/src/decorators/state.js +5 -44
- package/esm2015/src/dev-features/ngxs-development.module.js +8 -12
- package/esm2015/src/dev-features/ngxs-unhandled-actions-logger.js +12 -37
- package/esm2015/src/dev-features/symbols.js +2 -18
- 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/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 +9 -67
- package/esm2015/src/internal/state-factory.js +42 -225
- package/esm2015/src/internal/state-operations.js +19 -80
- package/esm2015/src/internal/state-operators.js +6 -20
- package/esm2015/src/internal/state-stream.js +7 -13
- 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 -111
- 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 +1 -5
- package/esm2015/src/public_to_deprecate.js +1 -51
- package/esm2015/src/state-token/state-token.js +4 -32
- package/esm2015/src/state-token/symbols.js +2 -5
- package/esm2015/src/store.js +20 -104
- 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/selector-utils.js +23 -136
- 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 +52 -185
- package/fesm2015/ngxs-store-operators.js.map +1 -1
- package/fesm2015/ngxs-store.js +400 -2473
- 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 -18
- package/operators/ngxs-store-operators.d.ts +1 -0
- package/operators/package.json +2 -5
- package/package.json +3 -6
- package/src/actions/actions.d.ts +2 -2
- package/src/actions-stream.d.ts +5 -0
- package/src/decorators/select/select-factory.d.ts +3 -0
- package/src/decorators/state.d.ts +1 -1
- package/src/dev-features/ngxs-development.module.d.ts +4 -0
- package/src/dev-features/ngxs-unhandled-actions-logger.d.ts +3 -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/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-stream.d.ts +3 -0
- 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/plugin-manager.d.ts +4 -1
- package/src/private_api.d.ts +2 -0
- package/src/store.d.ts +3 -0
- package/src/symbols.d.ts +4 -1
- 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/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 -26
- 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/ngxs-store-operators.js +0 -9
- package/esm5/operators/patch.js +0 -39
- package/esm5/operators/remove-item.js +0 -34
- package/esm5/operators/types.js +0 -5
- package/esm5/operators/update-item.js +0 -54
- 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 -201
- 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/dev-features/ngxs-development.module.js +0 -34
- package/esm5/src/dev-features/ngxs-unhandled-actions-logger.js +0 -100
- package/esm5/src/dev-features/symbols.js +0 -22
- 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 -599
- 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 -223
- package/esm5/src/plugin-manager.js +0 -82
- package/esm5/src/plugin_api.js +0 -10
- package/esm5/src/public_api.js +0 -31
- 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 -341
- package/fesm5/ngxs-store-operators.js.map +0 -1
- package/fesm5/ngxs-store.js +0 -4783
- 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/ngxs-store-operators.metadata.json +0 -1
- package/types/index.d.ts +0 -2
|
@@ -1,277 +1,157 @@
|
|
|
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((/** @type {?} */ (accumulator)))), (/** @type {?} */ (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
|
-
/** @type {?} */
|
|
121
50
|
const value = operatorOrValue(existing);
|
|
122
|
-
return
|
|
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
|
-
result = condition(
|
|
74
|
+
result = condition(existing);
|
|
153
75
|
}
|
|
154
76
|
if (result) {
|
|
155
|
-
return retrieveValue(
|
|
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
|
-
* @param {?} existing
|
|
213
|
-
* @return {?}
|
|
214
|
-
*/
|
|
215
|
-
function patchStateOperator(existing) {
|
|
216
|
-
/** @type {?} */
|
|
112
|
+
return function patchStateOperator(existing) {
|
|
217
113
|
let clone = null;
|
|
218
114
|
for (const k in patchObject) {
|
|
219
|
-
/** @type {?} */
|
|
220
115
|
const newValue = patchObject[k];
|
|
221
|
-
/** @type {?} */
|
|
222
116
|
const existingPropValue = existing[k];
|
|
223
|
-
/** @type {?} */
|
|
224
117
|
const newPropValue = isStateOperator(newValue)
|
|
225
|
-
? newValue(
|
|
118
|
+
? newValue(existingPropValue)
|
|
226
119
|
: newValue;
|
|
227
120
|
if (newPropValue !== existingPropValue) {
|
|
228
121
|
if (!clone) {
|
|
229
|
-
clone = Object.assign({},
|
|
122
|
+
clone = Object.assign({}, existing);
|
|
230
123
|
}
|
|
231
124
|
clone[k] = newPropValue;
|
|
232
125
|
}
|
|
233
126
|
}
|
|
234
127
|
return clone || existing;
|
|
235
|
-
}
|
|
128
|
+
};
|
|
236
129
|
}
|
|
237
130
|
|
|
238
131
|
/**
|
|
239
|
-
* @
|
|
240
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
241
|
-
*/
|
|
242
|
-
/**
|
|
243
|
-
* @template T
|
|
244
|
-
* @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
|
|
245
133
|
* that can be provided in `Array.prototype.findIndex`
|
|
246
|
-
* @param
|
|
134
|
+
* @param operatorOrValue - New value under the `selector` index or a
|
|
247
135
|
* function that can be applied to an existing value
|
|
248
|
-
* @return {?}
|
|
249
136
|
*/
|
|
250
137
|
function updateItem(selector, operatorOrValue) {
|
|
251
|
-
return (
|
|
252
|
-
* @param {?} existing
|
|
253
|
-
* @return {?}
|
|
254
|
-
*/
|
|
255
|
-
function updateItemOperator(existing) {
|
|
256
|
-
/** @type {?} */
|
|
138
|
+
return function updateItemOperator(existing) {
|
|
257
139
|
let index = -1;
|
|
258
140
|
if (isPredicate(selector)) {
|
|
259
|
-
index = existing.findIndex(
|
|
141
|
+
index = existing.findIndex(selector);
|
|
260
142
|
}
|
|
261
143
|
else if (isNumber(selector)) {
|
|
262
144
|
index = selector;
|
|
263
145
|
}
|
|
264
146
|
if (invalidIndex(index)) {
|
|
265
|
-
return
|
|
147
|
+
return existing;
|
|
266
148
|
}
|
|
267
|
-
|
|
268
|
-
let value = (/** @type {?} */ (null));
|
|
149
|
+
let value = null;
|
|
269
150
|
// Need to check if the new item value will change the existing item value
|
|
270
151
|
// then, only if it will change it then clone the array and set the item
|
|
271
|
-
|
|
272
|
-
const theOperatorOrValue = (/** @type {?} */ (operatorOrValue));
|
|
152
|
+
const theOperatorOrValue = operatorOrValue;
|
|
273
153
|
if (isStateOperator(theOperatorOrValue)) {
|
|
274
|
-
value = theOperatorOrValue(
|
|
154
|
+
value = theOperatorOrValue(existing[index]);
|
|
275
155
|
}
|
|
276
156
|
else {
|
|
277
157
|
value = theOperatorOrValue;
|
|
@@ -279,31 +159,19 @@ function updateItem(selector, operatorOrValue) {
|
|
|
279
159
|
// If the value hasn't been mutated
|
|
280
160
|
// then we just return `existing` array
|
|
281
161
|
if (value === existing[index]) {
|
|
282
|
-
return
|
|
162
|
+
return existing;
|
|
283
163
|
}
|
|
284
|
-
/** @type {?} */
|
|
285
164
|
const clone = existing.slice();
|
|
286
|
-
clone[index] =
|
|
165
|
+
clone[index] = value;
|
|
287
166
|
return clone;
|
|
288
|
-
}
|
|
167
|
+
};
|
|
289
168
|
}
|
|
290
169
|
|
|
291
170
|
/**
|
|
292
|
-
* @
|
|
293
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
294
|
-
*/
|
|
295
|
-
/**
|
|
296
|
-
* @template T
|
|
297
|
-
* @param {?} selector - index or predicate to remove an item from an array by
|
|
298
|
-
* @return {?}
|
|
171
|
+
* @param selector - index or predicate to remove an item from an array by
|
|
299
172
|
*/
|
|
300
173
|
function removeItem(selector) {
|
|
301
|
-
return (
|
|
302
|
-
* @param {?} existing
|
|
303
|
-
* @return {?}
|
|
304
|
-
*/
|
|
305
|
-
function removeItemOperator(existing) {
|
|
306
|
-
/** @type {?} */
|
|
174
|
+
return function removeItemOperator(existing) {
|
|
307
175
|
let index = -1;
|
|
308
176
|
if (isPredicate(selector)) {
|
|
309
177
|
index = existing.findIndex(selector);
|
|
@@ -312,23 +180,22 @@ function removeItem(selector) {
|
|
|
312
180
|
index = selector;
|
|
313
181
|
}
|
|
314
182
|
if (invalidIndex(index)) {
|
|
315
|
-
return
|
|
183
|
+
return existing;
|
|
316
184
|
}
|
|
317
|
-
/** @type {?} */
|
|
318
185
|
const clone = existing.slice();
|
|
319
186
|
clone.splice(index, 1);
|
|
320
187
|
return clone;
|
|
321
|
-
}
|
|
188
|
+
};
|
|
322
189
|
}
|
|
323
190
|
|
|
324
191
|
/**
|
|
325
|
-
* @
|
|
326
|
-
* @
|
|
192
|
+
* @module
|
|
193
|
+
* @description
|
|
194
|
+
* Entry point for all public APIs of this package.
|
|
327
195
|
*/
|
|
328
196
|
|
|
329
197
|
/**
|
|
330
|
-
*
|
|
331
|
-
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
198
|
+
* Generated bundle index. Do not edit.
|
|
332
199
|
*/
|
|
333
200
|
|
|
334
201
|
export { append, compose, iif, insertItem, isStateOperator, patch, removeItem, updateItem };
|
|
@@ -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 { 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;;;;cAGnD,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,CAAI,GAAG,SAAsC;IAClE;;;;IAAO,SAAS,eAAe,CAAC,QAA0B;QACxD,OAAO,SAAS,CAAC,MAAM;;;;;QACrB,CAAC,WAAW,EAAE,QAAQ,KAAK,QAAQ,oBAAC,WAAW,GAAqB,sBACpE,QAAQ,GACT,CAAC;KACH,EAAC;CACH;;;;;;;;;;;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AE;YACvB,0BAAO,QAAQ,GAAQ;SACxB;;cAEK,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":["../../../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 } from './patch';\nexport { isStateOperator } 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,C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