Skip to content
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

Ensure explicitly setting viewportUseIntersectionObserver is not allowed #147

Merged
merged 1 commit into from
May 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ export default Component.extend(InViewportMixin, {
viewportEnabled : true,
viewportUseRAF : true,
viewportSpy : false,
viewportUseIntersectionObserver : true,
viewportScrollSensitivity : 1,
viewportRefreshRate : 150,
intersectionThreshold : 0,
Expand All @@ -114,8 +113,9 @@ export default Component.extend(InViewportMixin, {
- `viewportUseIntersectionObserver: boolean`

Default: Depends on browser
Read-only

The Mixin by default will use the IntersectionObserver API. If IntersectionObserver is not supported in the target browser, ember-in-viewport will fallback to rAF.
The Mixin by default will use the IntersectionObserver API. If IntersectionObserver is not supported in the target browser, ember-in-viewport will fallback to rAF. We prevent users from explicitly setting this to `true` as browsers lacking support for IntersectionObserver will throw an error.

(https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API)
(https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/thresholds#Browser_compatibility)
Expand Down Expand Up @@ -191,7 +191,6 @@ module.exports = function(environment) {
viewportEnabled : false,
viewportUseRAF : true,
viewportSpy : false,
viewportUseIntersectionObserver : true,
viewportScrollSensitivity : 1,
viewportRefreshRate : 100,
viewportListeners : [],
Expand Down
8 changes: 6 additions & 2 deletions addon/mixins/in-viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ export default Mixin.create({
// ensure this mixin runs first, then your component can override the options
this._super(...arguments);

const options = assign({
let options = assign({
viewportUseRAF: canUseRAF(),
viewportUseIntersectionObserver: canUseIntersectionObserver(),
viewportEntered: false,
viewportListeners: []
}, this._buildOptions());

// set viewportUseIntersectionObserver after merging users config to avoid errors in browsers that lack support (https://github.com/DockYard/ember-in-viewport/issues/146)
options = assign(options, {
viewportUseIntersectionObserver: canUseIntersectionObserver(),
});

setProperties(this, options);
set(this, '_evtListenerClosures', []);
},
Expand Down