Git Product home page Git Product logo

Comments (2)

michaelolof avatar michaelolof commented on May 29, 2024

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 ]
  }
}

from vuex-class-component.

SaphuA avatar SaphuA commented on May 29, 2024

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.

from vuex-class-component.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.