Repository navigation
refactor: move grid's iron-list fork to a separate module - #321
Conversation
addbe48 to
23e0486
Compare
3861e2d to
e5a6a5a
Compare
| @@ -0,0 +1,208 @@ | |||
| /** | |||
There was a problem hiding this comment.
This file is a copy of https://github.com/Polymer/polymer/blob/master/lib/utils/async.js
| @@ -0,0 +1,168 @@ | |||
| /** | |||
There was a problem hiding this comment.
This file is a copy of https://github.com/Polymer/polymer/blob/master/lib/utils/debounce.js
| @@ -1,44 +1,27 @@ | |||
| /** | |||
| @license | |||
There was a problem hiding this comment.
This file is a trimmed copy of https://github.com/PolymerElements/iron-list/blob/master/iron-list.js
web-padawan
left a comment
There was a problem hiding this comment.
First batch of comments, will continue reviewing later today.
| while (movingUp.length) { | ||
| const idx = movingUp.pop(); | ||
| this._physicalTop -= this._physicalSizes[idx]; | ||
| var idx = movingUp.pop(); |
| */ | ||
| _increasePoolIfNeeded: function (count) { | ||
| const nextPhysicalCount = this._clamp( | ||
| var nextPhysicalCount = this._clamp( |
There was a problem hiding this comment.
nit: use let instead of var.
| const delta = nextPhysicalCount - this._physicalCount; | ||
| let nextIncrease = Math.round(this._physicalCount * 0.5); | ||
| nextPhysicalCount = this._convertIndexToCompleteRow(nextPhysicalCount); | ||
| if (this.grid) { |
There was a problem hiding this comment.
We can probably remove the code related to grid mode.
There was a problem hiding this comment.
Can be removed later once we have a conclusion for https://vaadin.slack.com/archives/G01DE1TBFFX/p1619608299042300
| } | ||
| if (delta > 0) { | ||
| const ts = window.performance.now(); | ||
| var ts = window.performance.now(); |
| // This workaround is needed until Safari also supports | ||
| // ResizeObserver.observe with {box: 'border-box'} | ||
| this.__virtualizer.__adapter._resizeHandler(); |
There was a problem hiding this comment.
ResizeObserver observes content-box by default so the padding applied to the row elements above would get ignored by the virtualizer ResizeObserver. Needed to add this temporary, manual _resizehandler invocation via private APIs :/ Once ResizeObserver supports border-box on all supported browsers, we can make virtualizer use it and remove this line.
| clock.restore(); | ||
| }); | ||
|
|
||
| function wheel({ |
There was a problem hiding this comment.
Created an issue to add this to @vaadin/testing-helpers vaadin/testing-helpers#6
| } | ||
|
|
||
| /** @private */ | ||
| _adjustVirtualIndexOffset(delta) { |
There was a problem hiding this comment.
This logic is invoked on "scroll" event and it updates the virtual index offset based on the new scroll position. The logic isn't new but was moved from here
| } | ||
|
|
||
| /** @private */ | ||
| __reorderElements() { |
There was a problem hiding this comment.
This function reorders the physical elements in the DOM. The primary purpose is to maintain the correct tabbing order and a11y. The logic was moved from here
| } | ||
|
|
||
| /** @private */ | ||
| __onWheel(e) { |
There was a problem hiding this comment.
This and the following few functions were moved from here. Their purpose is to support different wheel event delta modes (LINE, PAGE) and also to make wheel scrolling UX nicer; once you reach the end of the scrollable container, its scrollable host container doesn't immediately continue scrolling.
| get items() { | ||
| return { | ||
| length: Math.min(this.size, MAX_VIRTUAL_COUNT) | ||
| }; | ||
| } | ||
|
|
||
| /** @private */ | ||
| get offsetHeight() { | ||
| return this.scrollTarget.offsetHeight; | ||
| } | ||
|
|
||
| /** @private */ | ||
| get $() { | ||
| return { | ||
| items: this.scrollContainer | ||
| }; | ||
| } |
There was a problem hiding this comment.
These properties are directly accessed from the iron-list source code. Didn't want to do modifications to the iron-list source so added the properties here in the adapter instead.
| this.scrollToIndex(fvi); | ||
|
|
||
| const fviOffsetAfter = this.__getIndexScrollOffset(fvi); | ||
| if (fviOffsetBefore !== undefined && fviOffsetAfter !== undefined) { | ||
| this._scrollTop += fviOffsetBefore - fviOffsetAfter; | ||
| } |
There was a problem hiding this comment.
By default, the _itemsChanged invocation above would always reset the scrolltop back to 0. This logic is there to restore the scroll position to what it was before the size change. Logic moved from here
web-padawan
left a comment
There was a problem hiding this comment.
The iron-list cleaup was previously done as part of P3 conversion, see vaadin/vaadin-grid@3fab53c and vaadin/vaadin-grid@3bbdf8e. Added some comments related to grid mode removal. These aren't blockers.
| if (this.grid) { | ||
| val = val - (val % this._itemsPerRow); | ||
| } |
There was a problem hiding this comment.
Remove this block.
| if (this.grid) { | |
| val = val - (val % this._itemsPerRow); | |
| } |
| if (this.grid) { | ||
| val = val - (val % this._itemsPerRow); | ||
| } |
There was a problem hiding this comment.
Remove this block.
| if (this.grid) { | |
| val = val - (val % this._itemsPerRow); | |
| } |
| */ | ||
| get firstVisibleIndex() { | ||
| let idx = this._firstVisibleIndexVal; | ||
| var idx = this._firstVisibleIndexVal; |
There was a problem hiding this comment.
Restore let.
| var idx = this._firstVisibleIndexVal; | |
| let idx = this._firstVisibleIndexVal; |
| var idx = this._firstVisibleIndexVal; | ||
| if (idx == null) { | ||
| let physicalOffset = this._physicalTop + this._scrollOffset; | ||
| var physicalOffset = this._physicalTop + this._scrollOffset; |
There was a problem hiding this comment.
Restore let.
| var physicalOffset = this._physicalTop + this._scrollOffset; | |
| let physicalOffset = this._physicalTop + this._scrollOffset; |
|
|
||
| if (physicalOffset > this._scrollPosition) { | ||
| return vidx; | ||
| return this.grid ? vidx - (vidx % this._itemsPerRow) : vidx; |
There was a problem hiding this comment.
Remove grid mode block.
| return this.grid ? vidx - (vidx % this._itemsPerRow) : vidx; | |
| return vidx; |
| // Handle a partially rendered final row in grid mode | ||
| if (this.grid && this._virtualCount - 1 === vidx) { | ||
| return vidx - (vidx % this._itemsPerRow); | ||
| } |
There was a problem hiding this comment.
Remove this block.
| // Handle a partially rendered final row in grid mode | |
| if (this.grid && this._virtualCount - 1 === vidx) { | |
| return vidx - (vidx % this._itemsPerRow); | |
| } |
| */ | ||
| get lastVisibleIndex() { | ||
| let idx = this._lastVisibleIndexVal; | ||
| var idx = this._lastVisibleIndexVal; |
There was a problem hiding this comment.
Restore let.
| var idx = this._lastVisibleIndexVal; | |
| let idx = this._lastVisibleIndexVal; |
Co-authored-by: Serhii Kulykov <iamkulykov@gmail.com>
|
From my perspective, I don't see anything else to add more, so the PR looks good to me. Actually, I'm impressed with how much work has been done here. 👍 P.S. @tomivirkki Seems that several tests are failed... are you already aware of that? |
|
Kudos, SonarCloud Quality Gate passed!
|
Fixes #282