I agree there is no need for getters if you're accessing a basic, non-computed state. To me, 'basic' means one or at most two levels deep into the state. e.g. state.selectedOrder.deliveryTime
However, when accessing beyond two levels, I generally like using a getter. So state.selectedOrder.deliveryTime.date becomes getters.deliveryDate
This makes it easier to read components which are using this state imo. If you combine this with ...mapGetters[] you can write very succinct components like: <span>{{ deliveryDate }}<span>
Instead of: <span>{{ $state.selectedOrder.deliveryTime.date }}<span>
Oh, really good point! I'm going to work on rolling this into the main text, if you don't mind (crediting you, of course). I wouldn't want others to miss it.
Great post Joe, thanks!
I agree there is no need for getters if you're accessing a basic, non-computed state. To me, 'basic' means one or at most two levels deep into the state. e.g.
state.selectedOrder.deliveryTime
However, when accessing beyond two levels, I generally like using a getter. So
state.selectedOrder.deliveryTime.date
becomesgetters.deliveryDate
This makes it easier to read components which are using this state imo. If you combine this with ...mapGetters[] you can write very succinct components like:
<span>{{ deliveryDate }}<span>
Instead of:
<span>{{ $state.selectedOrder.deliveryTime.date }}<span>
Oh, really good point! I'm going to work on rolling this into the main text, if you don't mind (crediting you, of course). I wouldn't want others to miss it.
That's great! Feel free to! 😊