54
loading...
This website collects cookies to deliver better user experience
const createContinuousNumbers = (start, end) => {
if (start === end) return [start]
return [start, ...createContinuousNumbers(start + 1, end)]
}
const moveSlideToRight = (slide, step = 1) => {
return slide.map(pageNumber => pageNumber + step)
}
const moveSlideToLeft = (slide, step = 1) => {
return slide.map(pageNumber => pageNumber - step)
}
const getMaxPageNumberFromSlide = (slide) => Math.max(...slide)
const getMinPageNumberFromSlide = (slide) => Math.min(...slide)
out of range
area we can use one function to validate the page number. The over leftmost
and over rightmost
need to be handled by 2 functions to decide the slide should move right or leftconst isOverLeftmostOfSlide = (pageNumber, slide) => {
return pageNumber < getMinPageNumberFromSlide(slide)
}
const isOverRightmostOfSlide = (pageNumber, slide) => {
return pageNumber > getMaxPageNumberFromSlide(slide)
}
const isOutOfRange = (min, max) => pageNumber => {
return pageNumber < min || pageNumber > max
}
goTo
because the next
function equal goTo(currentPage + 1)
, prev
function equal goTo(currentPage - 1)
, last
function equal goTo(lastPage)
and first
function equal goTo(1)
const totalPage = 20
const slideWidth = 4
const currentPage = 1
const pagination = Pagination(currentPage, totalPage, slideWidth)
// { partition: [ [ 1, 2, 3, 4 ], [ 20 ] ], currentPage: 1 }
pagination.getState()
// { partition: [ [ 1, 2, 3, 4 ], [ 20 ] ], currentPage: 2 }
pagination
.next()
.getState()
//{ partition: [ [ 1, 2, 3, 4 ], [ 20 ] ], currentPage: 1 }
pagination
.next()
.prev()
.getState()
goTo
function.