From af76ab23217bd8131a29fee6bea77efc98657223 Mon Sep 17 00:00:00 2001 From: Dizzle Date: Tue, 6 Feb 2018 13:59:43 -0500 Subject: [PATCH] [fix] Rebuilds lib --- lib/VirtualList.js | 20 +++++++++++++++++++- package.json | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/VirtualList.js b/lib/VirtualList.js index 2c970a7..bb14937 100644 --- a/lib/VirtualList.js +++ b/lib/VirtualList.js @@ -53,6 +53,9 @@ var VirtualList = function VirtualList(options) { var _this = _possibleConstructorReturn(this, (vlist.__proto__ || Object.getPrototypeOf(vlist)).call(this, props)); + _this._isMounted = false; + + _this.options = _extends({ container: typeof window !== 'undefined' ? window : undefined }, options); @@ -82,17 +85,25 @@ var VirtualList = function VirtualList(options) { // get first and lastItemIndex var state = (0, _getVisibleItemBounds2.default)(list, container, items, itemHeight, itemBuffer); + if (state === undefined) { + return; + } + if (state.firstItemIndex > state.lastItemIndex) { return; } - if (state !== undefined && (state.firstItemIndex !== this.state.firstItemIndex || state.lastItemIndex !== this.state.lastItemIndex)) { + if (state.firstItemIndex !== this.state.firstItemIndex || state.lastItemIndex !== this.state.lastItemIndex) { this.setState(state); } } }, { key: 'refreshState', value: function refreshState() { + if (!this._isMounted) { + return; + } + var _props = this.props, itemHeight = _props.itemHeight, items = _props.items, @@ -101,6 +112,11 @@ var VirtualList = function VirtualList(options) { this.setStateIfNeeded(this.domNode, this.options.container, items, itemHeight, itemBuffer); } + }, { + key: 'componentWillMount', + value: function componentWillMount() { + this._isMounted = true; + } }, { key: 'componentDidMount', value: function componentDidMount() { @@ -117,6 +133,8 @@ var VirtualList = function VirtualList(options) { }, { key: 'componentWillUnmount', value: function componentWillUnmount() { + this._isMounted = false; + // remove events this.options.container.removeEventListener('scroll', this.refreshState); this.options.container.removeEventListener('resize', this.refreshState); diff --git a/package.json b/package.json index 56802ef..f4186ae 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-virtual-list", - "version": "2.2.3", + "version": "2.2.4", "description": "Super simple virtualized list React higher-order component", "main": "lib/VirtualList.js", "directories": {