Skip to content

feat(virtual-scroll): change fixed strategy to use min & max buffer #12557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 13, 2018

Conversation

mmalerba
Copy link
Contributor

@mmalerba mmalerba commented Aug 7, 2018

No description provided.

@mmalerba mmalerba added the target: major This PR is targeted for the next major release label Aug 7, 2018
@mmalerba mmalerba requested review from jelbourn and crisbeto August 7, 2018 00:10
@mmalerba mmalerba requested a review from andrewseguin as a code owner August 7, 2018 00:10
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Aug 7, 2018
if (!this._viewport) {
return {...range};
const firstVisibleIndex = scrollOffset / this._itemSize;
const range = {...this._viewport.getRenderedRange()};
Copy link
Member

Choose a reason for hiding this comment

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

The spread here transpiles to a for...in loop with some logic in it. Since this method is being while scrolling, it might a good idea if we just constructed the range here ourselves, also consider that it's only two properties.

range.start = Math.max(0, range.start - expandStart);
range.end = Math.min(this._viewport.getDataLength(),
Math.ceil(firstVisibleIndex +
(this._viewport.getViewportSize() + this._minBufferPx) / this._itemSize));
Copy link
Member

Choose a reason for hiding this comment

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

You're doing a couple of calls to getViewportSize and getDataLength in both the if and else. Consider moving them out into constants.

The fixed size strategy also supports setting the buffer size, i.e. the number of items rendered
beyond the edge of the viewport. This can be adjusted by setting the `bufferSize` input. If
`bufferSize` is not specified it defaults to 5 items.
The fixed size strategy also supports setting a couple buffer parameters that determine how much
Copy link
Member

Choose a reason for hiding this comment

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

"a couple" -> "a couple of"

.subscribe(observer));
@Output() scrolledIndexChange: Observable<number> = Observable.create(observer =>
this._scrollStrategy.scrolledIndexChange.subscribe(index =>
Promise.resolve().then(() => this._ngZone.run(() => observer.next(index)))));
Copy link
Member

Choose a reason for hiding this comment

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

AFAIK you shouldn't need the NgZone.run here due to the Promise.resolve.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the case even if scrolledIndexChange emits outside the NgZone? because I think it does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I confirmed that it does need the .run in this case


**`minBufferPx`** determines the minimum space outside virtual scrolling viewport that will be
filled with content. Increasing this will increase the amount of content a user will see before more
content must be rendered. However, too large a value will cause more content to be rendered than is
necessary.

**`addBufferPx`** determines the amount of content that will be added incrementally as the viewport
**`maxBufferPx`** determines the amount of content that will be added incrementally as the viewport
is scrolled. This should be greater than the size of `minBufferPx` so that one "render" is needed at
Copy link
Member

Choose a reason for hiding this comment

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

Should we throw an error if the minimum is greater than the maximum?

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM aside from @crisbeto's comments

@jelbourn jelbourn added pr: lgtm action: merge The PR is ready for merge by the caretaker and removed action: merge The PR is ready for merge by the caretaker labels Aug 7, 2018
@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Aug 7, 2018
@mmalerba mmalerba merged commit ba84d5b into angular:master Aug 13, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants