Skip to content

Commit 19ab26f

Browse files
committed
Debounce municipality query by 500 ms
1 parent e94a74c commit 19ab26f

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

vue/src/components/Search.vue

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
<script>
5050
import gql from 'graphql-tag';
51+
import _ from 'lodash';
5152
5253
export default {
5354
name: 'Search',
@@ -114,7 +115,19 @@ export default {
114115
});
115116
}
116117
}
117-
}
118+
},
119+
debouncedQuery: _.debounce(async (val, self) => {
120+
const result = await self.queryMunicipalities(val);
121+
self.municipalities = result.data.municipalities.edges;
122+
self.municipalities.forEach((item) => {
123+
const nrScans = item.node.snapshots.length;
124+
if (nrScans === 0) {
125+
item.node.fullnameWithSnapshots = `${item.node.fullname}`;
126+
} else {
127+
item.node.fullnameWithSnapshots = `${item.node.fullname}`;
128+
}
129+
});
130+
}, 500)
118131
},
119132
120133
computed: {
@@ -128,16 +141,7 @@ export default {
128141
129142
watch: {
130143
async search(val) {
131-
const result = await this.queryMunicipalities(val);
132-
this.municipalities = result.data.municipalities.edges;
133-
this.municipalities.forEach((item) => {
134-
const nrScans = item.node.snapshots.length;
135-
if (nrScans === 0) {
136-
item.node.fullnameWithSnapshots = `${item.node.fullname}`;
137-
} else {
138-
item.node.fullnameWithSnapshots = `${item.node.fullname}`;
139-
}
140-
});
144+
this.debouncedQuery(val, this);
141145
}
142146
}
143147
};

0 commit comments

Comments
 (0)