Rename vars, code cleanup

This commit is contained in:
Vadim
2021-01-22 19:55:24 +03:00
parent 0470ce313c
commit 905c00cd94
12 changed files with 66 additions and 80 deletions

View File

@@ -1,5 +0,0 @@
import { v4 as uuid } from 'uuid'
export function generateId() {
return uuid()
}

View File

@@ -1,25 +0,0 @@
export function getNextItemIndexLimited(currentItemIndex, length) {
return Math.min(currentItemIndex + 1, length - 1)
}
export function getNextItemIndexInfinte(currentItemIndex, length) {
const newCurrentItemIndex = currentItemIndex + 1
return newCurrentItemIndex > length - 1 ? 0 : newCurrentItemIndex
}
export function getNextItemIndexFn(infinite) {
return infinite ? getNextItemIndexInfinte : getNextItemIndexLimited
}
export function getPrevItemIndexLimited(currentItemIndex, length) {
return Math.max(currentItemIndex - 1, 0)
}
export function getPrevItemIndexInfinte(currentItemIndex, length) {
const newCurrentItemIndex = currentItemIndex - 1
return newCurrentItemIndex >= 0 ? newCurrentItemIndex : length - 1
}
export function getPrevItemIndexFn(infinite) {
return infinite ? getPrevItemIndexInfinte : getPrevItemIndexLimited
}

25
src/utils/page-index.js Normal file
View File

@@ -0,0 +1,25 @@
export function getNextPageIndexLimited(currentPageIndex, pagesCount) {
return Math.min(currentPageIndex + 1, pagesCount - 1)
}
export function getNextPageIndexInfinte(currentPageIndex, pagesCount) {
const newCurrentPageIndex = currentPageIndex + 1
return newCurrentPageIndex > pagesCount - 1 ? 0 : newCurrentPageIndex
}
export function getNextPageIndexFn(infinite) {
return infinite ? getNextPageIndexInfinte : getNextPageIndexLimited
}
export function getPrevPageIndexLimited(currentPageIndex, pagesCount) {
return Math.max(currentPageIndex - 1, 0)
}
export function getPrevPageIndexInfinte(currentPageIndex, pagesCount) {
const newCurrentPageIndex = currentPageIndex - 1
return newCurrentPageIndex >= 0 ? newCurrentPageIndex : pagesCount - 1
}
export function getPrevPageIndexFn(infinite) {
return infinite ? getPrevPageIndexInfinte : getPrevPageIndexLimited
}

View File

@@ -18,14 +18,14 @@ export function getIsNotCompletePage({
}
export function getSlideSize({
contentContainerWidth,
pageWidth,
slidesToShow,
slidesToShowTail,
isNotCompletePage
}) {
return isNotCompletePage
? Math.round(contentContainerWidth/slidesToShowTail)
: Math.round(contentContainerWidth/slidesToShow)
? Math.round(pageWidth/slidesToShowTail)
: Math.round(pageWidth/slidesToShow)
}
export function getPageIndex({ slideIndex, slidesToShow }) {