import { viewport } from '../../utils/dom'
import { listenOpts } from '../../utils/event'

export default {
  name: 'QWindowResizeObservable',
  render () {},
  methods: {
    trigger () {
      if (!this.timer) {
        this.timer = window.requestAnimationFrame(this.emit)
      }
    },
    emit () {
      this.timer = null
      this.$emit('resize', viewport())
    }
  },
  created () {
    this.emit()
  },
  mounted () {
    window.addEventListener('resize', this.trigger, listenOpts.passive)
  },
  beforeDestroy () {
    window.removeEventListener('resize', this.trigger, listenOpts.passive)
  }
}

import { viewport } from '../../utils/dom'
import { listenOpts } from '../../utils/event'

export default {
  name: 'QWindowResizeObservable',
  props: {
    debounce: {
      type: Number,
      default: 80
    }
  },
  render () {},
  methods: {
    trigger () {
      if (this.debounce === 0) {
        this.emit()
      }
      else if (!this.timer) {
        this.timer = setTimeout(this.emit, this.debounce)
      }
    },
    emit () {
      this.timer = null
      this.$emit('resize', viewport())
    }
  },
  created () {
    this.emit()
  },
  mounted () {
    window.addEventListener('resize', this.trigger, listenOpts.passive)
  },
  beforeDestroy () {
    clearTimeout(this.timer)
    window.removeEventListener('resize', this.trigger, listenOpts.passive)
  }
}

Improve QWindowResizeObservable delay