#69 : Remove unnecessary fns
This commit is contained in:
@@ -131,6 +131,7 @@
|
|||||||
infinite,
|
infinite,
|
||||||
pageIndex,
|
pageIndex,
|
||||||
clonesCountHead: clonesCount.head,
|
clonesCountHead: clonesCount.head,
|
||||||
|
clonesCountTail: clonesCount.tail,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
particlesCount,
|
particlesCount,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
@@ -292,6 +293,7 @@
|
|||||||
infinite,
|
infinite,
|
||||||
pageIndex: initialPageIndex,
|
pageIndex: initialPageIndex,
|
||||||
clonesCountHead: clonesCount.head,
|
clonesCountHead: clonesCount.head,
|
||||||
|
clonesCountTail: clonesCount.tail,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
particlesCount,
|
particlesCount,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
@@ -314,6 +316,7 @@
|
|||||||
infinite,
|
infinite,
|
||||||
pageIndex,
|
pageIndex,
|
||||||
clonesCountHead: clonesCount.head,
|
clonesCountHead: clonesCount.head,
|
||||||
|
clonesCountTail: clonesCount.tail,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
particlesCount,
|
particlesCount,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
@@ -376,8 +379,12 @@
|
|||||||
await changePage(
|
await changePage(
|
||||||
() => store.prev({
|
() => store.prev({
|
||||||
infinite,
|
infinite,
|
||||||
particlesCount,
|
currentPageIndex,
|
||||||
|
clonesCountHead: clonesCount.head,
|
||||||
|
clonesCountTail: clonesCount.tail,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
|
particlesCount,
|
||||||
|
particlesToShow,
|
||||||
}),
|
}),
|
||||||
options,
|
options,
|
||||||
)
|
)
|
||||||
@@ -387,9 +394,11 @@
|
|||||||
await changePage(
|
await changePage(
|
||||||
() => store.next({
|
() => store.next({
|
||||||
infinite,
|
infinite,
|
||||||
|
currentPageIndex,
|
||||||
particlesCount,
|
particlesCount,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
|
clonesCountHead: clonesCount.head,
|
||||||
clonesCountTail: clonesCount.tail,
|
clonesCountTail: clonesCount.tail,
|
||||||
}),
|
}),
|
||||||
options,
|
options,
|
||||||
|
|||||||
33
src/store.js
33
src/store.js
@@ -2,8 +2,7 @@ import {
|
|||||||
writable,
|
writable,
|
||||||
} from 'svelte/store';
|
} from 'svelte/store';
|
||||||
import {
|
import {
|
||||||
getNextParticleIndexFn,
|
getParticleIndexByPageIndex,
|
||||||
getPrevParticleIndexFn,
|
|
||||||
} from './utils/page'
|
} from './utils/page'
|
||||||
import {
|
import {
|
||||||
getValueInRange,
|
getValueInRange,
|
||||||
@@ -37,18 +36,22 @@ function createStore() {
|
|||||||
|
|
||||||
function next({
|
function next({
|
||||||
infinite,
|
infinite,
|
||||||
|
currentPageIndex,
|
||||||
particlesCount,
|
particlesCount,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
|
clonesCountHead,
|
||||||
clonesCountTail,
|
clonesCountTail,
|
||||||
}) {
|
}) {
|
||||||
update(store => {
|
update(store => {
|
||||||
const newCurrentParticleIndex = getNextParticleIndexFn(infinite)({
|
const newCurrentParticleIndex = getParticleIndexByPageIndex({
|
||||||
currentParticleIndex: store.currentParticleIndex,
|
infinite,
|
||||||
particlesCount,
|
pageIndex: currentPageIndex + 1,
|
||||||
particlesToScroll,
|
clonesCountHead,
|
||||||
particlesToShow,
|
|
||||||
clonesCountTail,
|
clonesCountTail,
|
||||||
|
particlesToScroll,
|
||||||
|
particlesCount,
|
||||||
|
particlesToShow,
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
...store,
|
...store,
|
||||||
@@ -59,14 +62,22 @@ function createStore() {
|
|||||||
|
|
||||||
function prev({
|
function prev({
|
||||||
infinite,
|
infinite,
|
||||||
particlesCount,
|
currentPageIndex,
|
||||||
|
clonesCountHead,
|
||||||
|
clonesCountTail,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
|
particlesCount,
|
||||||
|
particlesToShow,
|
||||||
}) {
|
}) {
|
||||||
update(store => {
|
update(store => {
|
||||||
const newCurrentParticleIndex = getPrevParticleIndexFn(infinite)({
|
const newCurrentParticleIndex = getParticleIndexByPageIndex({
|
||||||
currentParticleIndex: store.currentParticleIndex,
|
infinite,
|
||||||
particlesCount,
|
pageIndex: currentPageIndex - 1,
|
||||||
|
clonesCountHead,
|
||||||
|
clonesCountTail,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
|
particlesCount,
|
||||||
|
particlesToShow,
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
...store,
|
...store,
|
||||||
|
|||||||
@@ -2,58 +2,6 @@ import {
|
|||||||
getValueInRange,
|
getValueInRange,
|
||||||
} from './math'
|
} from './math'
|
||||||
|
|
||||||
export function getNextParticleIndexLimited({
|
|
||||||
currentParticleIndex,
|
|
||||||
particlesCount,
|
|
||||||
particlesToScroll,
|
|
||||||
particlesToShow,
|
|
||||||
}) {
|
|
||||||
if (particlesCount < 1) throw new Error('particlesCount must be at least 1')
|
|
||||||
return getValueInRange(0, currentParticleIndex + particlesToScroll, particlesCount - particlesToShow)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getNextParticleIndexInfinte({
|
|
||||||
currentParticleIndex,
|
|
||||||
particlesCount,
|
|
||||||
particlesToScroll,
|
|
||||||
clonesCountTail,
|
|
||||||
}) {
|
|
||||||
if (particlesCount < 1) throw new Error('particlesCount must be at least 1')
|
|
||||||
const newCurrentParticleIndex = Math.max(currentParticleIndex, 0) + Math.min(particlesCount - clonesCountTail - currentParticleIndex, particlesToScroll)
|
|
||||||
return newCurrentParticleIndex > particlesCount - 1 ? 0 : Math.max(newCurrentParticleIndex, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getNextParticleIndexFn(infinite) {
|
|
||||||
return infinite ? getNextParticleIndexInfinte : getNextParticleIndexLimited
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPrevParticleIndexLimited({
|
|
||||||
currentParticleIndex,
|
|
||||||
particlesCount,
|
|
||||||
particlesToScroll,
|
|
||||||
}) {
|
|
||||||
if (particlesCount < 1) throw new Error('particlesCount must be at least 1')
|
|
||||||
return getValueInRange(
|
|
||||||
0,
|
|
||||||
currentParticleIndex - Math.min(currentParticleIndex, particlesToScroll),
|
|
||||||
particlesCount - 1
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPrevParticleIndexInfinte({
|
|
||||||
currentParticleIndex,
|
|
||||||
particlesCount,
|
|
||||||
particlesToScroll,
|
|
||||||
}) {
|
|
||||||
if (particlesCount < 1) throw new Error('particlesCount must be at least 1')
|
|
||||||
const newCurrentParticleIndex = Math.min(currentParticleIndex, particlesCount - 1) - Math.min(currentParticleIndex, particlesToScroll)
|
|
||||||
return newCurrentParticleIndex >= 0 ? Math.min(newCurrentParticleIndex, particlesCount - 1) : particlesCount - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPrevParticleIndexFn(infinite) {
|
|
||||||
return infinite ? getPrevParticleIndexInfinte : getPrevParticleIndexLimited
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getSizes({
|
export function getSizes({
|
||||||
pageWindowElement,
|
pageWindowElement,
|
||||||
particlesContainerChildren,
|
particlesContainerChildren,
|
||||||
@@ -123,15 +71,54 @@ export function getPagesCountByParticlesCount({
|
|||||||
: Math.round(particlesCountWithoutClones / particlesToScroll)
|
: Math.round(particlesCountWithoutClones / particlesToScroll)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getParticleIndexByPageIndexInfinite({
|
||||||
|
pageIndex,
|
||||||
|
clonesCountHead,
|
||||||
|
clonesCountTail,
|
||||||
|
particlesToScroll,
|
||||||
|
particlesCount,
|
||||||
|
}) {
|
||||||
|
return getValueInRange(
|
||||||
|
clonesCountHead,
|
||||||
|
Math.min(clonesCountHead + pageIndex * particlesToScroll, particlesCount - clonesCountTail),
|
||||||
|
particlesCount - 1
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getParticleIndexByPageIndexLimited({
|
||||||
|
pageIndex,
|
||||||
|
particlesToScroll,
|
||||||
|
particlesCount,
|
||||||
|
particlesToShow,
|
||||||
|
}) {
|
||||||
|
return getValueInRange(
|
||||||
|
0,
|
||||||
|
Math.min(pageIndex * particlesToScroll, particlesCount - particlesToShow),
|
||||||
|
particlesCount - 1
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function getParticleIndexByPageIndex({
|
export function getParticleIndexByPageIndex({
|
||||||
infinite,
|
infinite,
|
||||||
pageIndex,
|
pageIndex,
|
||||||
clonesCountHead,
|
clonesCountHead,
|
||||||
|
clonesCountTail,
|
||||||
particlesToScroll,
|
particlesToScroll,
|
||||||
particlesCount,
|
particlesCount,
|
||||||
particlesToShow,
|
particlesToShow,
|
||||||
}) {
|
}) {
|
||||||
return infinite
|
return infinite
|
||||||
? clonesCountHead + pageIndex * particlesToScroll
|
? getParticleIndexByPageIndexInfinite({
|
||||||
: Math.min(pageIndex * particlesToScroll, particlesCount - particlesToShow)
|
pageIndex,
|
||||||
|
clonesCountHead,
|
||||||
|
clonesCountTail,
|
||||||
|
particlesToScroll,
|
||||||
|
particlesCount,
|
||||||
|
})
|
||||||
|
: getParticleIndexByPageIndexLimited({
|
||||||
|
pageIndex,
|
||||||
|
particlesToScroll,
|
||||||
|
particlesCount,
|
||||||
|
particlesToShow,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user