* Removes items from the list-value and, if necessary, * inserts new items in their place, returning the deleted items. \ * Dispatches a new copy of the value, without mutating the current-value. * * It only works if the Unit is not frozen, and \ * either deleteCount is not 0
(start: number, deleteCount: number, ...items: Item[])
| 539 | * @category Customised Array.prototype |
| 540 | */ |
| 541 | splice(start: number, deleteCount: number, ...items: Item[]): Item[] { |
| 542 | // tslint:disable-next-line:triple-equals |
| 543 | if (this.isFrozen || ((deleteCount == 0 || this.isEmpty) && !items.length)) { |
| 544 | return []; |
| 545 | } |
| 546 | this.checkSerializabilityMaybe(items); |
| 547 | |
| 548 | const listShallowCopy = [...this.rawValue()]; |
| 549 | const removedItems = this.deepCopyMaybe( |
| 550 | listShallowCopy.splice(start, deleteCount, ...items.map(item => this.deepCopyMaybe(item))) |
| 551 | ); |
| 552 | this.updateValueAndCache(listShallowCopy); |
| 553 | |
| 554 | if (this.eventsSubject?.observers.length && !this.isMuted) { |
| 555 | this.eventsSubject.next(new EventListUnitSplice(start, deleteCount, removedItems, items)); |
| 556 | } |
| 557 | return removedItems; |
| 558 | } |
| 559 | |
| 560 | /** |
| 561 | * Fills a section of the list-{@link value} with provided param `item`. \ |
no test coverage detected