* Update the items list and re-render
(items: T[])
| 639 | * Update the items list and re-render |
| 640 | */ |
| 641 | updateItems(items: T[]): void { |
| 642 | // Save current scroll position |
| 643 | const currentScrollTop = this.scrollContainer.scrollTop; |
| 644 | |
| 645 | this.items = items; |
| 646 | this.state.totalItems = items.length; |
| 647 | |
| 648 | // Keep existing height measurements - they're usually still valid |
| 649 | // Only clear measurements for indices beyond the new length |
| 650 | const maxIndex = this.itemHeights.size; |
| 651 | for (let i = items.length; i < maxIndex; i++) { |
| 652 | this.itemHeights.delete(i); |
| 653 | } |
| 654 | |
| 655 | // Rebuild position cache with existing measurements |
| 656 | this.rebuildPositionCache(); |
| 657 | |
| 658 | // Clear rendered elements cache since items changed |
| 659 | // This forces fresh cards to be created with updated data |
| 660 | for (const element of this.renderedElements.values()) { |
| 661 | if (this.resizeObserver) { |
| 662 | this.resizeObserver.unobserve(element); |
| 663 | } |
| 664 | } |
| 665 | this.renderedElements.clear(); |
| 666 | this.contentContainer.empty(); |
| 667 | |
| 668 | // Force state reset to trigger re-render at current scroll position |
| 669 | this.state.startIndex = -1; |
| 670 | this.state.endIndex = -1; |
| 671 | |
| 672 | // IMPORTANT: Restore scroll position BEFORE updateVisibleRange |
| 673 | // so it calculates the right visible range |
| 674 | this.scrollContainer.scrollTop = currentScrollTop; |
| 675 | |
| 676 | this.updateVisibleRange(); |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * Return a shallow copy of the current items in render order. |
no test coverage detected