mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-29 11:31:32 +00:00
re-enable observer for moved elements (#4486)
Signed-off-by: Danil Uzlov <danil.uzlov@xored.com>
This commit is contained in:
parent
7f7242b9de
commit
075b362c1c
@ -7,7 +7,6 @@ const delayedCaller = new DelayedCaller(5)
|
||||
function makeObserver (rootMargin: string): IntersectionObserver {
|
||||
const entriesPending = new Map<Element, { isIntersecting: boolean }>()
|
||||
const notifyObservers = (observer: IntersectionObserver): void => {
|
||||
console.log('notifyObservers', entriesPending.size)
|
||||
for (const [target, entry] of entriesPending.entries()) {
|
||||
const entryData = entryMap.get(target)
|
||||
if (entryData == null) {
|
||||
@ -69,12 +68,26 @@ export function lazyObserver (node: Element, onVisible: (value: boolean, unsubsc
|
||||
return {}
|
||||
}
|
||||
|
||||
const destroy = listen('20%', node, (isIntersecting) => {
|
||||
visible = isIntersecting
|
||||
onVisible(visible, destroy)
|
||||
})
|
||||
let needsUpdate = true
|
||||
let destroy = (): void => {}
|
||||
// we need this update function to re-trigger observer for moved elements
|
||||
// moved elements are relevant because onVisible can have side effects
|
||||
const update = (): void => {
|
||||
if (!needsUpdate) {
|
||||
return
|
||||
}
|
||||
needsUpdate = false
|
||||
destroy()
|
||||
destroy = listen('20%', node, (isIntersecting) => {
|
||||
visible = isIntersecting
|
||||
needsUpdate = visible
|
||||
onVisible(visible, destroy)
|
||||
})
|
||||
}
|
||||
update()
|
||||
|
||||
return {
|
||||
destroy
|
||||
destroy,
|
||||
update
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user