vuejs / vuex

🗃️ Centralized State Management for Vue.js.
https://vuex.vuejs.org
MIT License
28.41k stars 9.58k forks source link

fix: avoid resetting store state when registering a dynamic module #2234

Open alecgibson opened 1 year ago

alecgibson commented 1 year ago

Fixes https://github.com/vuejs/vuex/issues/2197

At the moment, when registering a dynamic module, we call resetStoreState() just to register the getters for the new module.

It seems unnecessary to reset the entire store state in this case, and this actually also leads to other issues.

This change is based on the test case added in https://github.com/vuejs/vuex/pull/2201

The approach taken in this change is to refactor the getter registration into its own function, and call that new method when registering a dynamic module instead of resetting the store state.

netlify[bot] commented 1 year ago

Deploy Preview for vuex-docs ready!

Name Link
Latest commit f46e028f9f27c24cb14e4cc73c17999d383b9bcc
Latest deploy log https://app.netlify.com/sites/vuex-docs/deploys/64f0a85148bda40008442370
Deploy Preview https://deploy-preview-2234--vuex-docs.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

alecgibson commented 1 year ago

Okay I thought this would be cleaner than https://github.com/vuejs/vuex/pull/2201 but it unfortunately doesn't handle module unregistration (which also clobbers the state). I think the approach in this PR would need basically a full rewrite of the unregisterModule() method to avoid completely resetting the rest of the store state, which is a pretty big change. Happy to do it if it's a direction that people want to go in, but otherwise let's go for https://github.com/vuejs/vuex/pull/2201