victorgarciaesgi / vuex-typed-modules

🧰 A VueX wrapper to fully type your modules without boilerplate!
35 stars 8 forks source link

Broken helpers methods with Vue3 + Vuex4 #23

Closed StazriN closed 3 years ago

StazriN commented 3 years ago

I'm using Vue 3 in my project and due to lack of type support in Vuex 4 (hope coming in Vuex 5) I use your package. Works perfectly except for the helper's method. I'm getting this error:

runtime-core.esm-bundler.js?9e79:217 Uncaught TypeError: Cannot read property 'set' of undefined
    at eval (index.js?c7ff:12)
    at Array.map (<anonymous>)
    at Store._mutations.resetState (index.js?c7ff:11)
    at wrappedMutationHandler (vuex.esm-bundler.js?58d9:808)
    at commitIterator (vuex.esm-bundler.js?58d9:438)
    at Array.forEach (<anonymous>)
    at eval (vuex.esm-bundler.js?58d9:437)
    at Store._withCommit (vuex.esm-bundler.js?58d9:596)
    at Store.commit (vuex.esm-bundler.js?58d9:436)
    at Store.boundCommit [as commit] (vuex.esm-bundler.js?58d9:376)

I think it's due to you are using the Vue.set() in your package.

Are you planning to upgrade your package for Vue 3 and Vuex 4 or not?

I use a workaround for resetState() with overriding it and calling my mutation for reset store state.

victorgarciaesgi commented 3 years ago

Hi @StazriN thanks for the report.

This lib is only working with Vue 2 I haven't tested it yet on Vue 3 and I have still no plan to port it yet. I will look at it, maybe it's just a registration issue. I'm waiting for the release of Vuex 5 and Nuxt 3 to fully refactor this project :(

victorgarciaesgi commented 3 years ago

Can you link me a reproduction for the bug you encountered with helpers methods? It may be fixable if all the rest works well

victorgarciaesgi commented 3 years ago

Probably coming from the fact that I use Vue.set on helpers methods. I will look at vue-demi to make it portable to Vue 3

victorgarciaesgi commented 3 years ago

Try updating vuex-typed-modules to 3.1.8, I've added vue-demi tell me if it works

StazriN commented 3 years ago

Helper's method resetState() now works as expected.

I also force set newer versions of Vue and Vuex in my package.json:

"resolutions": {
  "**/vuex": "4.0.0",
  "**/vue": "3.0.11",
},

and your package still works. Thank you so much for the very fast solution.

btw Do you have any info about the expected release date of Vuex 5?

victorgarciaesgi commented 3 years ago

Thanks for the update! (It was totally blind-coded so Yay)

I'm working on a new version of vuex-typed-modules that will provides typed hooks for each module.

No no info on Vuex5, besides the Rfc they released a while back. From my understanding it will look a lot like pinia api (same creator)

victorgarciaesgi commented 3 years ago

@StazriN Just so you now I released 4.0 with better Vue 3 support and module hooks!

StazriN commented 3 years ago

You are amazing @victorgarciaesgi !

This is the most elegant solution of Vuex missing types without any boilerplate (own enums, types, interfaces, etc.) and still, everything has a type and IntelliSense support.

Thank you so much for your work.

victorgarciaesgi commented 3 years ago

@StazriN Thanks man that means a lot to me. I have to be better at promoting it 😅