Anton Kosykh
1 min readApr 2, 2018

--

Vuex is a state management but operates on what is out of its responsibility, isn’t it? 🤔

In my opinion, state management should manage state (suddenly).

Normal flow:

→ *Wanna do API request*
→ Send payload to API layer
→ API layer handles result
→ API layer says about changes to our store

You can say that API layer shouldn’t know about store and this is not its role but you can’t get around it. You should connect API and store anyway.

And now, let’s look at this:

Broken flow:

→ *Wanna do API request*
→ Send payload to store (wtf)
→ Store sends payload to API (wtf)
→ Store handles API result (wtf)
→ Store commits mutations

And, as a bonus, we have

  • Monkey-styled copy-paste of requests in application
  • Almost no code-splitting and re-using of our API because “we think that Vuex+ axios is enough and we don’t need any services etc”
  • Broken single-responsibility principle and one calledapi.doSmth() outside store kills everything.

These “mediators” are so useful so even Vue core team wants to merge ’em with mutations.

--

--

Anton Kosykh
Anton Kosykh

Written by Anton Kosykh

— Stricty pants nerd that sounds like total dork (according to one of the readers) — Also YOLO JavaScript Engineer

Responses (2)