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

pinia-plugin-persist-orm

v0.0.7

Published

Pinia plugin to persist stores

Downloads

6

Readme

pinia-plugin-persist-orm

Pinia plugin to persist stores

快速开始

  1. 使用你喜欢的包管理器:
  • npm: npm i pinia-plugin-persist-orm
  • pnpm: pnpm i pinia-plugin-persist-orm
  • yarn: yarn add pinia-plugin-persist-orm
  1. 添加插件到pinia:
import { createPinia } from 'pinia';
import piniaPluginPersistORM from 'pinia-plugin-persist-orm';

const pinia = createPinia();
pinia.use(piniaPluginPersistORM);

配置

  1. 默认使用的localStorage, 修改如下:
// 全局修改
import { createPinia } from 'pinia';
import {piniaPluginPersistORM} from 'pinia-plugin-persist-orm';

const pinia = createPinia();
pinia.use(piniaPluginPersistORM({
  // 在这里进行全局配置, 具体参考 types.d.ts 文件
}));


// 局部修改
import { defineStore } from "pinia";

export const useWktStore = defineStore('wkt', {
  state: () => ({
    // 类似于组件的 data, 用来存储全局状态
  }),
  getters:{
    // 类似于组件的 computed, 封装计算属性, 有缓存功能
  },
  actions: {
    // todo
    // 类似于组件的 methods, 封装业务逻辑, 修改 state 等
  },
  persist: { // 开启持久化功能
    // 指定持久化的容器, useStoreDB 是手动封装的操作 IndexedDB 的类(需要外部实现)
    // 这个操作类需要实现基本的两个方法: getItem 和 setItem
    storage: useStoreDB as unknown as Storage
  }
});

说明

  1. 该插件是在pinia-plugin-persistedstate的基础之上得到的;
  2. 由于pinia-plugin-persistedstate只支持localStorage,sessionStorage这两种持久化方式, 持久化的空间大小就有了限制;
  3. 为了解决持久化空间大小的限制, 扩展了对IndexedDB支持;
  4. 众所周知IndexedDB的所有操作都是异步的, 具体请查看;
  5. 对操作getItme方法的方法进行了异步改造, 以对IndexedDB的支持;
  6. 可能需要是用watchwatchEffect等Apis监听pinia仓库数据的变更, 这在刷新页面的时候很有效;