const debounce = require('lodash.debounce')

export default {
  data() {
    return {
      $__resizeHandler: null
    }
  },
  mounted() {
    this.$__resizeHandler = debounce(() => {
      if (this.$__chart) {
        this.$__chart.resize()
      }
    }, 100)
    this.$__initResizeEvent()
  },
  beforeDestroy() {
    this.$__destroyResizeEvent()
  },
  methods: {
    $__initResizeEvent() {
      window.addEventListener('resize', this.$__resizeHandler)
    },
    $__destroyResizeEvent() {
      window.removeEventListener('resize', this.$__resizeHandler)
    }
  }
}
