Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
giuseppe-esposito-87 opened this issue Jun 15, 2020 · 3 comments
Closed

Comments

@giuseppe-esposito-87
Copy link

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
Copy link
Owner

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
Copy link
Owner

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!

@giuseppe-esposito-87
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants