Skip to content

refactor: move grid's iron-list fork to a separate module - #321

Merged
tomivirkki merged 33 commits into
masterfrom
virtualizer
May 10, 2021
Merged

tomivirkki merged 33 commits into
masterfrom
virtualizer

Conversation

@tomivirkki

Copy link
Copy Markdown
Member

Fixes #282

@tomivirkki
tomivirkki marked this pull request as draft May 4, 2021 09:47
@tomivirkki
tomivirkki force-pushed the virtualizer branch 4 times, most recently from addbe48 to 23e0486 Compare May 4, 2021 14:02
@vlukashov vlukashov added the no-polymer Removing Polymer from Vaadin public APIs label May 4, 2021
@tomivirkki
tomivirkki force-pushed the virtualizer branch 3 times, most recently from 3861e2d to e5a6a5a Compare May 5, 2021 12:52
@@ -0,0 +1,208 @@
/**

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -0,0 +1,168 @@
/**

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -1,44 +1,27 @@
/**
@license

@tomivirkki tomivirkki May 5, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomivirkki
tomivirkki marked this pull request as ready for review May 5, 2021 14:41
@tomivirkki
tomivirkki requested review from vursen and web-padawan May 6, 2021 07:07

@web-padawan web-padawan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First batch of comments, will continue reviewing later today.

Comment thread packages/vaadin-grid/test/basic.test.js Resolved
while (movingUp.length) {
const idx = movingUp.pop();
this._physicalTop -= this._physicalSizes[idx];
var idx = movingUp.pop();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: restore const.

*/
_increasePoolIfNeeded: function (count) {
const nextPhysicalCount = this._clamp(
var nextPhysicalCount = this._clamp(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably remove the code related to grid mode.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use const here.

Comment on lines +73 to +76
// This workaround is needed until Safari also supports
// ResizeObserver.observe with {box: 'border-box'}
this.__virtualizer.__adapter._resizeHandler();

@tomivirkki tomivirkki May 6, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread packages/vaadin-grid/src/vaadin-grid.js Resolved
Comment thread packages/vaadin-virtual-list/README.md Resolved
Comment thread packages/vaadin-virtual-list/index.html Resolved
clock.restore();
});

function wheel({

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue to add this to @vaadin/testing-helpers vaadin/testing-helpers#6

}

/** @private */
_adjustVirtualIndexOffset(delta) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +156 to +174
get items() {
return {
length: Math.min(this.size, MAX_VIRTUAL_COUNT)
};
}

/** @private */
get offsetHeight() {
return this.scrollTarget.offsetHeight;
}

/** @private */
get $() {
return {
items: this.scrollContainer
};
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +129 to +136
this.scrollToIndex(fvi);

const fviOffsetAfter = this.__getIndexScrollOffset(fvi);
if (fviOffsetBefore !== undefined && fviOffsetAfter !== undefined) {
this._scrollTop += fviOffsetBefore - fviOffsetAfter;
}

@tomivirkki tomivirkki May 6, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 web-padawan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +191 to +193
if (this.grid) {
val = val - (val % this._itemsPerRow);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this block.

Suggested change
if (this.grid) {
val = val - (val % this._itemsPerRow);
}

Comment on lines +209 to +211
if (this.grid) {
val = val - (val % this._itemsPerRow);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this block.

Suggested change
if (this.grid) {
val = val - (val % this._itemsPerRow);
}

*/
get firstVisibleIndex() {
let idx = this._firstVisibleIndexVal;
var idx = this._firstVisibleIndexVal;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore let.

Suggested change
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore let.

Suggested change
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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove grid mode block.

Suggested change
return this.grid ? vidx - (vidx % this._itemsPerRow) : vidx;
return vidx;

Comment on lines +269 to 272
// Handle a partially rendered final row in grid mode
if (this.grid && this._virtualCount - 1 === vidx) {
return vidx - (vidx % this._itemsPerRow);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this block.

Suggested change
// 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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restore let.

Suggested change
var idx = this._lastVisibleIndexVal;
let idx = this._lastVisibleIndexVal;

Comment thread packages/vaadin-grid/test/basic.test.js Resolved
Comment thread packages/vaadin-grid/test/helpers.js Resolved
@vursen

vursen commented May 10, 2021 •

Copy link
Copy Markdown
Contributor

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?

@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 14 Code Smells

No Coverage information No Coverage information
0.8% 0.8% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-polymer Removing Polymer from Vaadin public APIs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract grid's iron-list fork as a separate module

4 participants