`createNamespacedHelpers` return mappers that need `this`
See original GitHub issueVersion
3.1.2
Reproduction link
[https://jsfiddle.net/davidmeirlevy/9hbqjmg2/34/)
Steps to reproduce
get a mapper:
const { mapActions } = createNamespacedHelpers(MODULE_NAME)
map some action:
const {action} = mapActions(['action'])
run this action directly, without adding it to a component methods:
action()
What is expected?
the action should be dispacthed
What is actually happening?
This line breaks because we didn’t ran this function from a vue component context:
var dispatch = this.$store.dispatch;
when we want to use the mappers from the setup()
function of the composition-api, the component’s this
shouldn’t be relevant, so you should probably find another way to map actions without expecting being executed as a vue component’s method.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Vuex: createNamespacedHelpers with dynamic namespace
This style of work around by utilising beforeCreate to access the variables you want should work, I did this from the props passed...
Read more >How to use Vuex mappers inside Vue Composition API?
I wanted to use the createNamespacedHelpers to get the mappers only once inside my compositions files, so I can export those methods once...
Read more >Modules | Vuex
If you want your modules to be more self-contained or reusable, you can mark it as namespaced with namespaced: true .
Read more >Vuex: createNamespacedHelpers with dynamic namespace ...
So I just wanted to let everyone know that brophdawg11 (one of the commenters on the issue #863) created (and open sourced) set...
Read more >Mapping state from multiple namespaced vuex modules to a ...
Vuex has this helper-function which is supposed to make it easier to work with namespaced vuex modules. store/user.js import { createNamespacedHelpers } from...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Probably. Not 100% sure just yet, but I guess something like that 👍
We would not reuse
mapXXX
helpers forsetup
usage as they are totally different things and supporting both on one helper function will complicate the implementation. We are working on Vue v3 + Vuex now and consideringuseXXX
composition function forsetup
.