Use Vue.set in updateField to support reactive array watching
geoidesic opened this issue · 1 comments
geoidesic commented
Why does it not use Vue.set
here?
Line 33 in 96fa6b3
It seems to me that if you were to replace
export function updateField(state, { path, value }) {
path.split(/[.[\]]+/).reduce((prev, key, index, array) => {
if (array.length === index + 1) {
// eslint-disable-next-line no-param-reassign
prev[key] = value;
}
return prev[key];
}, state);
}
with
export function updateField(state, { path, value }) {
Vue.set(state, path, value);
}
It would be simpler and more reactive (as setting arrays directly via indexes does not default getter watchers).
maoberlehner commented
Just double checked Vue.set(state, 'some.nested.path', value);
does not work. If it would, it would be a big improvement indeed!
As for the "more" reactive thing: either it is reactive or not. It would enable setting new properties on the fly instead of declaring them beforehand. I can see how for some use cases this would be a nice improvement but I'm not sure if it doesn't promote anti patterns.