Added debounce.js
This commit is contained in:
parent
1e1d8da7f8
commit
3014acd2a5
9
web/src/utils/debounce.js
Normal file
9
web/src/utils/debounce.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
export function debounce(func, timeout = 500) {
|
||||
let timer
|
||||
return (...args) => {
|
||||
clearTimeout(timer)
|
||||
timer = setTimeout(() => {
|
||||
func.apply(this, args)
|
||||
}, timeout)
|
||||
}
|
||||
}
|
|
@ -269,6 +269,7 @@
|
|||
<script>
|
||||
import gql from 'graphql-tag'
|
||||
import Avatar from '../components/Avatar'
|
||||
import { debounce } from '../utils/debounce'
|
||||
|
||||
export default {
|
||||
name: 'UserPresence',
|
||||
|
@ -291,11 +292,11 @@ export default {
|
|||
},
|
||||
|
||||
watch: {
|
||||
search(newValue) {
|
||||
if (this.$route.query.search != newValue) this.updateQuery()
|
||||
search() {
|
||||
this.updateQuery()
|
||||
},
|
||||
onlyServants(newValue) {
|
||||
if (this.$route.query.onlyServants != newValue) this.updateQuery()
|
||||
onlyServants() {
|
||||
this.updateQuery()
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
@ -362,12 +363,14 @@ export default {
|
|||
}[status]
|
||||
},
|
||||
updateQuery() {
|
||||
this.$router.replace({
|
||||
query: {
|
||||
search: this.search,
|
||||
onlyServants: this.onlyServants
|
||||
}
|
||||
})
|
||||
debounce(() =>
|
||||
this.$router.replace({
|
||||
query: {
|
||||
search: this.search || undefined,
|
||||
onlyServants: this.onlyServants || undefined
|
||||
}
|
||||
})
|
||||
)()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user