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

cachestate

v1.0.2

Published

vuex持久化插件

Downloads

2

Readme

cacheState

vuex持久化的插件,自用,不能保证线上质量

文件说明

src

  • cacheState:核心逻辑
  • installCacheState:vue全局注入api文件

example

  • 使用案例(vue-cli4.x初始化的项目)

API

removeCache(callback:Function?,target:Arrary?)

  • callback:删除缓存后执行的回调
  • target:指定删除那些缓存,不指定时,默认删除全部

使用

  • 安装该插件
npm i cacheState -D
  • 在store/index.js中
// 引入插件
import {
  cacheState
} from '../until/cacheState'
export default new Vuex.Store({
    // 使用插件 只有一个参数 watch 数组类型
    // 传递的参数为要缓存的state的key
    // 当key为一个对象时,传递该key缓存整个对象
    // 要缓存对象的某一个key是 传递user.name
  plugins: [cacheState({
    // watch: []
    watch: ['name', 'user.name', 'other.msg']
    // watch: ['name']
  })],
  state: {
    name: "This is an about page",
    other: {
      msg: "root  state"
    }
  },
  mutations:{...}
  • 删除缓存
// 在所有组件中都可以使用
this.$removeCache()

原理

  • 利用浏览器本地缓存localstrong实现数据缓存
  • 通过vuex提供的plugins的特性,在每次实例化时检查缓存,更新state
  • 通过vuex的store.subscribe()监听state变化,每次变化后进行数据缓存
  • 通过利用闭包函数,提供配置选项