maoberlehner/vuex-map-fields

Can we use also actions and not only mutations?

mdiaz-payvision opened this issue · 0 comments

Hi!

Sorry if this a very basic question. From the examples in the docs and the source code, I guess I only can fire mutations when a property is set. What about actions? What if I always wanto to call some API before making a mutation? In the example of custom getters and setters, it would be something like this:

Store

// ...
  getters: {
    getUserField(state) {
      return getField(state.user);
    },
  },
  mutations: {
    updateUserField(state, field) {
      updateField(state.user, field);
    },
  },
  actions: {
    updateAsyncUserField(state, field) {
      // Async task like a call to some API
      updateField(state.user, field);
    }
  }

Component

import { createHelpers } from 'vuex-map-fields';

const { mapFields } = createHelpers({
  getterType: 'getUserField',
  mutationType: 'updateUserField',
  actionType: 'updateAsyncUserField',
});