<commit_before>import React, { Component } from 'react';

class DirectionFilter extends Component {
  constructor(props) {
    super(props);

    this.state = {
      direction: 'down',
    };

    this.getScrollDirection = this.getScrollDirection.bind(this);
    this.setEl = ref => {
      this.el = ref;
    };
    this.previousTop = 0;
  }

  componentDidMount() {
    this.attachListener();
  }

  componentWillUnmount() {
    this.removeListener();
  }

  getScrollDirection() {
    const rect = this.el.getBoundingClientRect();
    const direction = this.previousTop > rect.top ? 'down' : 'up';

    this.previousTop = rect.top;

    if (direction !== this.state.direction) {
      this.setState({ direction });
    }
  }

  attachListener() {
    window.addEventListener('scroll', this.getScrollDirection);
  }

  removeListener() {
    window.removeEventListener('scroll', this.getScrollDirection);
  }

  render(props) {
    return (
      <div ref={this.setEl}><commit_msg>improve code, needs a re-think.<commit_after>import React, { Component } from 'react';

class DirectionFilter extends Component {
  constructor(props) {
    super(props);

    this.state = {
      direction: 'down',
      pageYOffset: -1,
    };

    this.getScrollDirection = this.getScrollDirection.bind(this);
  }

  componentDidMount() {
    this.attachListener();
  }

  componentWillUnmount() {
    this.removeListener();
  }

  getScrollDirection() {
    const direction = this.state.pageYOffset > window.pageYOffset
      ? 'down'
      : 'up';

    this.setState({ direction, pageYOffset: window.pageYOffset });
  }

  attachListener() {
    window.addEventListener('scroll', this.getScrollDirection);
  }

  removeListener() {
    window.removeEventListener('scroll', this.getScrollDirection);
  }

  render(props) {
    return (
      <div>
{'fraction_non_alphanumeric': 0.1340599455040872, 'fraction_numerical': 0.0010899182561307902, 'mean_word_length': 3.163265306122449, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '400606', 'n_tokens_mistral': 566, 'n_tokens_neox': 545, 'n_words': 98}