guard against NPEs for IntersectionObserver
This commit is contained in:
parent
2a215480e2
commit
0a7f56004f
|
@ -14,25 +14,31 @@ class AsyncLayout {
|
|||
}
|
||||
|
||||
observe(key, node, callback) {
|
||||
if (this._intersectionObserver) {
|
||||
this._onIntersectionCallbacks[key] = (entry) => {
|
||||
callback(getRectFromEntry(entry))
|
||||
this.unobserve(key, node)
|
||||
}
|
||||
this._intersectionObserver.observe(node)
|
||||
}
|
||||
}
|
||||
|
||||
unobserve(key, node) {
|
||||
if (key in this._onIntersectionCallbacks) {
|
||||
return
|
||||
}
|
||||
if (this._intersectionObserver) {
|
||||
this._intersectionObserver.unobserve(node)
|
||||
}
|
||||
delete this._onIntersectionCallbacks[key]
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
if (this._intersectionObserver) {
|
||||
this._intersectionObserver.disconnect()
|
||||
this._intersectionObserver = null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { AsyncLayout }
|
Loading…
Reference in a new issue