dom: batch dom operations that trigger layout calculation

panel: store raw scroll when scrolling and use that value when the editor needs it (avoids many layout trashing)
This commit is contained in:
jean-emmanuel 2022-01-20 19:21:42 +01:00
parent 2225a3f760
commit 876c3277b2
8 changed files with 137 additions and 98 deletions

View file

@ -1,37 +1,42 @@
var fastdom = require('fastdom')
var elements = []
function checkResizes(context, force){
// Iterate over all elements to which the 'resize' event is bound.
var resizedElems = [],
cachedStyles = []
for (let i = elements.length - 1; i >= 0; i--) {
var elem = elements[i]
fastdom.measure(()=>{
// Iterate over all elements to which the 'resize' event is bound.
let resizedElems = [],
cachedStyles = []
for (let i = elements.length - 1; i >= 0; i--) {
var elem = elements[i]
if (!context.contains(elem)) continue
if (!context.contains(elem)) continue
var style = window.getComputedStyle(elem),
width = parseInt(style['width']) - parseInt(style['padding-left']) - parseInt(style['padding-right']),
height = parseInt(style['height']) - parseInt(style['padding-top']) - parseInt(style['padding-bottom'])
var style = window.getComputedStyle(elem),
width = parseInt(style['width']) - parseInt(style['padding-left']) - parseInt(style['padding-right']),
height = parseInt(style['height']) - parseInt(style['padding-top']) - parseInt(style['padding-bottom'])
if (!width || !height) continue
if (!width || !height) continue
// If element size has changed since the last time, update the element
// data store and trigger the 'resize' event.
if (force || width != elem.resizedataw || height != elem.resizedatah) {
elem.resizedataw = width
elem.resizedatah = height
resizedElems.push(elem)
cachedStyles.push(style)
// If element size has changed since the last time, update the element
// data store and trigger the 'resize' event.
if (force || width != elem.resizedataw || height != elem.resizedatah) {
elem.resizedataw = width
elem.resizedatah = height
resizedElems.push(elem)
cachedStyles.push(style)
}
}
}
for (let i = resizedElems.length - 1; i >= 0; i--) {
resizedElems[i]._resize_widget.trigger('resize', {
width: resizedElems[i].resizedataw,
height: resizedElems[i].resizedatah,
style:cachedStyles[i],
stopPropagation: true
fastdom.mutate(()=>{
for (let i = resizedElems.length - 1; i >= 0; i--) {
resizedElems[i]._resize_widget.trigger('resize', {
width: resizedElems[i].resizedataw,
height: resizedElems[i].resizedatah,
style:cachedStyles[i],
stopPropagation: true
})
}
})
}
})
}