w3c / IntersectionObserver

Intersection Observer
https://www.w3.org/TR/intersection-observer/
Other
3.62k stars 523 forks source link

HTML spec needs further changes in IntersectionObserver for proper integration #464

Open zcorpan opened 4 years ago

zcorpan commented 4 years ago

Follow-up to https://github.com/w3c/IntersectionObserver/issues/427

In https://github.com/whatwg/html/pull/6097 I tried to update the HTML spec to use the new terms, but found additional issues.

The callback is these steps, with arguments entries and observer:

  1. For each entry in entries [ using a method of iteration which does not trigger developer-modifiable array accessors or iteration hooks ] :

So... we need a way to enumerate entries, but without triggering developer-modifiable array accessors or iteration hooks. I'm not entirely sure how to solve this concretely, but maybe @annevk or @domenic can advise?

In addition, @annevk mentioned this in IRC: https://w3c.github.io/IntersectionObserver/#initialize-new-intersection-observer says in step 8:

The thresholds attribute getter will return this sorted thresholds list.

This should instead set an internal slot, and the definition of thresholds getter should say to return the value of that internal slot.

domenic commented 4 years ago

It would be ideal if HTML didn't initialize JavaScript-facing IntersectionObserver objects at all. Instead there should be algorithms like "add intersection observer steps", which takes a series of spec steps, which HTML can use. Then the IntersectionObserver constructor would call "add intersection observer steps" with the steps being to invoke the provided callback.