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

weex-vuex-storage

v1.1.24

Published

依据Vuex的module来存储数据到storage

Downloads

16

Readme

weex-vuex-storage

依据Vuex的module来存储数据到storage

install

npm install weex-vuex-storage -S

use

加载vuex插件

store.js

import {createStatePlugin} from 'weex-vuex-storage';
const plugins = [];
plugins.push(createStatePlugin({
  key: 'rootKey', // 根节点的key
  supportRegister: true, // 支持registerModule和unregisterModule时读取、删除本地数据
  intercept: function(init) {
    router.beforeEach((from, to, next) => {
      init.then(next);
    });
  }
}));
export default new Vuex.Store({
  ...
  plugins,
})

给action添加修饰器,调用action时存储当前module的state到storage,同时给需要存储的state属性添加到黑白名单,不能在同一个module中同时使用shouldWriteforbidWrite

module.js

import {setState, shouldWrite, forbidWrite} from 'weex-vuex-storage';
const module = {
  ...
  state: {
    @shouldWrite
    someState: {}
  },
  actions: {
    @setState,
    someAction({commit}) {

    }
  }
}

也可以手动获取storage中的数据

view.vue

import {getState} from 'weex-vuex-storage';
export default {
  methods: {
    // module A storage data
    getStateData() {
      getState({
        namespace: 'A/',
        store: this.$store
      }).then(state => {
        console.log(state);
      })
    }
  }
}

获取storage快照数据,导入快照数据至storage并同步更新module的state

view.vue

import {getModuleMap, loadStore} from 'weex-vuex-storage';
export default {
  methods: {
    getStorageSnapshot() {
      // 获取快照数据
      getModuleMap({
        namespace: 'A/',
        store: this.$store
      }).then((snapshot) => {})
    },
    loadSnapshot() {
      // 导入快照数据,并更新对应state
      // 快照数据可由getModuleMap导出,key由createStatePlugin时填写
      loadStore(this.$store, ['A'], {
        `${key}/A/`: '{"a": 1}',
        `${key}/A/B`: '{"b": "foo"}'
      }, {
        onlyState: false, // 是否需要覆盖到storage
        removeList: [], // 需要移除的storage key,只在onlyState为true时生效
        reserveList: [], // 需要保留的storage key,只在onlyState为true时生效
        isReplace: true, // 是否全量替换module的state,需要module中的state为函数而非对象
      }).then(() => {})
    }
  }
}