* Deletes items at given indices in the list-value. \ * Dispatches a new copy of the value, without mutating the current-value. \ * It doesn't modify the length of the list as these indices are only deleted, not removed. * * It only works if the Unit is not frozen, and * the l
(...indices: number[])
| 266 | * @category Custom ListUnit |
| 267 | */ |
| 268 | delete(...indices: number[]): Item[] { |
| 269 | indices = sanitizeIndices(indices, this.length).filter(i => this.hasOwnProperty(i)); |
| 270 | |
| 271 | if (this.isFrozen || indices.length === 0 || this.isEmpty) { |
| 272 | return []; |
| 273 | } |
| 274 | |
| 275 | const deletedItems = []; |
| 276 | const listShallowCopy = [...this.rawValue()]; |
| 277 | indices.forEach(index => { |
| 278 | deletedItems.push(this.deepCopyMaybe(listShallowCopy[index])); |
| 279 | delete listShallowCopy[index]; |
| 280 | }); |
| 281 | this.updateValueAndCache(listShallowCopy); |
| 282 | |
| 283 | if (this.eventsSubject?.observers.length && !this.isMuted) { |
| 284 | this.eventsSubject.next(new EventListUnitDelete(indices, deletedItems)); |
| 285 | } |
| 286 | return deletedItems; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * Deletes items from the list-{@link value} where the predicate returns `true`. \ |
no test coverage detected