<commit_before>/* @flow */
import { Component } from 'react'
import PropTypes from 'prop-types'
import { getContext, compose } from 'recompose'
import { connect } from 'react-redux'

import { mapStateToProps, mapDispatchToProps } from '../mapping/field'

import type { Field as FieldType } from '../../types/Field'

type FieldProps = {
  // public API
  fieldId: string,
  initialData: FieldType,
  initialState: Object,
  render: Function,

  // passed via Redux / context
  formId: string,
  data: FieldType,
  state: Object,
  initField: Function,
  updateField: Function,
  updateState: Function,
  subscribeToReinit: Function,
}

class Field extends Component {
  constructor(props, context) {
    super(props, context)

    const { initField, initialData, subscribeToReinit } = props

    const init = () => initField(initialData, initialState)
    this.unsubscribe = subscribeToReinit(init)
    init()
  }

  componentWillUnmount() {
    this.unsubscribe()
  }

  props: FieldProps
  unsubscribe: Function

  render() {
    const {
      data: { value = '', isEnabled, isRequired, isValid, isTouched },
      state,
      render,
      updateField,
      updateState,
      formId,
      fieldId,
    } = this.props<commit_msg>fix initialState from field<commit_after>/* @flow */
import { Component } from 'react'
import PropTypes from 'prop-types'
import { getContext, compose } from 'recompose'
import { connect } from 'react-redux'

import { mapStateToProps, mapDispatchToProps } from '../mapping/field'

import type { Field as FieldType } from '../../types/Field'

type FieldProps = {
  // public API
  fieldId: string,
  initialData: FieldType,
  initialState: Object,
  render: Function,

  // passed via Redux / context
  formId: string,
  data: FieldType,
  state: Object,
  initField: Function,
  updateField: Function,
  updateState: Function,
  subscribeToReinit: Function,
}

class Field extends Component {
  constructor(props, context) {
    super(props, context)

    const { initField, initialData, initialState, subscribeToReinit } = props

    const init = () => initField(initialData, initialState)
    this.unsubscribe = subscribeToReinit(init)
    init()
  }

  componentWillUnmount() {
    this.unsubscribe()
  }

  props: FieldProps
  unsubscribe: Function

  render() {
    const {
      data: { value = '', isEnabled, isRequired, isValid, isTouched },
      state,
      render,
      updateField,
      updateState,
      formId,
      fieldId,
    } = this.props
{'fraction_non_alphanumeric': 0.109375, 'fraction_numerical': 0.0, 'mean_word_length': 3.342608695652174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7219657', 'n_tokens_mistral': 762, 'n_tokens_neox': 743, 'n_words': 207}