Skip to content
/ vuexy Public

A static typed wrapper for vuex

Notifications You must be signed in to change notification settings

paraself/vuexy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vuexy

An static typed wrapper for vuex. It's still a proof of concept, bugs are everywhere, do not use in production

Usage

In main.ts

import Vuex from 'vuex'
import { Vuexy } from 'vuexy'

const store = new Vuex.Store({
  // ... initialize your vuex store
})

Vuexy.init(store)

Define you vuexy module.

// StoreCart.ts
import { VuexyModule, Mutation, Action, Getter } from '../index'

class StoreCart extends VuexyModule {
  
  // memeber variables become states
  public count: number = 0
  
  @Mutation
  add(payload?: any):void {
    console.log(payload)
    this.count  
  }

  @Action
  async deferAdd():Promise<any> {
    setTimeout(() => {
      this.add()
    }, 1000);
  }

  @Getter
  getCount() { 
    return this.count
  }
}

// this is IMPORTANT! export a singleton via parent's factory function
export default StoreCart.Instance<StoreCart>(StoreCart)

Use your module

// MyComponent.vue
<template>
// use your module states directly in template
{{StoreCart.count}}
</template>
<script lang="ts">
import { Vue, Component } from 'vue-property-decorator'
import StoreCart from './StoreCart.ts'
@Component
export default class MyComponent extends Vue {
  private StoreCart: any = StoreCart

  // use mutation or actions in functions
  myFunc () {
    this.StoreCart.deferAdd()
      .then(this.StoreCart.add)
  }

  // can also assign member variable to StoreCart's state
  count = StoreCart.count
  deferAdd = StoreCart.deferAdd
  add = StoreCart.add
}
</script>



About

A static typed wrapper for vuex

Resources

Stars

Watchers

Forks

Packages

No packages published