chore: replace search emitter with vue.emit

This commit is contained in:
2018-09-17 18:34:17 -07:00
parent 2c60ec4afc
commit b73957e7df
2 changed files with 12 additions and 14 deletions

View File

@@ -109,7 +109,7 @@ export default {
};
this.error = '';
emitter.emit('search', requirements);
this.$emit('search', requirements);
},
resetForm() {
this.$el.reset();

View File

@@ -8,7 +8,13 @@
<section class="section">
<div class="container">
<SearchForm :effects="effects" :uses="uses" :conditions="conditions" :flavors="flavors" />
<SearchForm
:effects="effects"
:uses="uses"
:conditions="conditions"
:flavors="flavors"
@search="onSearch"
/>
</div>
</section>
@@ -83,6 +89,10 @@ export default {
},
},
methods: {
onSearch(reqs) {
this.requirements = reqs;
this.updateMatches();
},
showDefaults(limit = 40) {
// const favs = store.get('favorites') || [];
// const favStrains = this.strains.filter(({ id }) => favs.indexOf(id) !== -1);
@@ -123,15 +133,6 @@ export default {
},
},
created() {
// function to handle search form submissions
this.searchListener = reqs => {
this.requirements = reqs;
this.updateMatches();
};
// listen for search form submissions
emitter.on('search', r => this.searchListener(r));
// listen for favorite changes
emitter.on('favorite', ({ id, isFav }) => {
const favs = store.get('favorites') || [];
@@ -147,8 +148,5 @@ export default {
this.updateMatches(); // set initial match list
},
beforeDestroy() {
emitter.off('search', r => this.searchListener(r));
},
};
</script>