gertqin / vuex-class-modules

Typescript class decorators for vuex modules
MIT License
194 stars 20 forks source link

Access generated mutations (generateMutationSetters: true) from module instance #63

Closed mzymta closed 3 years ago

mzymta commented 3 years ago

Is there a way to use auto-generated mutations (with generateMutationSetters: true option) from the module instance? In Vue component for example?

const userModule = new UserModule({ store, name: "user" });

userModule.firstName = value;

// OR

userModule.set__firstName(value)

Or they have to be explicitly defined in this case?

bodograumann commented 3 years ago

Yes, I think this should exactly like you say. Similar to the automatically generated getters. Did you have any problems with it?

mzymta commented 3 years ago

Hi Bodo, so you are saying that in Vue component I can import module instance and do userModule.firstName = value; to modify the state?

The thing is that it looks like I am directly modifying the state bypassing mutation which contradicts with the Vuex pattern where the state should only be changed inside mutations. Or I am getting it wrong and userModule.firstName = value; calls generated mutation on the background?

mzymta commented 3 years ago

userModule.firstName = value; is indeed calling the generated set__firstName mutation on the background. Super cool!

Thank you!