chore: replace error emitter with vue.emit

This commit is contained in:
2018-09-17 18:42:44 -07:00
parent 1f2e307f05
commit 3ab623fea1
2 changed files with 9 additions and 18 deletions

View File

@@ -76,8 +76,6 @@
</template> </template>
<script> <script>
import emitter from '../lib/emitter.mjs';
const getMultiValues = node => Array.from(node.selectedOptions).map(o => o.value); const getMultiValues = node => Array.from(node.selectedOptions).map(o => o.value);
export default { export default {
@@ -86,17 +84,10 @@ export default {
uses: Array, uses: Array,
conditions: Array, conditions: Array,
flavors: Array, flavors: Array,
error: {
type: String,
default: '',
}, },
data() {
return {
error: '',
};
},
created() {
emitter.on('error', this.setError);
},
beforeDestroy() {
emitter.off('error', this.setError);
}, },
methods: { methods: {
handleSubmit() { handleSubmit() {
@@ -108,15 +99,11 @@ export default {
flavors: getMultiValues(this.$refs.flavors), flavors: getMultiValues(this.$refs.flavors),
}; };
this.error = '';
this.$emit('search', requirements); this.$emit('search', requirements);
}, },
resetForm() { resetForm() {
this.$el.reset(); this.$el.reset();
}, },
setError(msg) {
this.error = msg;
},
}, },
}; };
</script> </script>

View File

@@ -13,6 +13,7 @@
:uses="uses" :uses="uses"
:conditions="conditions" :conditions="conditions"
:flavors="flavors" :flavors="flavors"
:error="error"
@search="onSearch" @search="onSearch"
/> />
</div> </div>
@@ -40,6 +41,7 @@ export default {
}, },
data() { data() {
return { return {
error: '',
matches: [], matches: [],
requirements: { requirements: {
name: '', name: '',
@@ -100,6 +102,8 @@ export default {
this.matches = this.strains.slice(0, limit); this.matches = this.strains.slice(0, limit);
}, },
updateMatches(limit = 40) { updateMatches(limit = 40) {
this.error = '';
if (!this.hasName && !this.hasFilters) { if (!this.hasName && !this.hasFilters) {
this.showDefaults(limit); this.showDefaults(limit);
return; return;
@@ -127,7 +131,7 @@ export default {
}); });
} catch (err) { } catch (err) {
this.matches = []; this.matches = [];
emitter.emit('error', err.message); this.error = err.message;
} }
}, },
}, },