Skip to content

Commit 6c2ea20

Browse files
committed
feat(Screen): add setDebounce() method
1 parent 04b67e9 commit 6c2ea20

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/plugins/screen.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ export default {
6868
}
6969

7070
update()
71-
update = debounce(update, 100)
71+
let updateEvt = debounce(update, 100)
7272

73-
window.addEventListener('resize', update, listenOpts.passive)
73+
window.addEventListener('resize', updateEvt, listenOpts.passive)
7474

7575
this.setSizes = sizes => {
7676
['sm', 'md', 'lg', 'xl'].forEach(name => {
@@ -80,6 +80,13 @@ export default {
8080
})
8181
update()
8282
}
83+
this.setDebounce = delay => {
84+
window.removeEventListener('resize', updateEvt, listenOpts.passive)
85+
updateEvt = delay > 0
86+
? debounce(update, delay)
87+
: update
88+
window.addEventListener('resize', updateEvt, listenOpts.passive)
89+
}
8390

8491
Vue.util.defineReactive($q, 'screen', this)
8592
}

0 commit comments

Comments
 (0)