f / vue-wait

Complex Loader and Progress Management for Vue/Vuex and Nuxt Applications
MIT License
2k stars 101 forks source link

FR: Usage with namespaced Vuex modules #53

Closed razorfever closed 6 years ago

razorfever commented 6 years ago

Splitting a Vuex store in one of my projects into namespaced modules made me think of the following.

Current way to use vue-wait with namespaced Vuex modules seems to be: (Not documented btw.)

import { mapWaitingActions } from 'vue-wait'

// ...
  methods: {
    ...mapWaitingActions('users', {
      'user/getUser': 'loading the user',
    }),
  },
  mounted() {
    // get the user data
    this.user = this['user/getUser'](this.userId);
  },
// ...

I think something like this would be more preferable:

import { mapWaitingActions } from 'vue-wait'

// ...
  methods: {
    ...mapWaitingActions('users', {
      getUser: ['user/getUser', 'loading the user'],
    }),
  },
  mounted() {
    // get the user data
    this.user = this.getUser(this.userId);
  },
// ...

Thanks.

f commented 6 years ago

How your store looks like?

f commented 6 years ago

vue-wait already supports module namespaces. The first parameter is the namespace and it's optional.

razorfever commented 6 years ago

Oh sorry. It seems I made a copy / paste error while making the example and did not even spot the first parameter. I have tried to use it without it in my code like one would use the normal mapActions.

So what if I want to use actions from multiple modules? Would this work:

import { mapWaitingActions } from 'vue-wait'

// ...
  methods: {
    ...mapWaitingActions('users', {
      getUser: 'loading the user',
      updateUser: 'updating the user',
    }),
    ...mapWaitingActions('posts', {
      getPosts: 'loading the posts',
      deletePost: 'deleting a post',
    }),
  },
  mounted() {
    // get the user data
    this.user = this.getUser(this.userId);
    this.posts = this.getPosts(); 
  },
// ...
f commented 6 years ago

Sure this will work.

razorfever commented 6 years ago

Ok. Thanks. Sorry for the inconvenience. Keep up the good work