Syntactic sugar helpers to leverage Vuex usage and write less repetitive code.
npm i gist:7b2bec2ef24eb5c1d30d83660af49ed6
import { createStore } from 'vuex';
import { set, remove, filterBy } from 'vuex-saccharin';
import api from './services/api';
export default createStore({
state: {
users: [],
},
mutations: {
SET_USERS: set('users'),
REMOVE_USER: remove('users', 'id'),
},
actions: {
loadUsers: async ({ commit }) => {
const users = await api.getUsers();
commit('SET_USERS', users);
},
removeUser: ({ commit }, id) => commit('REMOVE_USER', id),
}
});