Forked from aganglada/intersection-observer-polyfill.js
Created
March 1, 2018 03:09
-
-
Save zheeeng/700bf92614a7ebfcffdde637aa4b8d0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loadPolyfills() | |
.then(() => /* Render React application now that your Polyfills are ready */) | |
/** | |
* Do feature detection, to figure out which polyfills needs to be imported. | |
**/ | |
function loadPolyfills() { | |
const polyfills = [] | |
if (!supportsIntersectionObserver()) { | |
polyfills.push(import('intersection-observer')) | |
} | |
return Promise.all(polyfills) | |
} | |
function supportsIntersectionObserver() { | |
return ( | |
'IntersectionObserver' in global && | |
'IntersectionObserverEntry' in global && | |
'intersectionRatio' in IntersectionObserverEntry.prototype | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment