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

Return values from mutation commits. #1437

adjenks opened this Issue Nov 2, 2018 · 0 comments


None yet
1 participant

adjenks commented Nov 2, 2018

What problem does this feature solve?

One often wants to get the id of a created object back from the data store. Much like in a database, if you add an object to an array in the store, you want to get it's id so that you can reference it again. When looking up how to do this, I found that you cannot, and I also found that someone else had the exact same inquiry on stackoverflow:
The response to the question on stack overflow was to use vuex actions, but I don't think that one should have to use an asynchronous action to achieve a synchronous task.
To carry on with the database example, one might use postgresql's "RETURNING" as an analogy. One can perform an insert statement and then say RETURNING thing_id to get the automatically generated id, or whatever other fields they would like.

What does the proposed API look like?

let myReturn = this.$store.commit('ADD_THING",{"name":"new_thing"});
// 'ADD_THING' adds a thing to an numerically indexed object and then returns the number.
console.log(myReturn); // {"id":42,"datestamp":1541145883085}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment