Kitware / VolView

Kitware VolView: an all-in-one radiological viewer!
https://volview.kitware.com
Apache License 2.0
184 stars 60 forks source link

visualization module should be namespaced #11

Closed floryst closed 3 years ago

floryst commented 3 years ago

When namespacing a module, the most important part is ensuring that calls to mapActions, mapState, mapGetters, and dispatch are handled correctly. I've provided a few examples below.

https://github.com/KitwareMedical/paraview-medical/blob/master/src/components/VtkTwoView.vue#L73 is a mapState() call that accesses visualization.worldOrientation. This technically still works regardless of whether the module is namespaced, but we can be more succinct by rewriting it to be the following:

...mapState('visualization', ['worldOrientation', ...]),

In the same file, we have mapped actions here: https://github.com/KitwareMedical/paraview-medical/blob/master/src/components/VtkTwoView.vue#L479. Actions from un-namespaced modules are registered globally, but with namespaced modules we must make the appropriate mapActions invocation:

...mapActions('visualization', ['setWindowing', 'setSlices']),

Generally for the map* family of vuex functions, you want to (1) see if the mapped properties are part of the visualization module, and (2) make a call to map<State|Actions|Getters>('visualization', ...).

Finally, we have dispatches. Generally I don't think I have any store.dispatch() call that calls a visualization action, but if you ever get an error complaining about some action not existing, then it's probably a visualization action and the corresponding dispatch call should look like dispatch('visualization/<action_name>').