Skip to content

Commit

Permalink
perf(virtual-grid): don't use throttle function when no throttle is d…
Browse files Browse the repository at this point in the history
…efined
  • Loading branch information
ferferga committed Jan 26, 2023
1 parent 72f470d commit 9ecfeb7
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions frontend/src/components/Layout/VirtualGrid/VirtualGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
:key="visibleItems[i].index"
:item="visibleItems[i].value"
:index="visibleItems[i].index"
:style="visibleItems[i].style" />
:style="visibleItems[i].style"
data-virtualized-grid />
</template>
</component>
</template>
Expand Down Expand Up @@ -203,22 +204,32 @@ function destroyEventListeners(): void {
}
}
watch(fromScrollParent(rootRef), (newValue) => {
destroyEventListeners();
watch(
[fromScrollParent(rootRef), (): number => props.throttleScroll],
(newValue) => {
destroyEventListeners();
if (!isNil(newValue[0])) {
const fn =
props.throttleScroll > 0
? useThrottleFn(() => {
scrollEvents.value++;
}, props.throttleScroll)
: (): void => {
scrollEvents.value++;
};
if (!isNil(newValue)) {
for (const parent of newValue) {
const cleanup = useEventListener(
parent,
'scroll',
useThrottleFn(() => scrollEvents.value++, props.throttleScroll),
{ passive: true, capture: true }
);
for (const parent of newValue[0]) {
const cleanup = useEventListener(parent, 'scroll', fn, {
passive: true,
capture: true
});
eventCleanups.push(cleanup);
eventCleanups.push(cleanup);
}
}
}
});
);
onUnmounted(() => {
destroyEventListeners();
Expand Down

0 comments on commit 9ecfeb7

Please sign in to comment.