ktsn / vuex-connect

A binding utility for a Vue component and a Vuex store.
MIT License
251 stars 20 forks source link

The modules with state and namespace #53

Open ghost opened 6 years ago

ghost commented 6 years ago

How do I use StateToProps with state in namespace? Thanks

gear54rus commented 6 years ago

It appears that there is no way (judjing by code): https://github.com/ktsn/vuex-connect/blob/master/src/connect.js#L81

mapX functions are executed with only one argument (without namespace).

@ktsn is there any particular reason you chose not to forward namespace through your connect function? If there isn't, would you be open to accepting a pull request with this functionality?

ktsn commented 6 years ago

feel free to make a PR.

jack-michaud commented 5 years ago

@ktsn Made a PR, is this solution adequate?

export default connect({
  stateToProps: (mapState) => ({
    ...mapState('someNestedStore', {
      nestedMessage: 'message',
    }),
    ...mapState({
      message: 'message',
    })
  }),
  gettersToProps: (mapGetters) => ({
    ...mapGetters('someNestedStore', {
      messageNestedGetter: 'inputMessageGetter'
    }),
    ...mapGetters({
      messageGetter: 'inputMessageGetter'
    }),
  })
})('hello', HelloComponent)

(Edit: fixed example, demonstrates that you can use both mapGetters and mapState as well as with/without namespace)

VladimirCores commented 4 years ago

Also interested in proper solution

VladimirCores commented 4 years ago

I would like to know how to apply connect to regular component with