<commit_before><template>
  <f7-page>
    <f7-navbar back-link="Back" :title="key" sliding></f7-navbar>
    <form-fields :fields="fields" :item="item"></form-fields>
  </f7-page>
</template>
<script> 

  import firebase from '../fb.js'

  import FormFields from './form-fields.vue'

  export default {
    name: 'FirebaseEdit',

    data: function () {
      return {
        // item: {}
        key: '',
        fields: [
          {
            label: 'Name',
            type: 'text',
            key: 'name'
          },
          {
            label: '<NAME>',
            type: 'text',
            key: 'lastName',
            default: '<NAME>'
          },
          {
            label: 'Age',
            type: 'text',
            key: 'age'
          },
          {
            label: 'Switch',
            type: 'switch',
            key: 'switch'
          },
          {
            label: 'Select',
            type: 'select',
            key: 'select',
            default: '3',
            options: [
              { value: 1, text: 'USD' },
              { value: 2, text: 'EUR' },
              { value: 3, text: 'UAH' },
            ]
          },
          {
            label: 'Color',
            type: 'color',
            key: 'color',
            default: '#03ff00'
          },
        ]

      }
    },
    firebase: {
      // items: firebase.database().ref('null'),
      item: {
        source: firebase.database().ref(),
        asObject: true,
        cancelCallback: function () { }
      }
    },
    watch: {
      key: function (value, oldValue) {
        console.log('KEY changed', value, oldValue)
        this.$firebaseRefs && this.$firebaseRefs.item && this.$unbind('item')
        this.$bindAsObject('item', firebase.database().ref(value))
      },
      item: {
        handler: function (value, oldValue) {
          var res = JSON.parse(JSON.stringify(value))
          delete res['.key']
          console.log('item changed', value, oldValue, value['.key'], Object.keys(value))
          if (value['.key']) {
            firebase.database().ref(this.key).set(res)
          }
        },
        deep: true
      }
    },
    mounted: function () {
      console.log('$route', this.$route.params.key, this.$route)
      this.key = this.$route.path.substring(6)
    },
    components: {
      'form-fields': FormFields
    }
  }
</script><commit_msg>error handle<commit_after><template>
  <f7-page>
    <f7-navbar back-link="Back" :title="key" sliding></f7-navbar>
    <form-fields :fields="fields" :item="item"></form-fields>
  </f7-page>
</template>
<script> 

  import firebase from '../fb.js'

  import FormFields from './form-fields.vue'

  export default {
    name: 'FirebaseEdit',

    data: function () {
      return {
        // item: {}
        key: '',
        fields: [
          {
            label: 'Name',
            type: 'text',
            key: 'name'
          },
          {
            label: '<NAME>',
            type: 'text',
            key: 'lastName',
            default: '<NAME>'
          },
          {
            label: 'Age',
            type: 'text',
            key: 'age'
          },
          {
            label: 'Switch',
            type: 'switch',
            key: 'switch'
          },
          {
            label: 'Select',
            type: 'select',
            key: 'select',
            default: '3',
            options: [
              { value: 1, text: 'USD' },
              { value: 2, text: 'EUR' },
              { value: 3, text: 'UAH' },
            ]
          },
          {
            label: 'Color',
            type: 'color',
            key: 'color',
            default: '#03ff00'
          },
        ]

      }
    },
    firebase: {
      // items: firebase.database().ref('null'),
      item: {
        source: firebase.database().ref(),
        asObject: true,
        cancelCallback: function () {
          console.error('cancelCallback')
        }
      }
    },
    watch: {
      key: function (value, oldValue) {
        console.log('KEY changed', value, oldValue)
        this.$firebaseRefs && this.$firebaseRefs.item && this.$unbind('item')
        this.$bindAsObject('item', firebase.database().ref(value))
      },
      item: {
        handler: function (value, oldValue) {
          var vm = this
          var res = JSON.parse(JSON.stringify(value))
          delete res['.key']
          console.log('item changed', value, oldValue, value['.key'], Object.keys(value))
          if (value['.key']) {
            firebase.database().ref(this.key).set(res)
              .then(function () {
                // console.log('Synchronization succeeded');
              })
              .catch(function (error) {
                console.log('Synchronization failed', error);
                vm.$f7.alert(error, 'Firebase')
              });
          }
        },
        deep: true
      }
    },
    mounted: function () {
      console.log('$route', this.$route.params.key, this.$route)
      this.key = this.$route.path.substring(6)
    },
    components: {
      'form-fields': FormFields
    }
  }
</script>
{'fraction_non_alphanumeric': 0.1607316598560031, 'fraction_numerical': 0.005253940455341506, 'mean_word_length': 1.3708487084870848, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '2085369', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1491, 'n_words': 296}