<commit_before>import React from "react";
import { IntlProvider } from "react-intl";
import { hook } from "renderer/hocs/hook";
import { theme, ThemeProvider } from "renderer/styles";
import AppContents from "renderer/App/AppContents";

class App extends React.PureComponent<Props, State> {
  constructor(props: App["props"], context: any) {
    super(props, context);
    this.state = {
      localeVersion: 1,
      locale: "en",
      messages: {},
    };
  }

  render() {
    const { localeVersion, locale, messages } = this.state;
    return (
      <IntlProvider key={localeVersion} locale={locale} messages={messages}>
        <ThemeProvider theme={theme}>
          <AppContents />
        </ThemeProvider>
      </IntlProvider>
    );
  }

  componentWillMount() {
    this.updateMessages(this.props);
  }

  componentWillReceiveProps(nextProps: App["props"]) {
    if (
      nextProps.locale !== this.props.locale ||
      nextProps.messages !== this.props.messages ||
      nextProps.fallbackMessages !== this.props.fallbackMessages
    ) {
      this.updateMessages(nextProps);
    }
  }

  updateMessages(nextProps: App["props"]) {
    this.setState({
      localeVersion: this.state.localeVersion + 1,
      locale: nextProps.locale,
      messages: {
        ...nextProps.fallbackMessages,
        ...nextProps.messages,
      },
    });
  }
}

interface Props {
  locale: string;
  messages: {
    [id: string]: string;
  };
  fallbackMessages: {
    [id: string]: string;
  };
}

interface State {
  localeVersion: number;
  locale: string;
  messages: {
    [id: string]: string;
  };
}

const emptyObj = {};

export default hook(map => ({
  locale: map(rs => rs.i18n.lang),
  messages: map(rs => {
    const { strings, lang } = rs.i18n;
    return strings[lang] || strings[lang.substring(0, 2)] || emptyObj;
  }),
  fallbackMessages: map(rs => rs.i18n.strings.en || emptyObj),
}))(App);
<commit_msg>Get rid of componentWillMount usage, cf. https://github.com/itchio/itch/issues/1869<commit_after>import React from "react";
import { IntlProvider } from "react-intl";
import { hook } from "renderer/hocs/hook";
import { theme, ThemeProvider } from "renderer/styles";
import AppContents from "renderer/App/AppContents";

class App extends React.PureComponent<Props, State> {
  constructor(props: App["props"], context: any) {
    super(props, context);
    this.state = {
      localeVersion: 1,
      locale: "en",
      messages: {},
    };
  }

  render() {
    const { localeVersion, locale, messages } = this.state;
    return (
      <IntlProvider key={localeVersion} locale={locale} messages={messages}>
        <ThemeProvider theme={theme}>
          <AppContents />
        </ThemeProvider>
      </IntlProvider>
    );
  }

  componentDidMount() {
    this.updateMessages(this.props);
  }

  componentWillReceiveProps(nextProps: App["props"]) {
    if (
      nextProps.locale !== this.props.locale ||
      nextProps.messages !== this.props.messages ||
      nextProps.fallbackMessages !== this.props.fallbackMessages
    ) {
      this.updateMessages(nextProps);
    }
  }

  updateMessages(nextProps: App["props"]) {
    this.setState({
      localeVersion: this.state.localeVersion + 1,
      locale: nextProps.locale,
      messages: {
        ...nextProps.fallbackMessages,
        ...nextProps.messages,
      },
    });
  }
}

interface Props {
  locale: string;
  messages: {
    [id: string]: string;
  };
  fallbackMessages: {
    [id: string]: string;
  };
}

interface State {
  localeVersion: number;
  locale: string;
  messages: {
    [id: string]: string;
  };
}

const emptyObj = {};

export default hook(map => ({
  locale: map(rs => rs.i18n.lang),
  messages: map(rs => {
    const { strings, lang } = rs.i18n;
    return strings[lang] || strings[lang.substring(0, 2)] || emptyObj;
  }),
  fallbackMessages: map(rs => rs.i18n.strings.en || emptyObj),
}))(App);

{'fraction_non_alphanumeric': 0.15042210283960092, 'fraction_numerical': 0.0061396776669224865, 'mean_word_length': 3.051813471502591, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 1, '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': '6929660', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1218, 'n_words': 252}