Writing Vuex modules in neat Typescript classes

Arnav Gupta
Coding Blocks
Published in
1 min readJul 14, 2018

Typescript/ES7 Decorators to make Vuex modules a breeze

Installation

npm install -D vuex-module-decorators

Babel 6/7

  1. You need to install babel-plugin-transform-decorators

Typescript

  1. set experimentalDecorators to true
  2. For reduced code with decorators, set emitHelpers: true and importHelpers: true and install tslib

Usage

The conventional old & boring way

Remember how vuex modules used to be made ?

Hello Decorators !

Well not anymore. Now you get better syntax. Inspired by vue-class-component

async MutationAction === magic

Want to see something even better ?

Automatic getter detection

this is turned into the equivalent

Putting into the store

Use the modules just like you would earlier

Written with StackEdit.

Originally published at gist.github.com.

--

--

Arnav Gupta
Coding Blocks

Swimmer, Coder, Poet, Engineer, Entrepreneur. Co founder of Coding Blocks. Mobile Platform at Zomato