<commit_before>// FIXME: waiting for release of fixed package.json entry. >= 4.1.0
import "sanitize.css/sanitize.css"

import React from "react"
import { Switch, Route, NavLink } from "react-router-dom"
import Helmet from "react-helmet"
import { injectIntl, FormattedMessage, IntlProvider } from "react-intl"
import { connect } from "react-redux"

import { getLocale, getLanguage } from "../common/State"
import AsyncRoute from "../common/AsyncRoute"

// Application specific
import "./Fonts.css"
import Styles from "./Root.css"
import RouterConnector from "../common/RouterConnector"

import messages from "./messages/en.json"

function Error404() {
  return <div>Sorry, that page was not found.</div>
}

function Header({ intl }) {
  return (
    <header id="site-header">
      <Helmet
        titleTemplate={`${intl.formatMessage({ id: "app.title" })} - %s`}
        defaultTitle={intl.formatMessage({ id: "app.title" })}
        meta={[
          { name: "charset", content: "utf-8" },
          { "http-equiv": "X-UA-Compatible", "content": "IE=edge" },
          { name: "viewport", content: "width=device-width, initial-scale=1" },
          { name: "description", content: intl.formatMessage({ id: "app.description" }) }
        ]}
      />

      <h1 className={Styles.title}><FormattedMessage id="app.title"/></h1>
      <strong><FormattedMessage id="app.description"/></strong>
    </header>
  )
}

Header = injectIntl(Header)


function HomeComponent() {
  return <b>Home</b>
}



function createLazyComponent(options) {
  var LazyLoading = false
  var LazyPromise = null
  var LazyComponent = null
  var LazyMessages = null

  class LazyComponentWrapper extends React.Component {
    constructor(props, context) {
      super(props)

      this.state = {
        loading: LazyLoading,
        component: LazyComponent,
        messages: LazyMessages
      }
    }

    fetchData() {
      if (LazyLoading === true || LazyComponent != null) {
        return LazyPromise
      }

      console.log("LazyComponentWrapper: Loading...")
      this.setState({
        loading: true
      })

      LazyLoading = true
      LazyPromise = Promise.all(options.load(this.props.language)).then((result) => {
        console.log("LazyComponentWrapper: Loading done!")
        console.log("LazyComponentWrapper: Result:", result)

        LazyComponent = result[0].default
        LazyMessages = result[1]
        LazyLoading = false

        this.setState({
          loading: LazyLoading,
          component: LazyComponent,
          messages: LazyMessages
        })

        console.log("LazyComponentWrapper: Final State...", this.state)
      })

      return LazyPromise
    }

    componentDidMount() {
      if (!LazyComponent) {
        this.fetchData()
      }
    }

    render() {
      let Component = LazyComponent
      let { load, ...props } = this.props

      return Component ? <Component {...props} /> : null
    }
  }

  LazyComponentWrapper.propTypes = {
    children: React.PropTypes.node,
    locale: React.PropTypes.string,
    language: React.PropTypes.string,
    intl: React.PropTypes.object
  }

  const mapStateToProps = (state, ownProps) => ({
    locale: getLocale(state),
    language: getLanguage(state)
  })

  return connect(mapStateToProps)(LazyComponentWrapper)
}

const AboutComponent = createLazyComponent({
  load: (language) => {
    return [
      import("./views/About"),
      import("./views/messages/About." + language + ".json")
    ]
  }
})



<commit_msg>Using lazy component for home as well.<commit_after>// FIXME: waiting for release of fixed package.json entry. >= 4.1.0
import "sanitize.css/sanitize.css"

import React from "react"
import { Switch, Route, NavLink } from "react-router-dom"
import Helmet from "react-helmet"
import { injectIntl, FormattedMessage, IntlProvider } from "react-intl"
import { connect } from "react-redux"

import { getLocale, getLanguage } from "../common/State"
import AsyncRoute from "../common/AsyncRoute"

// Application specific
import "./Fonts.css"
import Styles from "./Root.css"
import RouterConnector from "../common/RouterConnector"

import messages from "./messages/en.json"

function Error404() {
  return <div>Sorry, that page was not found.</div>
}

function Header({ intl }) {
  return (
    <header id="site-header">
      <Helmet
        titleTemplate={`${intl.formatMessage({ id: "app.title" })} - %s`}
        defaultTitle={intl.formatMessage({ id: "app.title" })}
        meta={[
          { name: "charset", content: "utf-8" },
          { "http-equiv": "X-UA-Compatible", "content": "IE=edge" },
          { name: "viewport", content: "width=device-width, initial-scale=1" },
          { name: "description", content: intl.formatMessage({ id: "app.description" }) }
        ]}
      />

      <h1 className={Styles.title}><FormattedMessage id="app.title"/></h1>
      <strong><FormattedMessage id="app.description"/></strong>
    </header>
  )
}

Header = injectIntl(Header)





function createLazyComponent(options)
{
  var LazyLoading = false
  var LazyPromise = null
  var LazyComponent = null
  var LazyMessages = null

  class LazyComponentWrapper extends React.Component {
    constructor(props, context) {
      super(props)

      this.state = {
        loading: LazyLoading,
        component: LazyComponent,
        messages: LazyMessages
      }
    }

    fetchData() {
      if (LazyLoading === true || LazyComponent != null) {
        return LazyPromise
      }

      console.log("LazyComponentWrapper: Loading...")
      this.setState({
        loading: true
      })

      LazyLoading = true
      LazyPromise = Promise.all(options.load(this.props.language)).then((result) => {
        console.log("LazyComponentWrapper: Loading done!")
        console.log("LazyComponentWrapper: Result:", result)

        LazyComponent = result[0].default
        LazyMessages = result[1]
        LazyLoading = false

        this.setState({
          loading: LazyLoading,
          component: LazyComponent,
          messages: LazyMessages
        })

        console.log("LazyComponentWrapper: Final State...", this.state)
      })

      return LazyPromise
    }

    componentDidMount() {
      if (!LazyComponent) {
        this.fetchData()
      }
    }

    render() {
      let Component = LazyComponent
      let { load, ...props } = this.props

      return Component ? <Component {...props} /> : null
    }
  }

  LazyComponentWrapper.propTypes = {
    children: React.PropTypes.node,
    locale: React.PropTypes.string,
    language: React.PropTypes.string,
    intl: React.PropTypes.object
  }

  const mapStateToProps = (state, ownProps) => ({
    locale: getLocale(state),
    language: getLanguage(state)
  })

  return connect(mapStateToProps)(LazyComponentWrapper)
}



const HomeComponent = createLazyComponent({
  load: (language) => {
    return [
      import("./views/Home")
    ]
  }
})

const AboutComponent = createLazyComponent({
  load: (language) => {
    return [
      import("./views/About"),
      import("./views/messages/About." + language + ".json")
    ]
  }
})




{'fraction_non_alphanumeric': 0.13643389068427708, 'fraction_numerical': 0.0033722073907545315, 'mean_word_length': 2.764145954521417, 'pattern_counts': {'":': 4, '<': 29, '<?xml version=': 0, '>': 38, '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': '2590085', 'n_tokens_mistral': 2159, 'n_tokens_neox': 2114, 'n_words': 473}