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

Proposal: let the actions function first param context is configurable #895

Closed
superwf opened this issue Aug 4, 2017 · 2 comments
Closed

Comments

@superwf
Copy link

superwf commented Aug 4, 2017

What problem does this feature solve?

when I use axios in many modules

// each module has to import
import axios from 'axios'
export default {
  ...
  actions: {
    getUsers ({ commit }) {
      axios.get('/users').then(data => {
        commit('users', data)
      })
    }
  }
}

What does the proposed API look like?

If the actions first param context is configurable, it could be like this,
the axios may be db, model or socket

// in store/index
import axios from 'axios'
const store = new Vuex.Store({
  context: {
    axios
  },
  ...
  modules: {
    ...
  }
})


// in module/user
export default {
  ...,
  actions: {
    getUsers ({ axios, commit }) {
      axios.get('/users').then(data => {
        commit('users', data)
      })
    }
  }
}

I read src/store.js and find that the context is not configurable.

@ktsn
Copy link
Member

ktsn commented Aug 5, 2017

There was this kind of discussion in the past and we didn't introduce the feature that can be inject something in the action context. See #571

You can use the action enhancer approach to do that.

@ktsn ktsn closed this as completed Aug 5, 2017
@superwf
Copy link
Author

superwf commented Aug 5, 2017

I read #571, thank you

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

No branches or pull requests

2 participants