<commit_before>import map from 'lodash/map'
import React from 'react'

const call = fn => fn()

// `subscriptions` can be a function if we want to ensure that the subscription
// callbacks have been correctly initialized when there are circular dependencies
const addSubscriptions = subscriptions => Component =>
  class SubscriptionWrapper extends React.PureComponent {
    _unsubscribes = null

    componentWillMount () {
      const state = {}
      this._unsubscribes = map(
        typeof subscriptions === 'function'
          ? subscriptions(this.props)
          : subscriptions,
        (subscribe, prop) => {
          state[prop] = undefined
          return subscribe(value => this.setState({ [prop]: value }))
        }
      )

      // provide all props since the beginning (better behavior with Freactal)
      this.setState(state)
    }

    componentWillUnmount () {
      this._unsubscribes.forEach(call)
      this._unsubscribes = null
    }

    render () {
      return <Component {...this.props} {...this.state} />
    }
  }
export { addSubscriptions as default }<commit_msg>chore(xo-web/addSubscriptions): dont use deprecated componentWillMount (#3734)<commit_after>import React from 'react'
import { map, mapValues, noop } from 'lodash'

const call = fn => fn()

// `subscriptions` can be a function if we want to ensure that the subscription
// callbacks have been correctly initialized when there are circular dependencies
const addSubscriptions = subscriptions => Component =>
  class SubscriptionWrapper extends React.PureComponent {
    constructor(props) {
      super(props)

      // provide all props since the beginning (better behavior with Freactal)
      this.state = mapValues(
        (this._subscribes =
          typeof subscriptions === 'function'
            ? subscriptions(props)
            : subscriptions),
        noop
      )
    }

    _unsubscribes = undefined

    componentDidMount() {
      this._unsubscribes = map(this._subscribes, (subscribe, prop) =>
        subscribe(value => this.setState({ [prop]: value }))
      )
    }

    componentWillUnmount() {
      this._unsubscribes.forEach(call)
      this._unsubscribes = undefined
    }

    render() {
      return <Component {...this.props} {...this.state} />
    }
  }
export { addSubscriptions as default }
{'fraction_non_alphanumeric': 0.10120585701981051, 'fraction_numerical': 0.0017226528854435831, 'mean_word_length': 2.7833876221498373, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '7312860', 'n_tokens_mistral': 637, 'n_tokens_neox': 618, 'n_words': 183}