🚧 Debounce of 500ms

This commit is contained in:
Kevin van der Werff
2019-11-07 00:52:25 +01:00
parent 35a11766d8
commit 73a53c8161
2 changed files with 12 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
<template lang="pug"> <template lang="pug">
input.search(v-model="searchInput" type="text" placeholder="Search (does not work currently, sorry)") input.search(v-model="searchInput" type="text" placeholder="Search")
</template> </template>
<script> <script>

View File

@@ -16,7 +16,6 @@
import Card from '../components/Card' import Card from '../components/Card'
import TableRow from '../components/TableRow' import TableRow from '../components/TableRow'
import * as R from 'ramda' import * as R from 'ramda'
// import { removeFirstChar } from '../utils/pure'
export default { export default {
components: { Card, TableRow }, components: { Card, TableRow },
@@ -27,6 +26,7 @@ export default {
searchInput: {}, searchInput: {},
showTitle: false, showTitle: false,
showCards: false, showCards: false,
debounceID: 0,
} }
}, },
computed: { computed: {
@@ -36,13 +36,16 @@ export default {
}, },
watch: { watch: {
$route(updatedChanges) { $route(updatedChanges) {
const keywords = updatedChanges.query.keywords clearTimeout(this.debounceID)
const tags = updatedChanges.query.tags this.debounceID = setTimeout(() => {
const newSearchInput = { const keywords = updatedChanges.query.keywords
keywords: keywords && R.split(',', keywords), const tags = updatedChanges.query.tags
tags: tags && R.split(',', tags), const newSearchInput = {
} keywords: keywords && R.split(',', keywords),
this.searchInput = newSearchInput tags: tags && R.split(',', tags),
}
this.searchInput = newSearchInput
}, 500)
}, },
searchInput(searchInput) { searchInput(searchInput) {
this.resources = this.$store.getters['data/findBySearchInputs'](searchInput.keywords, searchInput.tags) this.resources = this.$store.getters['data/findBySearchInputs'](searchInput.keywords, searchInput.tags)