K
K
Kotaro Hiba2020-06-21 13:36:14
Vue.js
Kotaro Hiba, 2020-06-21 13:36:14

Is it worth doing the same type methods in vuex?

Hello, maybe the title is not quite correct, I immediately apologize. In general, I’m mastering vuex, learning to work with the server and that mutations that events actually repeat each other, in the sense that there is a bunch of functions they are almost of the same type
5eef375e09c10104179847.jpeg
. Maybe it’s worth making 1 universal function that will receive the right just the right parameter by type
updateData(state, data, nameData)
and do the same with getters, or would it be bad form to work with the framework?
PS This is my first framework, I don't know much about them at all.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Kitaev, 2020-06-21
@lina666

So, of course, it is possible, but the meaning of mutations and the view itself is lost. Mutation names tell the developer, both by the name itself and by the mutation logs in Vue DevTools, what happened. And it is very desirable if the mutation is called by some name close to the business. Not "set X value to Y position" (whatever you want to do), but "show header" or "make user logged in".

S
Sergey Nekrasov, 2020-06-22
@Judixel

One function is responsible for one action, no need for generic methods. It will be hard to maintain and over time you will cram more into it, it is universal.

M
Maksios, 2020-06-22
@Maksios

In such cases, I make the same type for internal use, and for external named ones that already use the same type inside

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question