open-nomad/ui/app/components/search-box.js

28 lines
645 B
JavaScript
Raw Normal View History

import { reads } from '@ember/object/computed';
import Component from '@ember/component';
import { run } from '@ember/runloop';
2017-09-19 14:47:10 +00:00
export default Component.extend({
// Passed to the component (mutable)
searchTerm: null,
// Used as a debounce buffer
_searchTerm: reads('searchTerm'),
2017-09-19 14:47:10 +00:00
// Used to throttle sets to searchTerm
debounce: 150,
2017-09-30 00:41:12 +00:00
classNames: ['search-box', 'field', 'has-addons'],
2017-09-19 14:47:10 +00:00
actions: {
setSearchTerm(e) {
this.set('_searchTerm', e.target.value);
run.debounce(this, updateSearch, this.get('debounce'));
},
},
});
function updateSearch() {
this.set('searchTerm', this.get('_searchTerm'));
}