<commit_before>/* eslint-disable no-underscore-dangle */

import { Component, createElement } from 'react';
import isEqual from 'lodash/isEqual';
import omit from 'lodash/omit';
import assign from 'lodash/assign';
import map from 'lodash/map';
import set from 'lodash/set';
import isArray from 'lodash/isArray';
import isEmpty from 'lodash/isEmpty';
import PropTypes from 'prop-types';

import { prefixName, unliftFieldArrayValue } from './utils';
import unknownProps from './unknownProps';
import { FieldArrayMutatorAction } from './constants';

function fieldValueReader(callback, fieldArrayValues, item, index) {
  const name = `[${index}]`;
  return callback(
    name,
    index,

    // make sure key changes when its name changes
    `${name}-${item._fieldInternalKey}`,

    fieldArrayValues[index],
    fieldArrayValues
  );
}

class FieldArray extends Component {
  static propTypes = {
    name: PropTypes.string.isRequired,
    value: PropTypes.array,
    component: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
      .isRequired,
  };

  static contextTypes = {
    zentForm: PropTypes.object,
  };

  static childContextTypes = {
    zentForm: PropTypes.object.isRequired,
  };

  getChildContext() {
    const { zentForm } = this.context;
    return {
      zentForm: {
        ...zentForm,
        prefix: this._name,
        onChangeFieldArray: this.onChangeFieldArray,
      },
    };
  }

  constructor(props, context) {
    super(props, context);
    if (!context.zentForm) {
      throw new Error('FieldArray must be in zent-form');
    }

    this.state = {
      fieldArray: (props.value || []).map(this.createInternalFieldValue),
    };
    this._name = prefixName(context.zentForm, props.name);
    this._uniqueKey = 0;

    // 标记触发 FieldArray 值改变的操作是什么类型
    this._mutatorAction = FieldArrayMutatorAction.Initialize;<commit_msg>Fix form field array initialize bug (#922)<commit_after>/* eslint-disable no-underscore-dangle */

import { Component, createElement } from 'react';
import isEqual from 'lodash/isEqual';
import omit from 'lodash/omit';
import assign from 'lodash/assign';
import map from 'lodash/map';
import set from 'lodash/set';
import isArray from 'lodash/isArray';
import isEmpty from 'lodash/isEmpty';
import PropTypes from 'prop-types';

import { prefixName, unliftFieldArrayValue } from './utils';
import unknownProps from './unknownProps';
import { FieldArrayMutatorAction } from './constants';

function fieldValueReader(callback, fieldArrayValues, item, index) {
  const name = `[${index}]`;
  return callback(
    name,
    index,

    // make sure key changes when its name changes
    `${name}-${item._fieldInternalKey}`,

    fieldArrayValues[index],
    fieldArrayValues
  );
}

class FieldArray extends Component {
  static propTypes = {
    name: PropTypes.string.isRequired,
    value: PropTypes.array,
    component: PropTypes.oneOfType([PropTypes.func, PropTypes.string])
      .isRequired,
  };

  static contextTypes = {
    zentForm: PropTypes.object,
  };

  static childContextTypes = {
    zentForm: PropTypes.object.isRequired,
  };

  getChildContext() {
    const { zentForm } = this.context;
    return {
      zentForm: {
        ...zentForm,
        prefix: this._name,
        onChangeFieldArray: this.onChangeFieldArray,
      },
    };
  }

  constructor(props, context) {
    super(props, context);
    if (!context.zentForm) {
      throw new Error('FieldArray must be in zent-form');
    }

    this._uniqueKey = 0;
    this._name = prefixName(context.zentForm, props.name);

    // 标记触发 FieldArray 值改变的操作是什么类型
    this._mutatorAction = FieldArrayMutatorAction.Initialize;

    this.state = {
      fieldArray: (props.value || []).map(this.createInternalFieldValue),
    };
{'fraction_non_alphanumeric': 0.1199468085106383, 'fraction_numerical': 0.0013297872340425532, 'mean_word_length': 3.5204326923076925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4211587', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1145, 'n_words': 277}