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-j-store

v1.0.2

Published

模块化vue状态管理,解决store文件过大,命名空间过长等问题。

Downloads

4

Readme

vue-j-store

vue2.X 模块化状态管理,解决store文件过大,命名空间过长等问题。其实只是一种思路。

用法尽可能与vuex保存一致,(注意)其中对map方法进行了扩展,调用方式也不一样。

npm


$ npm install vue-j-store

优点对照

vue-j-store

相信用过的人都想过store过大,actions过多而头痛吧。换个角度不好吗?一对一,删除方便,查找方便,读取变量也方便。

Usage

main.js

  import Vue from "vue";
  import VueStore from "vue-j-store";

  Vue.use(VueStore);

componentA

componentA/store.js

  import VueStore from "vue-j-store";

  export default new VueStore({
    state:{
      count:0
    },
    mutations:{
      inc(state){
         state.count++;
      },
      reduce(state){
        state.count--;
      }
    }
  });

componentA/index.vue

<template>
  <div>
    <h4>{{$store.state.count}}</h4>
    <button @click="$store.commit('inc')">加</button>
    <button @click="$store.commit('reduce')">减</button>
  </div>
</template>

<script>
  import store from "./store";
  export default {
    store
  }
</script>

componentB

componentB/store.js

  import VueStore from "vue-j-store";

  export default new VueStore({
    state:{
      count:0
    },
    mutations:{
      inc(state,len){
         state.count+=len;
      },
      reduce(state){
        state.count--;
      }
    },
    actions:{      
      ajaxRequest(context){
          console.log("请求数据中...");

          fetch("http://gank.io/api/data/Android/10/1").then(function(res){
            return res.json();
          }).then(function(json){
             context.commit("inc",json.results.length);
             console.log("操作完毕!");
          });
      }
    }
  });

componentB/index.vue

<template>
  <div>
    <h4>{{count}}</h4>
    <button @click="ajaxRequest">请求</button>
  </div>
</template>

<script>
  import store from "./store";
  export default {
    computed:{          
        count(){
            return this.$store.state.count;
        }
    },
    methods:store.mapActions(),
    store
  }
</script>

map使用惯例

   store.mapState();   //全部
   store.mapState("count");   //等同于["count"]
   store.mapState(["count"]);
   
   store.mapSetters();   //同上
   ...
   ...

   store.mapMutations(); //同上
   ...
   ...

   store.mapActions();   //同上
   ...
   ...