Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using both Vuex and emit events

I have recently started working in VueJS and I have been instructed by one of the lead devs to never combine emit events and vuex store. Basically, if the project will use a store, take all the events/state through the store.

From one point of view I can understand this, but there are a lot scenarios in which emiting an event is so much faster than taking everything through the store.

Is this the best practice by not combining Vuex and emit events?

like image 693
Darkkz Avatar asked Oct 24 '25 11:10

Darkkz


1 Answers

As a lead developer myself using Vue, this arbitrary rule is simply narrow-minded.

When using Vuex and deciding to use an emit or not, I look at the relationship. If I have a component that only needs to interact with its parent, then I use an emit. It keeps the store cleaner and the relationships clearer. Your lead is not making scalable or maintainable code.

If he/she argues you shouldn't use emits when you have a store, then following that logic, you shouldn't use props ever either. That is equally nonsensical.

Once you start working with applications that have several children down, you'll realize that jamming the store with every variable you'll need just for a few components way down the hierarchy creates a horrible mess of things.

like image 63
Arc Avatar answered Oct 27 '25 00:10

Arc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!