Skip to content

fix: state objects don't work with submodules #100

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

Closed
andrewvasilchuk opened this issue Apr 25, 2020 · 8 comments
Closed

fix: state objects don't work with submodules #100

andrewvasilchuk opened this issue Apr 25, 2020 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@andrewvasilchuk
Copy link
Contributor

andrewvasilchuk commented Apr 25, 2020

🐛 The bug
I get the following issue during invocation of useAccessor function.

const storePattern = {
  state,
  mutations,
  modules: {
    foo,
  },
}

const store = new Vuex.Store(storePattern)

export const accessor = useAccessor(store, storePattern)
Uncaught TypeError: Cannot set property foo of #<Object> which has only a getter

🛠️ To reproduce
Try to invoke useAccessor with any module, which state declared as plain object.

🌈 Expected behaviour
I expect the correct module registration.

ℹ️ Additional context
Add any other context about the problem here.

@andrewvasilchuk andrewvasilchuk added the bug Something isn't working label Apr 25, 2020
@danielroe
Copy link
Owner

@andrewvasilchuk Fancy a repro? 🤞 I'm looking at the test code here, for example, and not seeing any issue with useAccessor and modules.

@andrewvasilchuk
Copy link
Contributor Author

@danielroe, Getting this issue when state is not typeof 'function'.

@danielroe
Copy link
Owner

@andrewvasilchuk Is this an error from TypeScript or a bug in the behaviour of the accessor? (I'm reading your report as the former.) I also take it that you are not using Nuxt?

@andrewvasilchuk
Copy link
Contributor Author

@danielroe, It's a runtime bug. I am not using Nuxt.js, so state is not a function.

@danielroe
Copy link
Owner

Thanks. It's definitely bad behaviour. Though I recommend a function, the accessor should definitely support a simple object.

Will investigate.

@andrewvasilchuk
Copy link
Contributor Author

@danielroe, Yes, a function solved the issue.

@danielroe
Copy link
Owner

danielroe commented Apr 29, 2020

If you have submodules defined, Vuex actually mutates the state object passed in - so that when the accessor is created, it gets a state object that is different from the one passed to Vuex.

For the moment, that means if you want to use typed-vuex you'll need to use a state function, which doesn't suffer from this kind of mutation by Vuex. I'll consider whether there is a simple way to enable state object usage.

@andrewvasilchuk
Copy link
Contributor Author

@danielroe, Thanks for the quick and comprehensive answer.

@danielroe danielroe changed the title fix: correct module registration fix: state objects don't work with submodules Jul 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants