npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-store-decorator

v0.5.5

Published

vue vuex vuex-modules decorator

Downloads

19

Readme

vue-store-decorator

store/modules/demo.{ts|js}

import StoreDecorator, {
  Action,
  Mutation,
  Getter,
  AutoLoading,
  AutoErrors,
} from 'vue-store-decorator';

@StoreDecorator
@AutoLoading
class Store {
  state() {
    return {
      name: 'nobody',
      level: {
          age: 'level age'
      },
      age: 0,
    }
  }

  @Action()
  unautoDispatch({ commit }) {
    console.log('unautoDispatch');
    
    commit('xxx', payload);
  }

  @Getter
  info(state) {
    return `Name: ${state.name} - Age+1: ${state.age + 1}`;
  }

  @Mutation('name')
  changeName(state, { name }) {
    return name;
  }

  @Mutation('level.age')
  changeAge(state, payload) {
    return payload.xxx;
  }

  @Action('changeName', { autoLoading: false })
  async fetch(context, params) {
    const res: any = await mockReq(params);
    return res.data;
  }

  @Action('changeAge')
  async updateAge(context, params) {
    const res: any = await mockReq(params);
    return res.data;
  }

  @Action('changeName')
  async update(context, params) {
    return await mockReq(params);
  }

  @Action(['changeAge', 'changeName'])
  async updateAll(context, params) {
    return await mockReq(params);
  }
}

export default new Store();

views/demo.vue

  • template
<div class="hello">
  <button @click="updateName">Update Name, (loading: {{ loadings.update }})</button>
  <button @click="handleAge">Update Age, (loading: {{ loadings.updateAge }})</button>
</div>
  • script lang="ts"
@Component
export default class App extends Vue {
  @Getter('auth/loadings') loadings: any
  @Action('auth/update') update: any
  @Action('auth/updateAge') updateAge: any

  updateName() {
    this.update({
      name: 'demo name'
    })
  }

  handleAge() {
    this.updateAge({
      age: 32,
    })
  }
}

@StoreDecorator return {}

{
  namespaced: true,
  state: ...,
  mutations: ...,
  actions: ...,
  getters: ...,
}

state 使用函数 return

@Action(param) {string|array}

包裹的 Method name 对应 *.vue Vuex-class: @Action('moduleName/methodName') param 为该 store.ts 中 @Mutation() 包裹的 Method name 注意:此处需要 return 一个 Promise

@Mutation(param) {string}

包裹的 Method name 对应 *.vue Vuex-class: @Mutation('moduleName/methodName') param 为对应的 state 中的 key,此处可以是 Key or Object Path,例如: @Mutation('key'), @Mutation('key1.key2') 注意:此处需要 return 一个结果

@Getter

包裹的 Method name 对应 *.vue Vuex-class: @Getter('moduleName/methodName') 注意:此处需要 return 一个结果

@AutoLoading 自动为 @Action 创建 loadings 对象

对应 .vue @Getter('moduleName/loadings') loadings: any 注意:store.ts 中的 @Action 包裹的 Method name 为 loadings 的 key

1. 默认方式 vuex

2. vuex-class

vuex-class 参照 views/demo.vue 中的写法

Required packages