@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.
Files changed (267) hide show
  1. package/bundles/ngxs-store-internals-testing.umd.js +409 -420
  2. package/bundles/ngxs-store-internals-testing.umd.js.map +1 -1
  3. package/bundles/ngxs-store-internals.umd.js +48 -117
  4. package/bundles/ngxs-store-internals.umd.js.map +1 -1
  5. package/bundles/ngxs-store-operators.umd.js +62 -402
  6. package/bundles/ngxs-store-operators.umd.js.map +1 -1
  7. package/bundles/ngxs-store.umd.js +1296 -3219
  8. package/bundles/ngxs-store.umd.js.map +1 -1
  9. package/esm2015/index.js +7 -7
  10. package/esm2015/internals/angular.js +1 -8
  11. package/esm2015/internals/index.js +2 -6
  12. package/esm2015/internals/initial-state.js +1 -21
  13. package/esm2015/internals/internal-tokens.js +4 -15
  14. package/esm2015/internals/memoize.js +8 -33
  15. package/esm2015/internals/ngxs-bootstrapper.js +7 -20
  16. package/esm2015/internals/ngxs-store-internals.js +2 -6
  17. package/esm2015/internals/src/symbols.js +2 -14
  18. package/esm2015/internals/symbols.js +2 -14
  19. package/esm2015/internals/testing/fresh-platform.js +13 -53
  20. package/esm2015/internals/testing/helpers/ngxs-test.component.js +11 -17
  21. package/esm2015/internals/testing/helpers/ngxs-test.module.js +13 -16
  22. package/esm2015/internals/testing/index.js +1 -5
  23. package/esm2015/internals/testing/ngxs-store-internals-testing.js +2 -6
  24. package/esm2015/internals/testing/ngxs.setup.js +1 -31
  25. package/esm2015/internals/testing/skip-console-logging.js +7 -42
  26. package/esm2015/internals/testing/symbol.js +2 -29
  27. package/esm2015/ngxs-store.js +2 -22
  28. package/esm2015/operators/append.js +7 -18
  29. package/esm2015/operators/compose.js +4 -22
  30. package/esm2015/operators/iif.js +12 -30
  31. package/esm2015/operators/index.js +2 -6
  32. package/esm2015/operators/insert-item.js +10 -22
  33. package/esm2015/operators/ngxs-store-operators.js +2 -6
  34. package/esm2015/operators/patch.js +5 -23
  35. package/esm2015/operators/remove-item.js +5 -17
  36. package/esm2015/operators/types.js +2 -0
  37. package/esm2015/operators/update-item.js +13 -25
  38. package/esm2015/operators/utils.js +1 -32
  39. package/esm2015/src/actions/actions.js +1 -18
  40. package/esm2015/src/actions/symbols.js +2 -39
  41. package/esm2015/src/actions-stream.js +20 -122
  42. package/esm2015/src/configs/messages.config.js +1 -44
  43. package/esm2015/src/decorators/action.js +3 -18
  44. package/esm2015/src/decorators/select/select-factory.js +10 -27
  45. package/esm2015/src/decorators/select/select.js +3 -22
  46. package/esm2015/src/decorators/select/symbols.js +4 -25
  47. package/esm2015/src/decorators/selector/selector.js +11 -38
  48. package/esm2015/src/decorators/selector/symbols.js +2 -5
  49. package/esm2015/src/decorators/selector-options.js +6 -19
  50. package/esm2015/src/decorators/state.js +5 -44
  51. package/esm2015/src/dev-features/ngxs-development.module.js +22 -0
  52. package/esm2015/src/dev-features/ngxs-unhandled-actions-logger.js +46 -0
  53. package/esm2015/src/dev-features/symbols.js +6 -0
  54. package/esm2015/src/execution/dispatch-outside-zone-ngxs-execution-strategy.js +10 -56
  55. package/esm2015/src/execution/internal-ngxs-execution-strategy.js +10 -32
  56. package/esm2015/src/execution/noop-ngxs-execution-strategy.js +7 -19
  57. package/esm2015/src/execution/symbols.js +3 -32
  58. package/esm2015/src/internal/custom-rxjs-subjects.js +81 -0
  59. package/esm2015/src/internal/dispatcher.js +26 -121
  60. package/esm2015/src/internal/error-handler.js +18 -72
  61. package/esm2015/src/internal/internals.js +24 -244
  62. package/esm2015/src/internal/lifecycle-state-manager.js +19 -117
  63. package/esm2015/src/internal/state-context-factory.js +8 -66
  64. package/esm2015/src/internal/state-factory.js +60 -227
  65. package/esm2015/src/internal/state-operations.js +19 -80
  66. package/esm2015/src/internal/state-operators.js +15 -28
  67. package/esm2015/src/internal/state-stream.js +9 -15
  68. package/esm2015/src/ivy/ivy-enabled-in-dev-mode.js +7 -17
  69. package/esm2015/src/module.js +12 -47
  70. package/esm2015/src/modules/ngxs-feature.module.js +18 -36
  71. package/esm2015/src/modules/ngxs-root.module.js +18 -26
  72. package/esm2015/src/operators/leave-ngxs.js +8 -43
  73. package/esm2015/src/operators/of-action.js +16 -105
  74. package/esm2015/src/plugin-manager.js +17 -50
  75. package/esm2015/src/plugin_api.js +1 -5
  76. package/esm2015/src/private_api.js +3 -0
  77. package/esm2015/src/public_api.js +7 -9
  78. package/esm2015/src/public_to_deprecate.js +1 -51
  79. package/esm2015/src/selectors/create-model-selector.js +28 -0
  80. package/esm2015/src/selectors/create-pick-selector.js +14 -0
  81. package/esm2015/src/selectors/create-property-selectors.js +18 -0
  82. package/esm2015/src/selectors/create-selector.js +9 -0
  83. package/esm2015/src/selectors/index.js +6 -0
  84. package/esm2015/src/selectors/selector-checks.util.js +18 -0
  85. package/esm2015/src/selectors/selector-metadata.js +30 -0
  86. package/esm2015/src/selectors/selector-models.js +2 -0
  87. package/esm2015/src/selectors/selector-types.util.js +2 -0
  88. package/esm2015/src/selectors/selector-utils.js +74 -0
  89. package/esm2015/src/state-token/state-token.js +4 -32
  90. package/esm2015/src/state-token/symbols.js +2 -5
  91. package/esm2015/src/store.js +24 -108
  92. package/esm2015/src/symbols.js +7 -177
  93. package/esm2015/src/utils/compose.js +5 -23
  94. package/esm2015/src/utils/freeze.js +5 -20
  95. package/esm2015/src/utils/store-validators.js +3 -36
  96. package/esm2015/src/utils/utils.js +13 -64
  97. package/fesm2015/ngxs-store-internals-testing.js +38 -159
  98. package/fesm2015/ngxs-store-internals-testing.js.map +1 -1
  99. package/fesm2015/ngxs-store-internals.js +18 -100
  100. package/fesm2015/ngxs-store-internals.js.map +1 -1
  101. package/fesm2015/ngxs-store-operators.js +54 -186
  102. package/fesm2015/ngxs-store-operators.js.map +1 -1
  103. package/fesm2015/ngxs-store.js +662 -2488
  104. package/fesm2015/ngxs-store.js.map +1 -1
  105. package/index.d.ts +4 -0
  106. package/internals/index.d.ts +1 -1
  107. package/internals/internal-tokens.d.ts +2 -8
  108. package/internals/ngxs-bootstrapper.d.ts +4 -1
  109. package/internals/ngxs-store-internals.d.ts +1 -0
  110. package/internals/package.json +2 -5
  111. package/internals/testing/helpers/ngxs-test.component.d.ts +3 -0
  112. package/internals/testing/helpers/ngxs-test.module.d.ts +6 -0
  113. package/internals/testing/ngxs-store-internals-testing.d.ts +1 -0
  114. package/internals/testing/package.json +2 -5
  115. package/ngxs-store.d.ts +1 -17
  116. package/operators/append.d.ts +2 -3
  117. package/operators/compose.d.ts +2 -2
  118. package/operators/iif.d.ts +3 -4
  119. package/operators/index.d.ts +3 -2
  120. package/operators/insert-item.d.ts +2 -3
  121. package/operators/ngxs-store-operators.d.ts +1 -0
  122. package/operators/package.json +2 -5
  123. package/operators/patch.d.ts +5 -8
  124. package/operators/remove-item.d.ts +3 -4
  125. package/operators/types.d.ts +56 -0
  126. package/operators/update-item.d.ts +3 -4
  127. package/operators/utils.d.ts +2 -3
  128. package/package.json +4 -7
  129. package/src/actions/actions.d.ts +2 -2
  130. package/src/actions-stream.d.ts +8 -22
  131. package/src/decorators/select/select-factory.d.ts +3 -0
  132. package/src/decorators/selector/selector.d.ts +7 -2
  133. package/src/decorators/state.d.ts +1 -1
  134. package/src/dev-features/ngxs-development.module.d.ts +9 -0
  135. package/src/dev-features/ngxs-unhandled-actions-logger.d.ts +17 -0
  136. package/src/dev-features/symbols.d.ts +8 -0
  137. package/src/execution/dispatch-outside-zone-ngxs-execution-strategy.d.ts +3 -0
  138. package/src/execution/internal-ngxs-execution-strategy.d.ts +3 -0
  139. package/src/execution/noop-ngxs-execution-strategy.d.ts +3 -0
  140. package/src/internal/custom-rxjs-subjects.d.ts +37 -0
  141. package/src/internal/dispatcher.d.ts +5 -0
  142. package/src/internal/error-handler.d.ts +4 -1
  143. package/src/internal/lifecycle-state-manager.d.ts +3 -0
  144. package/src/internal/state-context-factory.d.ts +3 -0
  145. package/src/internal/state-factory.d.ts +7 -4
  146. package/src/internal/state-operations.d.ts +3 -0
  147. package/src/internal/state-operators.d.ts +2 -2
  148. package/src/internal/state-stream.d.ts +5 -2
  149. package/src/module.d.ts +4 -0
  150. package/src/modules/ngxs-feature.module.d.ts +4 -0
  151. package/src/modules/ngxs-root.module.d.ts +4 -0
  152. package/src/operators/of-action.d.ts +20 -7
  153. package/src/plugin-manager.d.ts +4 -1
  154. package/src/private_api.d.ts +2 -0
  155. package/src/public_api.d.ts +8 -5
  156. package/src/selectors/create-model-selector.d.ts +10 -0
  157. package/src/selectors/create-pick-selector.d.ts +6 -0
  158. package/src/selectors/create-property-selectors.d.ts +5 -0
  159. package/src/selectors/create-selector.d.ts +19 -0
  160. package/src/selectors/index.d.ts +5 -0
  161. package/src/selectors/selector-checks.util.d.ts +9 -0
  162. package/src/selectors/selector-metadata.d.ts +7 -0
  163. package/src/selectors/selector-models.d.ts +10 -0
  164. package/src/selectors/selector-types.util.d.ts +7 -0
  165. package/src/selectors/selector-utils.d.ts +9 -0
  166. package/src/store.d.ts +3 -0
  167. package/src/symbols.d.ts +7 -3
  168. package/src/utils/utils.d.ts +1 -1
  169. package/bundles/ngxs-store-internals-testing.umd.min.js +0 -16
  170. package/bundles/ngxs-store-internals-testing.umd.min.js.map +0 -1
  171. package/bundles/ngxs-store-internals.umd.min.js +0 -2
  172. package/bundles/ngxs-store-internals.umd.min.js.map +0 -1
  173. package/bundles/ngxs-store-operators.umd.min.js +0 -16
  174. package/bundles/ngxs-store-operators.umd.min.js.map +0 -1
  175. package/bundles/ngxs-store.umd.min.js +0 -16
  176. package/bundles/ngxs-store.umd.min.js.map +0 -1
  177. package/esm2015/operators/internals.js +0 -5
  178. package/esm2015/src/utils/selector-utils.js +0 -221
  179. package/esm5/index.js +0 -13
  180. package/esm5/internals/angular.js +0 -20
  181. package/esm5/internals/index.js +0 -10
  182. package/esm5/internals/initial-state.js +0 -45
  183. package/esm5/internals/internal-tokens.js +0 -16
  184. package/esm5/internals/memoize.js +0 -71
  185. package/esm5/internals/ngxs-bootstrapper.js +0 -56
  186. package/esm5/internals/ngxs-store-internals.js +0 -9
  187. package/esm5/internals/src/symbols.js +0 -14
  188. package/esm5/internals/symbols.js +0 -14
  189. package/esm5/internals/testing/fresh-platform.js +0 -121
  190. package/esm5/internals/testing/helpers/ngxs-test.component.js +0 -32
  191. package/esm5/internals/testing/helpers/ngxs-test.module.js +0 -32
  192. package/esm5/internals/testing/index.js +0 -8
  193. package/esm5/internals/testing/ngxs-store-internals-testing.js +0 -9
  194. package/esm5/internals/testing/ngxs.setup.js +0 -98
  195. package/esm5/internals/testing/skip-console-logging.js +0 -62
  196. package/esm5/internals/testing/symbol.js +0 -29
  197. package/esm5/ngxs-store.js +0 -25
  198. package/esm5/operators/append.js +0 -31
  199. package/esm5/operators/compose.js +0 -28
  200. package/esm5/operators/iif.js +0 -56
  201. package/esm5/operators/index.js +0 -18
  202. package/esm5/operators/insert-item.js +0 -41
  203. package/esm5/operators/internals.js +0 -5
  204. package/esm5/operators/ngxs-store-operators.js +0 -9
  205. package/esm5/operators/patch.js +0 -40
  206. package/esm5/operators/remove-item.js +0 -34
  207. package/esm5/operators/update-item.js +0 -52
  208. package/esm5/operators/utils.js +0 -50
  209. package/esm5/src/actions/actions.js +0 -62
  210. package/esm5/src/actions/symbols.js +0 -39
  211. package/esm5/src/actions-stream.js +0 -203
  212. package/esm5/src/configs/messages.config.js +0 -79
  213. package/esm5/src/decorators/action.js +0 -60
  214. package/esm5/src/decorators/select/select-factory.js +0 -46
  215. package/esm5/src/decorators/select/select.js +0 -50
  216. package/esm5/src/decorators/select/symbols.js +0 -51
  217. package/esm5/src/decorators/selector/selector.js +0 -59
  218. package/esm5/src/decorators/selector/symbols.js +0 -5
  219. package/esm5/src/decorators/selector-options.js +0 -34
  220. package/esm5/src/decorators/state.js +0 -78
  221. package/esm5/src/execution/dispatch-outside-zone-ngxs-execution-strategy.js +0 -123
  222. package/esm5/src/execution/internal-ngxs-execution-strategy.js +0 -54
  223. package/esm5/src/execution/noop-ngxs-execution-strategy.js +0 -43
  224. package/esm5/src/execution/symbols.js +0 -52
  225. package/esm5/src/internal/dispatcher.js +0 -231
  226. package/esm5/src/internal/error-handler.js +0 -125
  227. package/esm5/src/internal/internals.js +0 -470
  228. package/esm5/src/internal/lifecycle-state-manager.js +0 -224
  229. package/esm5/src/internal/state-context-factory.js +0 -135
  230. package/esm5/src/internal/state-factory.js +0 -583
  231. package/esm5/src/internal/state-operations.js +0 -134
  232. package/esm5/src/internal/state-operators.js +0 -34
  233. package/esm5/src/internal/state-stream.js +0 -37
  234. package/esm5/src/ivy/ivy-enabled-in-dev-mode.js +0 -28
  235. package/esm5/src/module.js +0 -202
  236. package/esm5/src/modules/ngxs-feature.module.js +0 -65
  237. package/esm5/src/modules/ngxs-root.module.js +0 -44
  238. package/esm5/src/operators/leave-ngxs.js +0 -58
  239. package/esm5/src/operators/of-action.js +0 -217
  240. package/esm5/src/plugin-manager.js +0 -82
  241. package/esm5/src/plugin_api.js +0 -10
  242. package/esm5/src/public_api.js +0 -29
  243. package/esm5/src/public_to_deprecate.js +0 -64
  244. package/esm5/src/state-token/state-token.js +0 -57
  245. package/esm5/src/state-token/symbols.js +0 -5
  246. package/esm5/src/store.js +0 -241
  247. package/esm5/src/symbols.js +0 -230
  248. package/esm5/src/utils/compose.js +0 -55
  249. package/esm5/src/utils/freeze.js +0 -35
  250. package/esm5/src/utils/selector-utils.js +0 -230
  251. package/esm5/src/utils/store-validators.js +0 -78
  252. package/esm5/src/utils/utils.js +0 -151
  253. package/fesm5/ngxs-store-internals-testing.js +0 -345
  254. package/fesm5/ngxs-store-internals-testing.js.map +0 -1
  255. package/fesm5/ngxs-store-internals.js +0 -217
  256. package/fesm5/ngxs-store-internals.js.map +0 -1
  257. package/fesm5/ngxs-store-operators.js +0 -340
  258. package/fesm5/ngxs-store-operators.js.map +0 -1
  259. package/fesm5/ngxs-store.js +0 -4619
  260. package/fesm5/ngxs-store.js.map +0 -1
  261. package/internals/ngxs-store-internals.metadata.json +0 -1
  262. package/internals/testing/ngxs-store-internals-testing.metadata.json +0 -1
  263. package/ngxs-store.metadata.json +0 -1
  264. package/operators/internals.d.ts +0 -2
  265. package/operators/ngxs-store-operators.metadata.json +0 -1
  266. package/src/utils/selector-utils.d.ts +0 -23
  267. package/types/index.d.ts +0 -2
