<commit_before>/* eslint-disable react/prop-types */
import {graphql} from 'react-apollo'
import React from 'react'
import Loading from './Loading'
import ErrorComponent from './Error'
import getVariables from './getVariables'
import sleep from './sleep'
import debounce from 'lodash/debounce'
import NetworkError from './NetworkError'

const defaultOptions = {
  loading: <Loading />,
  networkErrorComponent: <NetworkError />,
  fetchPolicy: 'cache-and-network',
  variables: {}
}

export default function (query, userOptions) {
  const options = {...defaultOptions, ...userOptions}
  return function (ComposedComponent) {
    class GraphQLQuery extends React.Component {

      constructor (props) {
        super(props)
        this.debouncedTryRefetch = debounce(this.tryRefetch.bind(this), 1000)
      }

      componentDidUpdate () {
        if (this.props.error && this.props.error.networkError) {
          this.debouncedTryRefetch()
        }
      }

      async tryRefetch () {
        await sleep(1000)
        if (!this.props.error || !this.props.error.networkError) return
        try {
          await this.props.refetch()
        } catch (error) {
          console.warn('Error refetching:', error)
        }
      }

      componentWillUnmount () {
        if (this.interval) {
          clearInterval(this.interval)
        }
      }

      renderLoading () {
        if (!options.loading) return this.renderComposed()
        return options.loading
      }

      renderNetworkError () {
        if (options.networkErrorComponent) return options.networkErrorComponent
        if (options.loading) return options.loading
        return this.renderComposed()
      }<commit_msg>improve loading<commit_after>/* eslint-disable react/prop-types */
import {graphql} from 'react-apollo'
import React from 'react'
import Loading from './Loading'
import ErrorComponent from './Error'
import getVariables from './getVariables'
import sleep from './sleep'
import debounce from 'lodash/debounce'
import NetworkError from './NetworkError'

const defaultOptions = {
  loading: <Loading />,
  networkErrorComponent: <NetworkError />,
  fetchPolicy: 'cache-and-network',
  variables: {}
}

export default function (query, userOptions) {
  const options = {...defaultOptions, ...userOptions}
  return function (ComposedComponent) {
    class GraphQLQuery extends React.Component {

      constructor (props) {
        super(props)
        this.debouncedTryRefetch = debounce(this.tryRefetch.bind(this), 1000)
      }

      componentDidUpdate () {
        if (this.props.error && this.props.error.networkError) {
          this.debouncedTryRefetch()
        }
      }

      async tryRefetch () {
        await sleep(1000)
        if (!this.props.error || !this.props.error.networkError) return
        try {
          await this.props.refetch()
        } catch (error) {
          console.warn('Error refetching:', error)
        }
      }

      componentWillUnmount () {
        if (this.interval) {
          clearInterval(this.interval)
        }
      }

      renderLoading () {
        if (!options.loading) return this.renderComposed()
        return options.loading
      }

      renderNetworkError () {
        if (options.loading) return options.loading
        if (options.networkErrorComponent) return options.networkErrorComponent
        return this.renderComposed()
      }
{'fraction_non_alphanumeric': 0.11019446081319977, 'fraction_numerical': 0.004714201532115498, 'mean_word_length': 2.6349036402569594, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6393711', 'n_tokens_mistral': 948, 'n_tokens_neox': 912, 'n_words': 219}