<commit_before>import { ValidationProvider } from 'vee-validate';

import TextInput from '../components/TextInput.vue';
import Submit from '../components/Submit.vue';

export default {
  components: { TextInput, Submit, ValidationProvider },

  props: {
    initialFields: {
      type: Object,
      required: true,
    },
  },

  data() {
    return {
      currentFields: this.buildCurrentFields(),
      formKey: Date.now().toString(),
    };
  },

  computed: {
    formHasChanged() {
      const haveChanged = Object.keys(this.currentFields).filter(
        key => this.currentFields[key].changed
      );

      return haveChanged.length > 0;
    },

    formIsValid() {
      const fieldsToValidate = Object.keys(this.currentFields).filter(key => {
        const { shouldValidate, isVisible } = this.currentFields[key];
        return shouldValidate && isVisible;
      });

      const areNotValid = fieldsToValidate.filter(
        key => !this.currentFields[key].valid
      );

      return areNotValid.length === 0;
    },
  },

  watch: {
    formHasChanged(newHasChanged, oldHasChanged) {
      if (newHasChanged !== oldHasChanged) {
        this.$emit('onFormHasChangedToggle', newHasChanged);
      }
    },

    initialFields() {
      this.updateCurrentFields();
      this.formKey = Date.now().toString();
    },
  },

  methods: {
    updateCurrentFields() {
      const updateKeys = ['isVisible', 'shouldValidate', 'value'];

      Object.keys(this.initialFields).forEach(fieldKey => {
        updateKeys.forEach(updateKey => {
          this.$set(
            this.currentFields[fieldKey],
            updateKey,
            this.initialFields[fieldKey][updateKey]
          );
        });
      });
    },

    buildCurrentFields() {
      const final = {};

      Object.keys(this.initialFields).forEach(key => {
        const { value, shouldValidate, isVisible } = this.initialFields[key];

        final[key] = {
          value,
          isVisible,<commit_msg>no need to use this.$set as keys already exist<commit_after>import { ValidationProvider } from 'vee-validate';

import TextInput from '../components/TextInput.vue';
import Submit from '../components/Submit.vue';

export default {
  components: { TextInput, Submit, ValidationProvider },

  props: {
    initialFields: {
      type: Object,
      required: true,
    },
  },

  data() {
    return {
      currentFields: this.buildCurrentFields(),
      formKey: Date.now().toString(),
    };
  },

  computed: {
    formHasChanged() {
      const haveChanged = Object.keys(this.currentFields).filter(
        key => this.currentFields[key].changed
      );

      return haveChanged.length > 0;
    },

    formIsValid() {
      const fieldsToValidate = Object.keys(this.currentFields).filter(key => {
        const { shouldValidate, isVisible } = this.currentFields[key];
        return shouldValidate && isVisible;
      });

      const areNotValid = fieldsToValidate.filter(
        key => !this.currentFields[key].valid
      );

      return areNotValid.length === 0;
    },
  },

  watch: {
    formHasChanged(newHasChanged, oldHasChanged) {
      if (newHasChanged !== oldHasChanged) {
        this.$emit('onFormHasChangedToggle', newHasChanged);
      }
    },

    initialFields() {
      this.updateCurrentFields();
      this.formKey = Date.now().toString();
    },
  },

  methods: {
    updateCurrentFields() {
      const updateKeys = ['isVisible', 'shouldValidate', 'value'];

      Object.keys(this.initialFields).forEach(fieldKey => {
        updateKeys.forEach(updateKey => {
          this.currentFields[fieldKey][updateKey] = this.initialFields[
            fieldKey
          ][updateKey];
        });
      });
    },

    buildCurrentFields() {
      const final = {};

      Object.keys(this.initialFields).forEach(key => {
        const { value, shouldValidate, isVisible } = this.initialFields[key];

        final[key] = {
          value,
          isVisible,
{'fraction_non_alphanumeric': 0.13351772692984662, 'fraction_numerical': 0.0010057832537088258, 'mean_word_length': 2.5048458149779735, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1203753', 'n_tokens_mistral': 1135, 'n_tokens_neox': 1112, 'n_words': 199}