Vuex Best Practices for Complex Objects

My Vuex store contains objects of varying complexity. Some have nested objects, some have arrays of socket objects.

I could create a generic function to change the specified property line by line:

setProperty(state,{ type, id, prop, value })
{
  state[type][id][prop] = value;
}

but this will quickly get complicated for a nested object, arrays of objects. It also seems very tedious to create a mutation for each property of an object, nested or otherwise.

What are the best methods for creating mutations for modifying objects, nested objects, arrays, etc.

Another problem associated with this is to consider the bad form to transfer objects in mutations, and not look at them in a state:

setProperty(state,{ obj, prop, value })
{
  obj[prop] = value;
}
+6
source share
1 answer
+2

Source: https://habr.com/ru/post/1016736/


All Articles