vue-mc icon indicating copy to clipboard operation
vue-mc copied to clipboard

Vuex not recognizing collection.add

Open seanthingee opened this issue 4 years ago • 1 comments

I'm using Vuex and I'm attempting to add a new model to the collection via the add() method inside of a Vuex mutation. This is the mutation:

createNew (state, model) {
  state.collection.add(model)
}

I can confirm that the model is added but Vue is not noticing and is not updating the list of components that are bound to this collection via a v-for.

I can get this to work if I modify the function to recreate the collection by initializing the new collection with the previous collection's models:

createNew (state, model) {
  let newCollection = new Collection(state.collection.models)
  newCollection.add(collection)
  state.collection = newCollection
}

I dug through the code a bit and I narrowed it down to this line: https://github.com/FiguredLimited/vue-mc/blob/master/src/Structures/Model.js#L320. If I comment out the Vue.set line out it works as expected. Based on my noob understanding of Vue, this is kind of opposite of what I would expect since Vue.set is used to update objects so that the reactivity works.

Any ideas?

seanthingee avatar Dec 13 '19 15:12 seanthingee

Same

pascaldls avatar Nov 18 '20 05:11 pascaldls