Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Use namespaced modules for Vuex store #229

Closed
wants to merge 4 commits into from

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Sep 16, 2021

Fixes

Fixes #205 by @dhruvkb

Description

This PR refactors one mega-store that we currently have into namespaced modules inside the store directory.

Technical details

Tests

Screenshots

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the default branch of the repository (main or master).
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@obulat obulat requested a review from a team as a code owner September 16, 2021 03:48
@obulat obulat added ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository 🟧 priority: high Stalls work on the project or its dependents labels Sep 16, 2021
@dhruvkb
Copy link
Member

dhruvkb commented Sep 16, 2021

Nearly a hundred files changed! That'll be an intense review (although all checks passed so that's a good sign).

@dhruvkb dhruvkb added this to Needs review in Openverse Sep 16, 2021
@obulat
Copy link
Contributor Author

obulat commented Sep 16, 2021

Nearly a hundred files changed! That'll be an intense review (although all checks passed so that's a good sign).

I guess I should exchange this intense review with the review of WordPress/openverse-api#194 :)

With all store modules becoming namespaced, all calls of commit, dispatch and mapState had to be changed to add the namespace to them, that is one of the reasons for so many changes.
Another one is it has to be all or nothing change (or I don't know how to have both with the current structure).
The checks pass because I commented out some of the tests that fail because I haven't yet figured out how to mock namespaced actions

@zackkrida
Copy link
Member

@obulat I haven't read this yet but it appears to talk about mocking namespaced actions https://al-un.github.io/learn-nuxt-ts/06.test.html#mocking-vuex-store I'll check later when I review this.

So much work! That's why I didn't do this as part of the original Nuxt migration 😅

@obulat obulat mentioned this pull request Sep 18, 2021
7 tasks
@obulat obulat changed the base branch from main to use_map_helpers_in_components September 18, 2021 07:27
@obulat obulat changed the base branch from use_map_helpers_in_components to main September 18, 2021 07:31
@obulat obulat changed the base branch from main to use_map_helpers_in_components September 18, 2021 07:31
# Conflicts:
#	src/constants/mutation-types.js
#	src/middleware/middleware.js
#	src/store-modules/nav-store.js
#	src/store/active-media-store.js
#	src/store/index.js
Comment on lines +96 to +98
...mapActions({
fetchMedia: `${SEARCH}/${FETCH_MEDIA}`,
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For binding namespaced actions, provide the name of the module as the first argument for the mapActions call.

Suggested change
...mapActions({
fetchMedia: `${SEARCH}/${FETCH_MEDIA}`,
}),
...mapActions(SEARCH, [
FETCH_MEDIA,
]),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, that's a great suggestion @dhruvkb I didn't know you could do that. Bye string concatenation!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like mapActions because they allow us to use the actions by calling them just like regular Vue methods.
In this case, we can write this.fetchMedia() instead of this[FETCH_MEDIA]().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case we can do

...mapActions(SEARCH, {
  fetchMedia: FETCH_MEDIA
}),

@obulat
Copy link
Contributor Author

obulat commented Sep 21, 2021

Closing this PR as it was replaced by #244 and #242.

@obulat obulat closed this Sep 21, 2021
Openverse automation moved this from Needs review to Done! Sep 21, 2021
@obulat obulat deleted the store_modules branch November 26, 2021 07:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟧 priority: high Stalls work on the project or its dependents
Projects
No open projects
Openverse
  
Done!
Development

Successfully merging this pull request may close these issues.

[Feature] Break down megastore into smaller modules
3 participants