The make helper object provides functions to automatically generate Vuex mutations, actions, and getters based on a provided state object. This eliminates the need to write redundant 1:1 wiring functions for every state property.
Core Concepts
- Automatic Generation: Helpers create functions that map directly to your state structure.
- Mixing and Matching: You can use helpers to generate a subset of store members and mix them with your own manual declarations (e.g., custom actions or complex getters).
- Payload Support: Mutations generated by
make.mutations() support transparent sub-property writes using the Payload class.
Recommended Approach
While you can generate all three (mutations, actions, and getters), the Pathify-recommended approach is to eschew redundant getters and actions that simply proxy work to state and mutations. Instead, focus on creating mutations and let Pathify handle the heavy lifting for state access.
import { make } from 'vuex-pathify'
const state = {
items: [],
status: '',
filters: {
search: '',
sort: {}
}
}
// Generate mutations, actions, and getters
const mutations = make.mutations(state)
const actions = { ...make.actions(state) }
const getters = { ...make.getters(state) }
export default {
state,
mutations,
actions,
getters,
}