<commit_before>import React, { PureComponent, cloneElement } from 'react';
import classnames from 'classnames';
import { BaseCheckboxGroupProps } from './PropsType';

const getChildChecked = (children) => {
  const checkedValue: any[] = [];
  React.Children.map(children, (element: any) => {
    if (element.props && element.props.checked) {
      checkedValue.push(element.props.value);
    }
  });
  return checkedValue;
};

const getValue = (props, defaultValue) => {
  if ('value' in props) {
    return props.value;
  }
  if ('defaultValue' in props) {
    return props.defaultValue;
  }
  if (getChildChecked(props.children).length > 0) {
    return getChildChecked(props.children);
  }
  return defaultValue;
};

export interface CheckboxGroupProps extends BaseCheckboxGroupProps {
  prefixCls?: string;
  className?: string;
}

export default class CheckboxGroup extends PureComponent<CheckboxGroupProps, any> {
  static defaultProps = {
    prefixCls: 'za-checkbox-group',
    block: false,
    disabled: false,
    compact: false,
  };

  constructor(props) {
    super(props);
    this.state = {
      value: getValue(props, []),
    };
  }

  componentWillReceiveProps(nextProps) {
    if ('value' in nextProps || getChildChecked(nextProps.children).length > 0) {
      this.setState({
        value: nextProps.value || getChildChecked(nextProps.children),
      });
    }
  }

  onChildChange = (value) => {
    const values = this.state.value;
    const index = values.indexOf(value);

    if (index < 0) {
      values.push(value);
    } else {
      values.splice(index, 1);
    }

    this.setState({
      value: values,
    });<commit_msg>fix: copy value before operation<commit_after>import React, { PureComponent, cloneElement } from 'react';
import classnames from 'classnames';
import { BaseCheckboxGroupProps } from './PropsType';

const getChildChecked = (children) => {
  const checkedValue: any[] = [];
  React.Children.map(children, (element: any) => {
    if (element.props && element.props.checked) {
      checkedValue.push(element.props.value);
    }
  });
  return checkedValue;
};

const getValue = (props, defaultValue) => {
  if ('value' in props) {
    return props.value;
  }
  if ('defaultValue' in props) {
    return props.defaultValue;
  }
  if (getChildChecked(props.children).length > 0) {
    return getChildChecked(props.children);
  }
  return defaultValue;
};

export interface CheckboxGroupProps extends BaseCheckboxGroupProps {
  prefixCls?: string;
  className?: string;
}

export default class CheckboxGroup extends PureComponent<CheckboxGroupProps, any> {
  static defaultProps = {
    prefixCls: 'za-checkbox-group',
    block: false,
    disabled: false,
    compact: false,
  };

  constructor(props) {
    super(props);
    this.state = {
      value: getValue(props, []),
    };
  }

  componentWillReceiveProps(nextProps) {
    if ('value' in nextProps || getChildChecked(nextProps.children).length > 0) {
      this.setState({
        value: nextProps.value || getChildChecked(nextProps.children),
      });
    }
  }

  onChildChange = (value) => {
    const values = this.state.value.slice();
    const index = values.indexOf(value);

    if (index < 0) {
      values.push(value);
    } else {
      values.splice(index, 1);
    }

    this.setState({
      value: values,
    });
{'fraction_non_alphanumeric': 0.13281483697277893, 'fraction_numerical': 0.0023930601256356566, 'mean_word_length': 3.3541666666666665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '958600', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1017, 'n_words': 228}