-
Notifications
You must be signed in to change notification settings - Fork 515
Add IntersectionObserver polyfill – Take #02 #121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Improved the intersection detection to match the native implementation (technically, my previous behavior was just straight up non-compliant with the spec). PTAL :) |
Cool. Is margin support coming, or should we ship a v1 at this point? |
I vote for shipping a v1 without margin support. |
Hey there, I just want to point out some stuff and do some questions around this polyfill.
I hope this feedback is useful, you probably have answers and reasons for most of these, so sorry in advance if I missed something 😀 |
Personally I don't much care about relying on recent APIs or syntax because But it's really important to me to avoid embedding polyfills for things we So in summary:
On Sat, 16 Apr 2016 at 08:56, Jeremias Menichelli notifications@github.com
|
@triblondon I was actually thinking about that multi polyfilled scenario and I agree, that's a good point. I added three more points recently since I forgot them while adding the comment. |
@surma where are you going to host this polyfill? Is this WICG repo going to be the canonical source? If so I can require it from here. Ideally the polyfill would have its own repo though, and be published to npm. |
I thought the WICG repo would be a good fit, but you are right in that it’s not really |
The ES2015 code was never meant to make it into the repo. Oversight on my part. Definitely was trying to use ES5 only. I implement most of your remarks, @jeremenichelli. PTAL :) |
Looks great @surma, nice job 👌 |
Just noticed one thing. Now that we're listening to the |
Oh good catch! Fixed |
@triblondon I appreciate any time you spend on this. Feel free to contribute your code to this PR :) If you want to ditch IO and add margin support, I am obviously fine with that. I just didn’t want to implement a CSS string parser and thought IO were a good choice. Apparently they aren’t. Also, I don’t want to be held responsible for @slightlyoff opening those old wounds 😉
Since I was actively ignoring margins all this time, that is perfectly fair to say. If no one is veto-ing your assessment of the 99% use-case, go for it :) Regarding the feedback from @aFarkas:
|
Scroll doesn't bubble. I've updated my tests. I think this pattern works really well, offers a more linear read of the tests and assertions, tests run faster, and they're compatible with older browsers. It's actually slightly shorter too. I think your margin tests were slightly awry because the test case does not set up the IO with any margins! So I reset that test case to the steps I had in my last work on it. I'm now finding that Chrome 52 (canary) native passes all except the margin tests: Chrome 50 (stable) using the polyfill: I don't have push on either your fork or the WICG, so I can make a new surma-dump fork if you'd like these changes proposed for merge into your PR, but in the meantime I pushed them to https://github.com/Financial-Times/polyfill-service/compare/intersect-observer#diff-c0d2dbf8759d522d6028477a3a43497f |
Great! Awesome stuff, @triblondon. Made you collab on my fork. So feel free to push your changes. Looking forward to it. |
…s when they are created
…expectation failures are not surfaced properly. Use the latest version locally.
…e linear workflow.
OK, I pushed. Notes in the commit messages should be fairly explanatory. I guess your next steps are to investigate the difference in native vs polyfill test results, and look at @aFarkas's points? |
@surma will you be picking this back up at some point? We have a PR open in the polyfill service to merge this in once its ready. |
Sorry for the absence, but Google I/O was happening and was quite the marathon. Just got back and will continue working on this soon. Thanks for your work and for the patience :) |
This code is forked from the initial polyfill written by surma: w3c#121
This code is forked from the initial polyfill written by surma: w3c#121
return null; | ||
} | ||
// Older IE | ||
r.width = r.width || r.right - r.left; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safari throws an read-only error on setting this property. I fixed it by checking if the property is writable using the property descriptor getter.
var desc = Object.getOwnPropertyDescriptor(r, 'width');
if (desc && desc.writable) {
r.width = r.width || r.right - r.left;
r.height = r.height || r.bottom - r.top;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have this problem when using getBoundingClientRect
, I think the best way to get around this is to return a different object with the rects.
var r = el.getBoundingClientRect();
if(!r) {
return null;
}
// old IE
return {
top: r.top,
bottom: r.bottom,
left: r.left,
right: r.right,
width: r.width || r.right - r.left,
height: r.height || r.bottom - r.top
}
Extra code, but safe.
This code is forked from the initial polyfill written by surma: w3c#121
Continued in #135 |
This code is forked from the initial polyfill written by surma: w3c#121
This code is forked from the initial polyfill written by surma: w3c#121
This code is forked from the initial polyfill written by surma: w3c#121
This code is forked from the initial polyfill written by surma: w3c#121
Continued from #116