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

How to change a mutation #30

Closed marceloavf closed 7 years ago

marceloavf commented 7 years ago

I'm trying to change a mutation that createStore has done, I found in the docs that this could execute someting when it success:

  // This function will be called after successfully resolving the action.
  // If you define this property, only the corresponding
  // pending annmd error properties will be set, but not state[property].
  // The method signature is (state, error).
  mutationSuccessFn: Function,

But my problem is that I need to concat this state with the old one, is that possible?

Thanks!

christianmalek commented 7 years ago

Oops! There is an error in the documentation. I confound the comments for mutationSuccessFn and mutationFailureFn.

The method signature looks like function (state, payload), so state is the store state andpayload is the response from your API.

I've updated the README.

marceloavf commented 7 years ago

Is there a way to do it ? Or I need to do this inside another action/mutation?

mutationSuccessFn: (state, payload) => {
      this.state = this.state.concat(payload.data);
    },

I found it, was an error with the spelling and concat a first null state.

Thank you.

christianmalek commented 7 years ago

Glad you found the error. :)