question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

state values not accessible in dynamic modules

See original GitHub issue

I’d like to report a bug

Given the following code:

@Module({ dynamic: true, store, name: 'user' })
class User extends VuexModule implements IUserState {
  token = 'something';

  @MutationAction({ mutate: [ 'roles', 'name', 'avatar' ] })
  async GetInfo(input: string) {
    log.debug(this.token)
    log.debug(input)
   ...
  }

When executing this MutationAction from outside the module, the logging of this.token returns undefined. However, If I pass the value from this module from outside this module as the input parameter, then I can get the correct value:

UserModule.GetInfo(UserModule.token).then(() => { ... }

So UserModule.token does provide the correct value, only you need to re-enter it in the module… which does not make much sense, but it’s a workaround anyway.

I also observed that while debugging, the token value inside the Module can be accessed by using this.state.token instead of this.token. The only problem with this, is that typescript does not accept this as valid typings…

I don’t know if this has something to do with dynamic modules or a more generic bug. Just leaving this here.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:8
  • Comments:26 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
darylteocommented, Aug 1, 2019

I ran into maybe a similar issue and racked my brains for quite awhile until I figured it out.

vuex-module-decorators does not know if your module is namespaced or not and may get confused. That’s what the namespaced option in the @Module decorator is for.

I think for 99% percent of use cases this should be set to true.

2reactions
Kapcashcommented, Mar 16, 2019

I’m having the same issue, and I don’t find any elegant workaround. I don’t get why we can’t access the state within an action, in the vuex documentation this seems to be allowed.

Anyway, and as hectorj is mentionning, accessing the state within an action method using getters doesn’t work either.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using state inside @ModuleAction of vuex-module-decorators
What I want is to be able to reach a value set for the whole class, but this gives a typescript error. I...
Read more >
Modules | Vuex
When you set preserveState: true , the module is registered, actions, mutations and getters are added to the store, but the state is...
Read more >
Providing dependencies in modules - Angular
A provider is an instruction to the Dependency Injection system on how to obtain a value for a dependency. Most of the time,...
Read more >
Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code ... By using next/dynamic , the header component will not be included...
Read more >
Documentation - Modules - TypeScript
Import the entire module into a single variable, and use it to access the module ... Though not recommended practice, some modules set...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found