From 20f996e136912c8553fb52b2e55f8bc0992a2a5c Mon Sep 17 00:00:00 2001 From: Moritz Vetter <16950410+HansAuger@users.noreply.github.com> Date: Thu, 14 Oct 2021 22:27:23 +0000 Subject: [PATCH] refact(kotti-pagination): inline function that calculates center of shown number array --- .../components/PaginationFlexible.vue | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/packages/kotti-ui/source/kotti-pagination/components/PaginationFlexible.vue b/packages/kotti-ui/source/kotti-pagination/components/PaginationFlexible.vue index 350eaf1d1d..1172b37281 100644 --- a/packages/kotti-ui/source/kotti-pagination/components/PaginationFlexible.vue +++ b/packages/kotti-ui/source/kotti-pagination/components/PaginationFlexible.vue @@ -64,16 +64,14 @@ export default defineComponent<{ return baseElementsWidth + BASE_OFFSET * 2 + adjacentPagesOffset }) - const neighborValueCenter = computed(() => { - if (props.currentPage - props.adjacentAmount < 1) - return props.adjacentAmount + 1 - if (props.currentPage + props.adjacentAmount > props.maximumPage - 2) - return props.maximumPage - props.adjacentAmount - 1 - return props.currentPage - }) - const neighborValues = computed(() => { - const center = neighborValueCenter.value + const center = ((): number => { + if (props.currentPage - props.adjacentAmount < 1) + return props.adjacentAmount + 1 + if (props.currentPage + props.adjacentAmount > props.maximumPage - 2) + return props.maximumPage - props.adjacentAmount - 1 + return props.currentPage + })() const start = Math.max(0, center - props.adjacentAmount) const end = Math.min(props.maximumPage, center + props.adjacentAmount) return range(start, end + 1)