Typescript Decorators to create Vuex modules


#1

Hi!
I present you with https://www.npmjs.com/package/vuex-module-decorators

vuex-module-decorators allows creating decorated, class-style Vuex modules.

import {Module, VuexModule, Mutation, Action} from 'vuex-module-decorators' 
 
@Module
export default class Counter2 extends VuexModule {
  count = 0
 
  @Mutation increment(delta: number) {this.count+=delta}
  @Mutation decrement(delta: number) {this.count-=delta}
 
  // action 'incr' commits mutation 'increment' when done with return value as payload
  @Action({commit: 'increment'}) incr() {return 5}
  // action 'decr' commits mutation 'decrement' when done with return value as payload
  @Action({commit: 'decrement'}) decr() {return 5}
}

more examples on github