@@ -1,260 +1,141 @@
1
1
  /**
2
- * @fileoverview added by tsickle
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 (/** @type {?} */ (existing));
10
+ return existing;
22
11
  }
23
12
  if (Array.isArray(existing)) {
24
- return existing.concat((/** @type {?} */ (items)));
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 (/** @type {?} */ (items));
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
- * @param {?} existing
44
- * @return {?}
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
- /** @type {?} */
121
- const value = operatorOrValue((/** @type {?} */ ((/** @type {?} */ (existing)))));
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 (/** @type {?} */ ((/** @type {?} */ (((/** @type {?} */ (existing)))))));
57
+ return existing;
129
58
  }
130
- return (/** @type {?} */ (operatorOrValue));
59
+ return operatorOrValue;
131
60
  }
132
61
  /**
133
- * @template T
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 {?} trueOperatorOrValue - Any value or a state operator
138
- * @param {?=} elseOperatorOrValue - Any value or a state operator
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, (/** @type {?} */ (existing)));
77
+ return retrieveValue(trueOperatorOrValue, existing);
156
78
  }
157
- return retrieveValue((/** @type {?} */ (elseOperatorOrValue)), (/** @type {?} */ (existing)));
158
- });
79
+ return retrieveValue(elseOperatorOrValue, existing);
80
+ };
159
81
  }
