From 0443d221604e0a8a5437b976dbac81218bcf0b8b Mon Sep 17 00:00:00 2001 From: Joe Lencioni Date: Mon, 17 Aug 2015 09:06:26 -0700 Subject: [PATCH] Always remove window resize event listener As eagle-eyed @jeffkole pointed out [0], we always want to remove this event listener, even if the scrollableAncestor does not exist. [0]: https://github.com/brigade/react-waypoint/pull/20#discussion_r35925853 --- CHANGELOG.md | 1 + src/waypoint.jsx | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 645ffe6..8a58a5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Add event object and scope to onEnter/onLeave calls - Allow React 0.14.0-beta peerDependency +- Always remove window resize event listener ## 1.0.1 diff --git a/src/waypoint.jsx b/src/waypoint.jsx index 4f5f2fb..c3efc67 100644 --- a/src/waypoint.jsx +++ b/src/waypoint.jsx @@ -14,8 +14,6 @@ const Waypoint = React.createClass({ threshold: PropTypes.number, }, - _wasVisible: false, - /** * @return {Object} */ @@ -46,10 +44,12 @@ const Waypoint = React.createClass({ // // Cannot read property 'removeEventListener' of undefined this.scrollableAncestor.removeEventListener('scroll', this._handleScroll); - window.removeEventListener('resize', this._handleScroll); } + window.removeEventListener('resize', this._handleScroll); }, + _wasVisible: false, + /** * Traverses up the DOM to find an ancestor container which has an overflow * style that allows for scrolling.