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 6656a89f18
commit 554b219d62
1 changed files with 17 additions and 14 deletions

View File

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