Use requestAnimationFrame for DND overlay placeholder updates to further improve performance

This commit is contained in:
Andrew Kingston 2022-10-17 08:48:32 +01:00
parent 0378e06550
commit 8c1c84e9aa
1 changed files with 17 additions and 14 deletions

View File

@ -1,24 +1,27 @@
<script>
import { onMount } from "svelte"
import { DNDPlaceholderID } from "constants"
import { domDebounce } from "utils/domDebounce.js"
let left, top, height, width
onMount(() => {
const interval = setInterval(() => {
const node = document.getElementById(DNDPlaceholderID)
if (!node) {
height = 0
width = 0
} else {
const bounds = node.getBoundingClientRect()
left = bounds.left
top = bounds.top
height = bounds.height
width = bounds.width
}
}, 100)
const updatePosition = () => {
const node = document.getElementById(DNDPlaceholderID)
if (!node) {
height = 0
width = 0
} else {
const bounds = node.getBoundingClientRect()
left = bounds.left
top = bounds.top
height = bounds.height
width = bounds.width
}
}
const debouncedUpdate = domDebounce(updatePosition)
onMount(() => {
const interval = setInterval(debouncedUpdate, 100)
return () => {
clearInterval(interval)
}