Skip to content

Commit

Permalink
ensure explicitly setting viewportUseIntersectionObserver is not allo…
Browse files Browse the repository at this point in the history
…wed (#147)
  • Loading branch information
snewcomer authored May 12, 2018
1 parent 68c3e43 commit 80542be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit 80542be

Please sign in to comment.