christianmalek / vuex-rest-api

A utility to simplify the use of REST APIs with Vuex
http://vuex-rest-api.org
MIT License
382 stars 48 forks source link

provide action payload in onSuccess #84

Closed Walraz closed 6 years ago

Walraz commented 6 years ago

I don't find a way to access the called action payload in a onSuccess cb.

Lets say I want to make a delete request with params in action

this.$store.dispatch('user/delete', { params: { id: 1 })

can we have a actionPayload argument in the onSuccess() for convenient accessing the params/data from the action payload.

onSuccess(state, payload, axios, actionPayload) {
state.users = state.users.filter(user => user.id !== actionPayload.params.id)
}

thx!

christianmalek commented 6 years ago

Hey @Walraz !

Wow. This is the third request in this week for this feature! I'll try to add it this weekend.

Walraz commented 6 years ago

Cool @christianmalek !

Maybe the onSuccess arguments should be in an object for cleaner code and access only the args you need.

onSuccess({ state, actionPayload }) or even onSuccess({ state, params, data })

this would be breaking changes to the current api, but say it will be a 5th enhancement argument to onSuccess in the future, it will be a hassle to access it.

Thanks for an awesome library!

christianmalek commented 6 years ago

That's true. I will consider this in v3. Thanks for your input!

christianmalek commented 6 years ago

@Walraz Please update vuex-rest-api to v2.10.0. I've added the {params, data} as additional parameter in the onSuccess and onError functions.