You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose that we have created an IntersectionObserver and we give the observer a large array of elements to observe by iterating through the array and observing each element.
for (let target of list) {
observer.observe(target);
}
Is it guaranteed that when the callback is executed the first time it will include all entries that are being observed in a single callback (as opposed to queuing multiple callbacks with a subset of the original array)?
To clarify, if the above holds true, then in the below example, the line console.log(entries.length, target.length); will never be reached with the first callback - but will be reached with subsequent callbacks.
let list = document.querySelectorAll('li');
const observer = new IntersectionObserver((entries, observer) => {
if (entries.length !== list.length) {
// this statement will never be reached with the first callback
console.log(entries.length, list.length);
}
});
for (let target of list) {
observer.observe(target);
}
Please excuse me if this is not the appropriate place to ask and I will close the issue.
The text was updated successfully, but these errors were encountered:
kevinfarrugia
changed the title
Will IntersectionObserver always include all entries in a single callback?
Will IntersectionObserver always include all entries in the first callback?
Jul 16, 2021
Thanks for the test and results! The link 403s now, mind sticking the code into a gist or something? Might be useful to turn into a WPT down the road.
Given that this behavior is interoperable, if the spec doesn't currently require it, it sounds reasonable to do so (I'm still getting familiar w/ the spec, but I will try to find where that should be in the coming days(weeks/months/years??).
Suppose that we have created an IntersectionObserver and we give the observer a large array of elements to observe by iterating through the array and observing each element.
Is it guaranteed that when the callback is executed the first time it will include all entries that are being observed in a single callback (as opposed to queuing multiple callbacks with a subset of the original array)?
To clarify, if the above holds true, then in the below example, the line
console.log(entries.length, target.length);
will never be reached with the first callback - but will be reached with subsequent callbacks.Please excuse me if this is not the appropriate place to ask and I will close the issue.
The text was updated successfully, but these errors were encountered: