Use requestAnimationFrame for DND overlay placeholder updates to further improve performance
This commit is contained in:
parent
0378e06550
commit
8c1c84e9aa
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue