Added debounce.js

This commit is contained in:
Douglas Barone 2022-05-04 14:30:27 +00:00
parent 1e1d8da7f8
commit 3014acd2a5
2 changed files with 22 additions and 10 deletions

View File

@ -0,0 +1,9 @@
export function debounce(func, timeout = 500) {
let timer
return (...args) => {
clearTimeout(timer)
timer = setTimeout(() => {
func.apply(this, args)
}, timeout)
}
}

View File

@ -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
}) }
})
)()
} }
} }
} }