* Removes items at given indices from the list-value. \ * Dispatches a new copy of the value, without mutating the current-value. \ * It modifies the length of the list as these indices are not deleted, * rather removed using `Array.prototype.splice`. * * It only works if the
(...indices: number[])
| 193 | * @category Custom ListUnit |
| 194 | */ |
| 195 | remove(...indices: number[]): Item[] { |
| 196 | const listLength = this.length; |
| 197 | indices = sanitizeIndices(indices, listLength).filter(i => this.hasOwnProperty(i)); |
| 198 | |
| 199 | if (this.isFrozen || !indices.length || this.isEmpty) { |
| 200 | return []; |
| 201 | } |
| 202 | |
| 203 | indices.sort().reverse(); |
| 204 | const removedItems = []; |
| 205 | const listShallowCopy = [...this.rawValue()]; |
| 206 | |
| 207 | indices.forEach(index => { |
| 208 | removedItems.push(...this.deepCopyMaybe(listShallowCopy.splice(index, 1))); |
| 209 | }); |
| 210 | this.updateValueAndCache(listShallowCopy); |
| 211 | removedItems.reverse(); |
| 212 | |
| 213 | if (this.eventsSubject?.observers.length && !this.isMuted) { |
| 214 | this.eventsSubject.next(new EventListUnitRemove(indices, removedItems)); |
| 215 | } |
| 216 | return removedItems; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Removes items from the list-{@link value} where the predicate returns `truthy` value. \ |