-
Notifications
You must be signed in to change notification settings - Fork 63
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this a ton locally, everything is working great 😻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very massive undertaking. Thanks for simplifying this!
I've pointed out some changes, mostly including stylistic changes but one bug as well. These occur several times in the PR but I'm only highlighting one occurrence for brevity.
src/components/AudioResultsList.vue
Outdated
return this.$store.state.audios | ||
}, | ||
...mapState({ | ||
audios: (state) => state.audios, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arrow functions that map to state properties can be replaced with strings:
audios: (state) => state.audios, | |
audios: 'audios', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The strings do not work for namespaced stores, so for consistency I used the same syntax everywhere.
I thought that only Webstorm for some reason doesn't like dots in mapState (and warns about them), but apparently it's a Vuex limitation, see vuejs/vuex#459 and vuejs/vuex#1592
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For namespaced stores, the syntax is to use /
, not .
as the separator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried out different versions of state mapping in both WebStorm and Visual Studio Code, here are some results I get:
-
...mapState(REPORT_CONTENT, { isReportFormVisible: 'isReportFormVisible' })
(+) Clear, easy to set for namespaced modules.
(-) Error-prone: No autocomplete in either WebStorm or Visual Studio Code, the property is not a constant
(-) Webstorm shows a warning about 'isReportFormVisible': "Cannot resolve Vuex state isReportFormVisible"
(-) Not clear if it works for nested objects -
...mapState(REPORT_CONTENT, { isReportFormVisible: (state) => state.isReportFormVisible, }),
(-) Verbose
(+) Easier to avoid errors: both WebStorm and Visual Studio Code autocomplete the property after the dot (isReportFormVisible
)
(+) No warnings. -
...mapState(REPORT_CONTENT, ['isReportFormVisible'])
(+) Short
(-) Error prone: No autocomplete in either WebStorm or Visual Studio Code, the property is not a constant
(-) WebStorm warns that it "Cannot resolve Vuex state isReportFormVisible".
(-) Does not work well for nested objects (such as thequery
object in the search store)
src/components/AudioResultsList.vue
Outdated
...mapActions({ | ||
fetchMedia: `${FETCH_MEDIA}`, | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please correct @dhruvkb's handle in the PR description. |
Co-authored-by: Dhruv Bhanushali <dhruv_b@live.com>
# Conflicts: # src/components/NotificationBanner.vue # src/pages/search.vue
Make most of the Vuex store modules namespaced
# Conflicts: # src/store-modules/related-media-store.js # src/store-modules/search-store.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really massive undertaking with a lot of code quality improvements!
There are still a large number of direct calls to $store.state
, $store.dispatch
etc. Are they intentionally not using map*
helpers?
@@ -107,7 +107,7 @@ export default { | |||
) | |||
// Sync status from store to parent | |||
watch( | |||
() => [store.state.activeMediaType, store.state.activeMediaId], | |||
() => [store.state['active-media'].type, store.state['active-media'].id], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Nuxt automatically use the file name? Can we use the activeMedia
name for the module to avoid []
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, yes, Nuxt uses the file name, and we cannot use the camelCased version. We could rename the store module to active
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That'll be a good idea! I would've liked if Nuxt offered to option to name the state but we've got to work with what we have.
state.active
will be better than state['active-media']
.
Yes, they are not using |
Fixes
Related #205 by @dhruvkb and #229 by @obulat
Description
In an attempt to break the huge #229 into two parts, I extracted all the changes in the components into this PR.
Technical details
This PR contains many small refactorings replacing direct store calls (
this.$store.dispatch('actionName')
) with mapped versions (mapActions
,mapMutations
andmapState
) in order to simplify component code.Some actions here use a seemingly unnecessary string interpolation (
this.commit(`${MUTATION_NAME_CONSTANT}`)
). In fact, they are left this way to make adding module name easier in #229.Checklist
Update index.md
).main
ormaster
).Developer Certificate of Origin
Developer Certificate of Origin