diff --git a/lib/ReduxInfiniteScroll.js b/lib/ReduxInfiniteScroll.js index 2e3e081..305c31e 100644 --- a/lib/ReduxInfiniteScroll.js +++ b/lib/ReduxInfiniteScroll.js @@ -88,21 +88,16 @@ var ReduxInfiniteScroll = function (_Component) { }, { key: 'scrollListener', value: function scrollListener() { - var _this2 = this; - // This is to prevent the upcoming logic from toggling a load more before // any data has been passed to the component - if (this.props.items <= 0) return; + if (this._totalItemsSize() <= 0) return; - // Need to find better way around this setTimeout - setTimeout(function () { - var bottomPosition = _this2.props.elementIsScrollable ? _this2._elScrollListener() : _this2._windowScrollListener(); + var bottomPosition = this.props.elementIsScrollable ? this._elScrollListener() : this._windowScrollListener(); - if (bottomPosition < Number(_this2.props.threshold)) { - _this2.detachScrollListener(); - _this2.props.loadMore(); - } - }); + if (bottomPosition < Number(this.props.threshold)) { + this.detachScrollListener(); + this.props.loadMore(); + } } }, { key: 'detachScrollListener', @@ -118,6 +113,14 @@ var ReduxInfiniteScroll = function (_Component) { return [allItems, this.renderLoader()]; } + }, { + key: '_totalItemsSize', + value: function _totalItemsSize() { + var totalSize = void 0; + totalSize += this.props.children.size ? this.props.children.size : this.props.children.length; + totalSize += this.props.items.size ? this.props.items.size : this.props.items.length; + return totalSize; + } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { diff --git a/package.json b/package.json index 129a7df..3611bee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "redux-infinite-scroll", - "version": "1.1.1", + "version": "1.0.6", "description": "React infinite scroll component designed for a Redux data-flow.", "main": "lib/ReduxInfiniteScroll.js", "scripts": {