forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQWindowResizeObservable.js
More file actions
41 lines (40 loc) · 918 Bytes
/
QWindowResizeObservable.js
File metadata and controls
41 lines (40 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { listenOpts } from '../../utils/event.js'
import { onSSR, fromSSR } from '../../plugins/platform.js'
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 (ssr) {
this.timer = null
this.$emit('resize', {
height: ssr ? 0 : window.innerHeight,
width: ssr ? 0 : window.innerWidth
})
}
},
created () {
this.emit(onSSR)
},
mounted () {
fromSSR && this.emit()
window.addEventListener('resize', this.trigger, listenOpts.passive)
},
beforeDestroy () {
clearTimeout(this.timer)
window.removeEventListener('resize', this.trigger, listenOpts.passive)
}
}