#69 : Code cleanup

This commit is contained in:
Vadim
2021-09-12 18:55:28 +03:00
parent 0fbf44b04b
commit c21f7fe111
2 changed files with 35 additions and 32 deletions

View File

@@ -2,15 +2,6 @@ import {
getValueInRange, getValueInRange,
} from './math' } from './math'
export function applyParticleSizes({
particlesContainerChildren,
particleWidth,
}) {
for (let particleIndex=0; particleIndex<particlesContainerChildren.length; particleIndex++) {
particlesContainerChildren[particleIndex].style.minWidth = `${particleWidth}px`
particlesContainerChildren[particleIndex].style.maxWidth = `${particleWidth}px`
}
}
// getCurrentPageIndexByCurrentParticleIndex // getCurrentPageIndexByCurrentParticleIndex
@@ -58,24 +49,6 @@ export function getCurrentPageIndexByCurrentParticleIndex({
}) })
} }
// TODO: think about case if particlesCount < particlesToShow and particlesCount < particlesToScroll
export function getPartialPageSize({
particlesToScroll,
particlesToShow,
particlesCountWithoutClones,
}) {
const overlap = particlesToScroll - particlesToShow
let particlesCount = particlesToShow
while(true) {
const diff = particlesCountWithoutClones - particlesCount - overlap
if (diff < particlesToShow) {
return diff
}
particlesCount += particlesToShow + overlap
}
}
// getPagesCountByParticlesCount // getPagesCountByParticlesCount
export function _getPagesCountByParticlesCountInfinite({ export function _getPagesCountByParticlesCountInfinite({
@@ -162,6 +135,34 @@ export function getParticleIndexByPageIndex({
}) })
} }
export function applyParticleSizes({
particlesContainerChildren,
particleWidth,
}) {
for (let particleIndex=0; particleIndex<particlesContainerChildren.length; particleIndex++) {
particlesContainerChildren[particleIndex].style.minWidth = `${particleWidth}px`
particlesContainerChildren[particleIndex].style.maxWidth = `${particleWidth}px`
}
}
// TODO: think about case if particlesCount < particlesToShow and particlesCount < particlesToScroll
export function getPartialPageSize({
particlesToScroll,
particlesToShow,
particlesCountWithoutClones,
}) {
const overlap = particlesToScroll - particlesToShow
let particlesCount = particlesToShow
while(true) {
const diff = particlesCountWithoutClones - particlesCount - overlap
if (diff < particlesToShow) {
return diff
}
particlesCount += particlesToShow + overlap
}
}
export function createResizeObserver(onResize) { export function createResizeObserver(onResize) {
return new ResizeObserver(entries => { return new ResizeObserver(entries => {
onResize({ onResize({

View File

@@ -1,10 +1,12 @@
import { import {
getPartialPageSize, getPartialPageSize,
_getCurrentPageIndexByCurrentParticleIndexInfinite getPartialPageSize,
// getCurrentPageIndex, _getCurrentPageIndexByCurrentParticleIndexInfinite,
// getPagesCountByParticlesCount, _getCurrentPageIndexByCurrentParticleIndexLimited,
// getParticleIndexByPageIndexInfinite, _getPagesCountByParticlesCountInfinite,
// getParticleIndexByPageIndexLimited, _getPagesCountByParticlesCountLimited,
_getParticleIndexByPageIndexInfinite,
_getParticleIndexByPageIndexLimited,
} from './page.js' } from './page.js'
describe('getPartialPageSize', () => { describe('getPartialPageSize', () => {