Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use also actions and not only mutations? #131

Open
mdiaz-payvision opened this issue Jan 22, 2021 · 0 comments
Open

Can we use also actions and not only mutations? #131

mdiaz-payvision opened this issue Jan 22, 2021 · 0 comments

Comments

@mdiaz-payvision
Copy link

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',
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant