Skip to content

Commit

Permalink
refactor: debounce the journal input text entry (#1212)
Browse files Browse the repository at this point in the history
* refactor: debounce the journal input text entry

* bump debounce period to 750

* fix comment
  • Loading branch information
jaredgalanis authored Sep 26, 2023
1 parent 37c41e2 commit 3473e89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 18.15.0
2 changes: 1 addition & 1 deletion app/components/find-journal/index.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{! template-lint-disable no-action }}
<PowerSelect
@triggerClass={{if (eq @journalClass "is-invalid") (local-class "is-invalid") (local-class "is-valid")}}
@search={{this.searchJournals}}
@search={{perform this.searchJournals}}
@searchEnabled={{true}}
@selected={{@value}}
@placeholder="Journal"
Expand Down
11 changes: 8 additions & 3 deletions app/components/find-journal/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import Component from '@glimmer/component';
import { dropTask } from 'ember-concurrency-decorators';
import { timeout } from 'ember-concurrency';

const DEBOUNCE_MS = 750;

export default class FindJournal extends Component {
@service store;
Expand All @@ -14,10 +18,11 @@ export default class FindJournal extends Component {
* @param {string} term The search term
* @returns {array} array of Journals
*/
@action
searchJournals(term) {
@dropTask
searchJournals = function* (term) {
yield timeout(DEBOUNCE_MS);
return this.autocomplete.suggest('journal', 'journalName', term);
}
};

@action
onSelect(selected) {
Expand Down

0 comments on commit 3473e89

Please sign in to comment.