<commit_before><template>
  <div class="viewer" v-bind:data-fileFormat='fileFormat'>
    <viewerPages 
      v-if="fileFormat === 'pages'"
      :htmlData="getHtmlData"
      :scrollPosition="scrollPosition"
      v-on:updateEditorScrollPosition="updateEditorScrollPosition"
    ></viewerPages>
    <viewerSlides 
      v-else-if="fileFormat === 'slides'"
      :htmlData="getHtmlData"
      :scrollPosition="scrollPosition"
      v-on:updateEditorScrollPosition="updateEditorScrollPosition"
    ></viewerSlides>
    <viewerHtml 
      v-else 
      :htmlData="getHtmlData"
      :scrollPosition="scrollPosition"
      v-on:updateEditorScrollPosition="updateEditorScrollPosition"
    ></viewerHtml>
  </div>
</template>

<script>
  import Vue from 'vue';
  import AsyncComputed from 'vue-async-computed';
  import documentPackager from 'src/logic/documentPackager';
  import DocumentPrinter from 'src/logic/inputHandler/DocumentPrinter';
  import viewerPages from './Viewers/Pages';
  import viewerSlides from './Viewers/Slides';
  import viewerHtml from './Viewers/Html';

  Vue.use(AsyncComputed);

  let documentPrinter = null;

  export default {
    components: {
      viewerPages,
      viewerSlides,
      viewerHtml,
    },
    props: ['editorContent', 'fileFormat', 'scrollPosition'],
    asyncComputed: {
      getHtmlData() {
        return documentPackager.getHtmlData(this.editorContent);
      }
    },
    watch: {
      fileFormat() {
        // Update event listener reference on fileFormat change
        documentPrinter.setDomBehaviour();
      }
    },
    methods: {
      updateEditorScrollPosition(newLinePosition) {
        this.$emit('updateEditorScrollPosition', newLinePosition);
      }
    },
    mounted() {
      Vue.nextTick(() => {
        documentPrinter = new DocumentPrinter(window, this, 'editorContent');
      });
    },
    beforeDestroy() {<commit_msg>Add throttle function to markdown parsing<commit_after><template>
  <div class="viewer" v-bind:data-fileFormat='fileFormat'>
    <viewerPages 
      v-if="fileFormat === 'pages'"
      :htmlData="htmlData"
      :scrollPosition="scrollPosition"
      v-on:updateEditorScrollPosition="updateEditorScrollPosition"
    ></viewerPages>
    <viewerSlides 
      v-else-if="fileFormat === 'slides'"
      :htmlData="htmlData"
      :scrollPosition="scrollPosition"
      v-on:updateEditorScrollPosition="updateEditorScrollPosition"
    ></viewerSlides>
    <viewerHtml 
      v-else 
      :htmlData="htmlData"
      :scrollPosition="scrollPosition"
      v-on:updateEditorScrollPosition="updateEditorScrollPosition"
    ></viewerHtml>
  </div>
</template>

<script>
  import Vue from 'vue';
  import _ from 'lodash';
  import AsyncComputed from 'vue-async-computed';
  import documentPackager from 'src/logic/documentPackager';
  import DocumentPrinter from 'src/logic/inputHandler/DocumentPrinter';
  import viewerPages from './Viewers/Pages';
  import viewerSlides from './Viewers/Slides';
  import viewerHtml from './Viewers/Html';

  Vue.use(AsyncComputed);

  let documentPrinter = null;
  const htmlParserTrottleFn = _.throttle(function parseFn(data) {
    documentPackager.getHtmlData(data)
    .then((htmlData) => {
      this.htmlData = htmlData;
    });
  }, 1000);

  export default {
    components: {
      viewerPages,
      viewerSlides,
      viewerHtml,
    },
    data() {
      return {
        htmlData: '',
      };
    },
    props: ['editorContent', 'fileFormat', 'scrollPosition'],
    watch: {
      fileFormat() {
        // Update event listener reference on fileFormat change
        documentPrinter.setDomBehaviour();
      },
      editorContent(data) {
        htmlParserTrottleFn.call(this, data);
      }
    },
    methods: {
      updateEditorScrollPosition(newLinePosition) {
        this.$emit('updateEditorScrollPosition', newLinePosition);
      }
    },
    mounted() {
      Vue.nextTick(() => {
        documentPrinter = new DocumentPrinter(window, this, 'editorContent');
      });
    },
    beforeDestroy() {
{'fraction_non_alphanumeric': 0.12320633349826818, 'fraction_numerical': 0.0009896091044037606, 'mean_word_length': 3.220250521920668, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 28, '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': '1213072', 'n_tokens_mistral': 1220, 'n_tokens_neox': 1181, 'n_words': 209}