vuex-class-component icon indicating copy to clipboard operation
vuex-class-component copied to clipboard

[Feature] Add field name to internal mutations

Open SaphuA opened this issue 5 years ago • 2 comments

When one uses the strict=false method all the mutations look like this in the Vue dev tools: MyStoreName/__mystorename_internal_mutator__

I think having the field name in there would help a lot with debugging with Vue Dev Tools.

SaphuA avatar Nov 11 '19 09:11 SaphuA

So the goal of the __internal_mutator__ and __internal_getter__ is to act as a parent mutator or getter for the state when strict is set to false.

Adding the field name would defeat that purpose.

Eg say you have a store like this

class UserStore extends createModule({ strict: false }){
  firstname = "John";
  lastname = "Doe"
}

One way to generate the actual vuex store would something like this.

const userStore = {
  state: {
    firstname: "John",
    lastname: "Doe"
  },
  
  mutations: {
    __generated_mutator_setFirstName__: ( state, payload ) =>state.firstname = payload,
    __generated_mutator_setLastName__: ( state, payload ) =>state.lastname = payload,
  },

  getters: {
    __generated_getter_getFirstName__: ( state ) => state.firstname,
    __generated_getter_getLastName__: ( state ) => state.lastname,
  },
  
}

My issue with this is that for each state, there is an additional mutation and getter defined. I think this is unecessary. And there's really no difference in functionality between the two mutations and getters.

This is where the internal_mutator comes into play, so you have something like this.

const userStore = {
  state: {
    firstname: "John",
    lastname: "Doe"
  },

  mutations: {
    __userStore_internal_mutator__: (state, { field, payload }) => state[ field ] = payload,
  },

  getters: {
    __userStore_internal_getter__: (state, field) => state[ field ]
  }
}

michaelolof avatar Nov 11 '19 10:11 michaelolof

Yes exactly. So the only benefit of adding the field name would be a cleaner devtools experience. But from what I understand at really no cost - unless it's difficult to implement of course.

SaphuA avatar Nov 11 '19 20:11 SaphuA