From 7277e9eeb4e8503407c4f86e7ea174870aae61d1 Mon Sep 17 00:00:00 2001 From: snewcomer Date: Fri, 11 May 2018 14:01:54 -0500 Subject: [PATCH] ensure explicitly setting viewportUseIntersectionObserver is not allowed --- README.md | 5 ++--- addon/mixins/in-viewport.js | 8 ++++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bea69b7a..4bb29e0f 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,6 @@ export default Component.extend(InViewportMixin, { viewportEnabled : true, viewportUseRAF : true, viewportSpy : false, - viewportUseIntersectionObserver : true, viewportScrollSensitivity : 1, viewportRefreshRate : 150, intersectionThreshold : 0, @@ -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) @@ -191,7 +191,6 @@ module.exports = function(environment) { viewportEnabled : false, viewportUseRAF : true, viewportSpy : false, - viewportUseIntersectionObserver : true, viewportScrollSensitivity : 1, viewportRefreshRate : 100, viewportListeners : [], diff --git a/addon/mixins/in-viewport.js b/addon/mixins/in-viewport.js index a172c9a7..0963d7a5 100644 --- a/addon/mixins/in-viewport.js +++ b/addon/mixins/in-viewport.js @@ -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', []); },