Question: I have a [vuex](https://vuex.vuejs.org/en/intro.html) store, like following:

```
import spreeApi from '../../gateways/spree-api'
// initial state
const state = {
  products: [],
  categories: []
}

// mutations
const mutations = {
 SET_PRODUCTS: (state, response) => {
   state.products = response.data.products
   commit('SET_CATEGORIES')
 },
 SET_CATEGORIES: (state) => {
   state.categories = state.products.map(function(product) { return product.category})
 }

}

const actions = {
 FETCH_PRODUCTS: (state, filters) => {
   return spreeApi.get('products').then(response => state.commit('SET_PRODUCTS', response))
 }
}

export default {
  state,
  mutations,
  actions
}

```

I want to call mutation: `SET_CATEGORIES` from mutation: `SET_PRODUCTS`, But this gives me error: 

> 
> projectFilter.js:22 Uncaught (in promise) ReferenceError: commit is not defined(…)
> 
> 
> 

What should be correct way to do this. I tried `store.commit` and `this.commit`, but these also gave similar errors.

Answer: 
To share code between mutations, you must create a new function that performs the work, which you can then reuse. Fortunately, mutations are just plain old functions, and we can pass the `state` parameter around however we like, so this is quite easy to do.

For example:

```js
const mutations = {
 SET_PRODUCTS: (state, response) => {
   state.products = response.data.products
   setCategories(state)
 },
 SET_CATEGORIES: (state) => {
   setCategories(state)
 }
}

function setCategories(state) {
  state.categories = state.products.map(product => product.category)
}

```
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.