Skip to content

Commit

Permalink
refactor: make class functions private
Browse files Browse the repository at this point in the history
  • Loading branch information
orefalo committed Oct 14, 2024
1 parent 8f0f52c commit bf42c68
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
!.env.example
*.log
.eslintcache
vite.config.js.timestamp-*
vite.config.js.timestamp-*
.idea
15 changes: 6 additions & 9 deletions src/lib/SizeAndPositionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ export default class SizeAndPositionManager {
}
}

checkForMismatchItemSizeAndItemCount() {
private checkForMismatchItemSizeAndItemCount() {
if (Array.isArray(this.itemSize) && this.itemSize.length < this.modelCount) {
throw Error(`When itemSize is an array, itemSize.length can't be smaller than itemCount`);
}
}

getSize(index: number) {
private getSize(index: number) {
const { itemSize } = this;

if (typeof itemSize === 'function') {
Expand Down Expand Up @@ -96,9 +96,6 @@ export default class SizeAndPositionManager {
this.totalSize = totalSize;
}

getLastMeasuredIndex() {
return this.lastMeasuredIndex;
}

/**
* This method returns the size and position for the item at the specified index.
Expand All @@ -118,7 +115,7 @@ export default class SizeAndPositionManager {
* This is used when itemSize is a function.
* just-in-time calculates (or used cached values) for items leading up to the index.
*/
getJustInTimeSizeAndPositionForIndex(index: number) {
private getJustInTimeSizeAndPositionForIndex(index: number) {
if (index > this.lastMeasuredIndex) {
const lastMeasuredSizeAndPosition = this.getSizeAndPositionOfLastMeasuredItem();
let offset = lastMeasuredSizeAndPosition.offset + lastMeasuredSizeAndPosition.size;
Expand All @@ -144,13 +141,13 @@ export default class SizeAndPositionManager {
return this.itemSizeAndPositionData[index];
}

getSizeAndPositionOfLastMeasuredItem() {
private getSizeAndPositionOfLastMeasuredItem() {
return this.lastMeasuredIndex >= 0
? this.itemSizeAndPositionData[this.lastMeasuredIndex]
: { offset: 0, size: 0 };
}

getEstimatedItemSize(): number {
private getEstimatedItemSize(): number {
return this.estimatedItemSize || (typeof this.itemSize === 'number' && this.itemSize) || 50;
}

Expand Down Expand Up @@ -273,7 +270,7 @@ export default class SizeAndPositionManager {
* This allows partially visible items (with offsets just before/above the fold) to be visible.
*
*/
findNearestItem(offset: number): number {
private findNearestItem(offset: number): number {
if (isNaN(offset)) {
throw Error(`Invalid offset ${offset} specified`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/VirtualList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
onVisibleRangeUpdate,
onAfterScroll,
// dom
// css
class: className = '',
style = '',

Check warning on line 76 in src/lib/VirtualList.svelte

View workflow job for this annotation

GitHub Actions / tests

'style' is assigned a value but never used. Allowed unused vars must match /^_/u
Expand Down
2 changes: 1 addition & 1 deletion src/routes/examples/positioning2/code.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
{scrollToAlignment}
{scrollToBehaviour}
onVisibleRangeUpdate={handleMessage}>
{#snippet slot({ item: _item, style, index }: VirtualListModel<any>)}
{#snippet slot({ item: _item, style, index })}
<div class="row" {style} class:highlighted={index === scrollToIndex}>
Item #{index}
</div>
Expand Down

0 comments on commit bf42c68

Please sign in to comment.