mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-05 15:24:22 +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 {
|
function makeObserver (rootMargin: string): IntersectionObserver {
|
||||||
const entriesPending = new Map<Element, { isIntersecting: boolean }>()
|
const entriesPending = new Map<Element, { isIntersecting: boolean }>()
|
||||||
const notifyObservers = (observer: IntersectionObserver): void => {
|
const notifyObservers = (observer: IntersectionObserver): void => {
|
||||||
console.log('notifyObservers', entriesPending.size)
|
|
||||||
for (const [target, entry] of entriesPending.entries()) {
|
for (const [target, entry] of entriesPending.entries()) {
|
||||||
const entryData = entryMap.get(target)
|
const entryData = entryMap.get(target)
|
||||||
if (entryData == null) {
|
if (entryData == null) {
|
||||||
@ -69,12 +68,26 @@ export function lazyObserver (node: Element, onVisible: (value: boolean, unsubsc
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const destroy = listen('20%', node, (isIntersecting) => {
|
let needsUpdate = true
|
||||||
visible = isIntersecting
|
let destroy = (): void => {}
|
||||||
onVisible(visible, destroy)
|
// 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 {
|
return {
|
||||||
destroy
|
destroy,
|
||||||
|
update
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user