A persisted plugin for svelte store manager
基于svelte store manager开发的将state状态持久化的插件
Author:Alan Chen
Version: 0.1.1
Date: 2020/1/19
npm install --save-dev @alanchenchen/svelte-store-persisted
or yarn add @alanchenchen/svelte-store-persisted --dev
// 全局使用
import { useGlobalPlugins } from "@alanchenchen/svelte-store";
import persisted from "@alanchenchen/svelte-store-persisted";
useGlobalPlugins([
persisted({
// 只会存储所有store的name字段,过滤age字段.
paths: ["name"]
filter: (storeName) => {
// moduleA不会应用此插件.
if (storeName === "A") {
return false
} else {
return true;
}
}
})
]);
// 分模块使用
// a.js
import { createStore } from "@alanchenchen/svelte-store";
import persisted from "@alanchenchen/svelte-store-persisted";
const a = createStore({name: "A", age: 21}, "moduleA");
a.use(persisted());
// b.js
import { createStore } from "@alanchenchen/svelte-store";
import persisted from "@alanchenchen/svelte-store-persisted";
const b = createStore({name: "B", age: 22}, "moduleB");
b.use(persisted());
persisted的参数是个对象,格式如下:
git clone https://github.com/alanchenchen/svelte-store-persisted.git
yarn
安装好依赖npm run build
编译ts文件到dist目录.