Skip to content

Commit 0e96b4f

Browse files
committed
search: Debounce the search query task
1 parent 9a83264 commit 0e96b4f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

app/controllers/search.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ import { computed } from '@ember/object';
33
import { alias, bool, readOnly } from '@ember/object/computed';
44
import { inject as service } from '@ember/service';
55

6-
import { task } from 'ember-concurrency';
6+
import { task, timeout } from 'ember-concurrency';
77

88
import PaginationMixin from '../mixins/pagination';
99

10+
const DEBOUNCE_MS = 250;
11+
1012
export default Controller.extend(PaginationMixin, {
1113
search: service(),
1214
queryParams: ['q', 'page', 'per_page', 'sort'],
@@ -40,10 +42,13 @@ export default Controller.extend(PaginationMixin, {
4042
hasItems: bool('totalItems'),
4143

4244
dataTask: task(function* (params) {
45+
// debounce the search query
46+
yield timeout(DEBOUNCE_MS);
47+
4348
if (params.q !== null) {
4449
params.q = params.q.trim();
4550
}
4651

4752
return yield this.store.query('crate', params);
48-
}).drop(),
53+
}).restartable(),
4954
});

0 commit comments

Comments
 (0)