160
82
 
161
83
  /**
162
- * @fileoverview added by tsickle
163
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
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 (/** @type {?} */ (existing));
92
+ return existing;
181
93
  }
182
94
  // Property may be dynamic and might not existed before
183
95
  if (!Array.isArray(existing)) {
184
- return [(/** @type {?} */ (value))];
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 ((/** @type {?} */ (beforePosition)) > 0) {
194
- index = (/** @type {?} */ (beforePosition));
103
+ if (beforePosition > 0) {
104
+ index = beforePosition;
195
105
  }
196
- clone.splice(index, 0, (/** @type {?} */ (value)));
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((/** @type {?} */ (existingPropValue)))
118
+ ? newValue(existingPropValue)
227
119
  : newValue;
228
120
  if (newPropValue !== existingPropValue) {
229
121
  if (!clone) {
230
- clone = Object.assign({}, ((/** @type {?} */ (existing))));
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
- * @fileoverview added by tsickle
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 {?} operatorOrValue - New value under the `selector` index or a
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 (/** @type {?} */ (existing));
147
+ return existing;
267
148
  }
268
- /** @type {?} */
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
- if (isStateOperator(operatorOrValue)) {
273
- value = operatorOrValue((/** @type {?} */ (existing[index])));
152
+ const theOperatorOrValue = operatorOrValue;
153
+ if (isStateOperator(theOperatorOrValue)) {
154
+ value = theOperatorOrValue(existing[index]);
274
155
  }
275
156
  else {
276
- value = operatorOrValue;
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 (/** @type {?} */ (existing));
162
+ return existing;
282
163
  }
283
- /** @type {?} */
284
164
  const clone = existing.slice();
285
- clone[index] = (/** @type {?} */ (value));
165
+ clone[index] = value;
286
166
  return clone;
287
- });
167
+ };
288
168
  }
289
169
 
290
170
  /**
291
- * @fileoverview added by tsickle
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 (/** @type {?} */ (existing));
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
- * @fileoverview added by tsickle
325
- * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
192
+ * @module
193
+ * @description
194
+ * Entry point for all public APIs of this package.
326
195
  */
327
196
 
328
197
  /**
329
- * @fileoverview added by tsickle
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,OAAO,OAAO,KAAK,KAAK,UAAU,CAAC;CACpC;;;;;AAED,SAAgB,WAAW,CAAC,KAAU;IACpC,OAAO,OAAO,KAAK,KAAK,WAAW,CAAC;CACrC;;;;;;AAED,SAAgB,WAAW,CAAI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-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,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;AAC3B,YAAA,OAAO,QAAQ,CAAC,MAAM,CAAE,KAAuC,CAAC,CAAC;AAClE,SAAA;;;AAID,QAAA,OAAQ,KAAwB,CAAC;AACnC,KAAC,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