davestewart / vuex-pathify

Vue / Vuex plugin providing a unified path syntax to Vuex stores
https://davestewart.github.io/vuex-pathify
MIT License
1.37k stars 57 forks source link

Is possible to commit a mutation in a component using pathify? #106

Closed Peppe87 closed 4 years ago

Peppe87 commented 4 years ago

Hi, as the title says: I have a very simple store with a couple of variables. I set up the mutations using Pathify but I did not created actions\getters as they do not require any extra logic.

I'd like for consistence to use pathify, in the components, to commit the values, but I can't understand if that is possible and how; I managed to do so only using 'call' after creating the actions in the store.

I've already checked some the examples and some older issues, but yet I didn't solve my doubts.

Probably it's a overkill but I've set up a simple example to show what I'm trying to do.

Btw, it is unrelated but as you can see the 'get' in codesandbox for some reason doesn't work - it does not work even in the basic demo I've forked from.

davestewart commented 4 years ago

Hey,

Just checked your demo, and it looks like something is not quite right.

The get() result is a function, where of course it should be displaying as the getter value.

Not 100% sure why it is doing this. I just checked the basic code sandbox demo and it has the same behaviour:

So I suspect that Code Sandbox has recently had an update that is not rendering Vue files properly. I've filed a bug here:

As for your issue, you can use this.$store.set('SET_MY_VALUE', 123) and that will work.

The reason it is so verbose, is because Pathify maps key names using a naming strategy or "mapping" option:

So the mutation for myValue would be mapped to SET_MY_VALUE if you are using the default "standard" mapping.

I prefer the "simple" mapping which uses a 1:1 approach.

You can also import commit directly from Vuex Pathify (it just aliases the existing one).

Does that answer your question?

davestewart commented 4 years ago

OK, turns out is was a newly-introduced bug with CS, and they've just fixed it, so that should make the demo look a little more sane.

LMK about everything else!

Peppe87 commented 4 years ago

As for your issue, you can use this.$store.set('SET_MY_VALUE', 123) and that will work.

The reason it is so verbose, is because Pathify maps key names using a naming strategy or "mapping" option:

So the mutation for myValue would be mapped to SET_MY_VALUE if you are using the default "standard" mapping.

I prefer the "simple" mapping which uses a 1:1 approach.

You can also import commit directly from Vuex Pathify (it just aliases the existing one).

Does that answer your question?

Yes, this totally answer my question; in other words you have anyway to use a "verbose" approach.

Thank you.