I have a vuex store, like following:
import spreeApi from \'../../gateways/spree-api\'
// initial state
const state = {
products: [],
categories: []
}
// mu
In your case you should consider having only one mutation, namely SET_PRODUCTS.
// mutations
const mutations = {
SET_PRODUCTS: (state, response) => {
state.products = response.data.products
state.categories = state.products.map(function(product) { return product.category})
}
}
You should never have any need to call SET_CATEGORIES separately. Think about it! Categories can only mutate if products are changed. And products can change only through SET_PRODUCTS.