Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Aug 2, 2023
1 parent df07513 commit a509cd9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const findIndex = (
}
}

return min(max(i, 0), cache._length - 1);
return min(cache._length - 1, max(0, i));
};

export const findStartIndexWithOffset = (
Expand Down
2 changes: 1 addition & 1 deletion src/core/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const createScroller = (
scrollManually(store._getItemIndexForScrollTo(offset), () => offset);
},
_scrollToIndex(index) {
index = max(min(index, store._getItemLength() - 1), 0);
index = min(store._getItemLength() - 1, max(0, index));

scrollManually(index, () => store._getItemOffset(index));
},
Expand Down
2 changes: 1 addition & 1 deletion src/core/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export const createVirtualStore = (
}

// Scroll offset may exceed min or max especially in Safari's elastic scrolling.
scrollOffset = max(0, min(getScrollOffsetMax(), payload));
scrollOffset = min(getScrollOffsetMax(), max(0, payload));
mutated += UPDATE_SCROLL;
break;
}
Expand Down

0 comments on commit a509cd9

Please sign in to comment.