Skip to content

Commit

Permalink
Fixes items count and prevents extra loading of items
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide Curletti committed Apr 6, 2016
1 parent b9d113a commit d5c42db
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/ReduxInfiniteScroll.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@ export default class ReduxInfiniteScroll extends Component {
scrollListener() {
// 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(() => {
let bottomPosition = this.props.elementIsScrollable ? this._elScrollListener() : this._windowScrollListener();
let bottomPosition = this.props.elementIsScrollable ? this._elScrollListener() : this._windowScrollListener();

if (bottomPosition < Number(this.props.threshold)) {
this.detachScrollListener();
this.props.loadMore();
}
});
if (bottomPosition < Number(this.props.threshold)) {
this.detachScrollListener();
this.props.loadMore();
}
}

detachScrollListener () {
Expand All @@ -79,6 +76,13 @@ export default class ReduxInfiniteScroll extends Component {
return [allItems, this.renderLoader()];
}

_totalItemsSize() {
let totalSize;
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;
}

componentWillUnmount () {
this.detachScrollListener();
}
Expand Down

0 comments on commit d5c42db

Please sign in to comment.