* Removes the first item from the list-value and returns it. \ * Dispatches a new copy of the value, without mutating the current-value. * * It only works if the Unit is not frozen, and the list is not empty isEmpty. * * @returns The shifted item. * * @triggers {
()
| 480 | * @category Customised Array.prototype |
| 481 | */ |
| 482 | shift(): Item | undefined { |
| 483 | if (this.isFrozen || this.isEmpty) { |
| 484 | return; |
| 485 | } |
| 486 | const listShallowCopy = [...this.rawValue()]; |
| 487 | const shiftedItem = this.deepCopyMaybe(listShallowCopy.shift()); |
| 488 | this.updateValueAndCache(listShallowCopy); |
| 489 | |
| 490 | if (this.eventsSubject?.observers.length && !this.isMuted) { |
| 491 | this.eventsSubject.next(new EventListUnitShift(shiftedItem)); |
| 492 | } |
| 493 | return shiftedItem; |
| 494 | } |
| 495 | |
| 496 | /** |
| 497 | * Inserts new items at the start of the list-{@link value}. \ |
no test coverage detected