<commit_before>import React from 'react';
import ReactDOM from 'react-dom';

function topPosition(domElt) {
  if (!domElt) {
    return 0;
  }
  return domElt.offsetTop + topPosition(domElt.offsetParent);
}

export default class InfiniteScroll extends React.Component {
  constructor(props) {
    super(props);
    
    this.scrollListener = this.scrollListener.bind(this);
  }
  componentDidMount() {
    this.pageLoaded = this.props.pageStart;
    this.attachScrollListener();
  }
  componentDidUpdate() {
    this.attachScrollListener();
  }
  render() {
    var {
      children,
      hasMore,
      loader,
      loadMore,
      pageStart,
      threshold,
      useWindow,
      ...props
    } = this.props;
    return React.DOM.div(props, children, hasMore && (loader || this._defaultLoader));
  }
  scrollListener() {
    var el = ReactDOM.findDOMNode(this);
    var scrollEl = window;

    var offset;
    if(this.props.useWindow == true) {
      var scrollTop = (scrollEl.pageYOffset !== undefined) ? scrollEl.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
      offset = topPosition(el) + el.offsetHeight - scrollTop - window.innerHeight;
    } else {
      offset = el.offsetHeight - el.parentNode.scrollTop - el.parentNode.clientHeight;
    }

    if (offset < Number(this.props.threshold)) {
      this.detachScrollListener();
      // call loadMore after detachScrollListener to allow
      // for non-async loadMore functions
      this.props.loadMore(this.pageLoaded += 1);
    }<commit_msg>use el.scrollHeight to calculate offset<commit_after>import React from 'react';
import ReactDOM from 'react-dom';

function topPosition(domElt) {
  if (!domElt) {
    return 0;
  }
  return domElt.offsetTop + topPosition(domElt.offsetParent);
}

export default class InfiniteScroll extends React.Component {
  constructor(props) {
    super(props);
    
    this.scrollListener = this.scrollListener.bind(this);
  }
  componentDidMount() {
    this.pageLoaded = this.props.pageStart;
    this.attachScrollListener();
  }
  componentDidUpdate() {
    this.attachScrollListener();
  }
  render() {
    var {
      children,
      hasMore,
      loader,
      loadMore,
      pageStart,
      threshold,
      useWindow,
      ...props
    } = this.props;
    return React.DOM.div(props, children, hasMore && (loader || this._defaultLoader));
  }
  scrollListener() {
    var el = ReactDOM.findDOMNode(this);
    var scrollEl = window;

    var offset;
    if(this.props.useWindow == true) {
      var scrollTop = (scrollEl.pageYOffset !== undefined) ? scrollEl.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
      offset = topPosition(el) + el.offsetHeight - scrollTop - window.innerHeight;
    } else {
      offset = el.scrollHeight - el.parentNode.scrollTop - el.parentNode.clientHeight;
    }

    if (offset < Number(this.props.threshold)) {
      this.detachScrollListener();
      // call loadMore after detachScrollListener to allow
      // for non-async loadMore functions
      this.props.loadMore(this.pageLoaded += 1);
    }
{'fraction_non_alphanumeric': 0.11673027989821882, 'fraction_numerical': 0.001272264631043257, 'mean_word_length': 3.0633074935400515, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1436664', 'n_tokens_mistral': 938, 'n_tokens_neox': 932, 'n_words': 194}