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>
|
<script>
|
||||||
import gql from 'graphql-tag'
|
import gql from 'graphql-tag'
|
||||||
import Avatar from '../components/Avatar'
|
import Avatar from '../components/Avatar'
|
||||||
|
import { debounce } from '../utils/debounce'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'UserPresence',
|
name: 'UserPresence',
|
||||||
|
@ -291,11 +292,11 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
watch: {
|
watch: {
|
||||||
search(newValue) {
|
search() {
|
||||||
if (this.$route.query.search != newValue) this.updateQuery()
|
this.updateQuery()
|
||||||
},
|
},
|
||||||
onlyServants(newValue) {
|
onlyServants() {
|
||||||
if (this.$route.query.onlyServants != newValue) this.updateQuery()
|
this.updateQuery()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -362,12 +363,14 @@ export default {
|
||||||
}[status]
|
}[status]
|
||||||
},
|
},
|
||||||
updateQuery() {
|
updateQuery() {
|
||||||
this.$router.replace({
|
debounce(() =>
|
||||||
query: {
|
this.$router.replace({
|
||||||
search: this.search,
|
query: {
|
||||||
onlyServants: this.onlyServants
|
search: this.search || undefined,
|
||||||
}
|
onlyServants: this.onlyServants || undefined
|
||||||
})
|
}
|
||||||
|
})
|
||||||
|
)()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user