Skip to content
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

Add support for namespace functions in mapXXX helpers #1510

Closed
wants to merge 1 commit into from

Conversation

brophdawg11
Copy link

This is a stab at adding the functionality requested by #863.

I also noticed that there was another attempt at this in #924, but the diff seems to be beyond the scope of just the change.

Unit tests have been added, but no changes have yet been made to TypeScript types or documentation, etc.

@@ -11,7 +11,13 @@ export const mapState = normalizeNamespace((namespace, states) => {
let state = this.$store.state
let getters = this.$store.getters
if (namespace) {
const module = getModuleByNamespace(this.$store, 'mapState', namespace)
if (typeof namespace === 'function') {
namespace = namespace.call(this, this)
Copy link

Choose a reason for hiding this comment

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

Because the component may be loaded multiple times, the namespace of the subsequent component is always the result of the first execution, so the code cannot override namespace = namespace.call(this, this), we can use the local variable let ns = namespace.call(this, this)

@brophdawg11
Copy link
Author

Closing as we have released our internal solution to this as a separate package: https://www.npmjs.com/package/@urbn/vuex-helpers

@brophdawg11 brophdawg11 deleted the namespace-functions branch February 17, 2020 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants