From 85a2fc06c168a2870374c6b8f29699262ace607d Mon Sep 17 00:00:00 2001 From: Tomi Virkki Date: Mon, 15 Oct 2018 14:30:58 +0300 Subject: [PATCH] Don't throw with large size --- src/vaadin-combo-box-data-provider-mixin.html | 12 ++++++------ test/lazy-loading.html | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/vaadin-combo-box-data-provider-mixin.html b/src/vaadin-combo-box-data-provider-mixin.html index 8ee8abfe9..f3186e7a2 100644 --- a/src/vaadin-combo-box-data-provider-mixin.html +++ b/src/vaadin-combo-box-data-provider-mixin.html @@ -175,12 +175,12 @@ } } - _sizeChanged(size) { - const filteredItems = this.filteredItems || []; - filteredItems.length = size || 0; - this.filteredItems = new Array(...filteredItems).map(item => { - return item !== undefined ? item : new Vaadin.ComboBoxPlaceholder(); - }); + _sizeChanged(size = 0) { + const filteredItems = (this.filteredItems || []).slice(0); + for (let i = 0; i < size; i++) { + filteredItems[i] = filteredItems[i] !== undefined ? filteredItems[i] : new Vaadin.ComboBoxPlaceholder(); + } + this.filteredItems = filteredItems; } _pageSizeChanged(pageSize, oldPageSize) { diff --git a/test/lazy-loading.html b/test/lazy-loading.html index 7506bdf5c..b144fde8f 100644 --- a/test/lazy-loading.html +++ b/test/lazy-loading.html @@ -88,6 +88,10 @@ expect(spyDataProvider).to.be.calledOnce; }); + it('should not throw with large size', () => { + expect(() => comboBox.size = 500000).not.to.throw(Error); + }); + it('should throw if set after items', () => { comboBox.items = ['foo']; function setDataProvider() {