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 🙏

© 2025 – Pkg Stats / Ryan Hefner

dva-model-persist

v1.0.0

Published

#### 软件架构 适用于 dva 项目

Readme

dva-model-persist

软件架构

适用于 dva 项目

Why

之前基于redux-persist@5.*开发的dva-resist-persist,在异步加载model时并不会存贮modelstate,所以使用reduxenhancer特性开发这个支持异步model加载的工具

安装教程

yarn add dva-model-persist

或者

npm i -S dva-model-persist

使用说明

dva示例

//src/index.js
import dva from 'dva';
import { persistEnhancer } from 'dva-model-persist';

const app = dva();
app.use({
  extraEnhancers: [
    persistEnhancer()
  ],
});

umi示例(或[email protected]版)

// src/dva.js
import { persistEnhancer } from 'dva-model-persist';

export function config () {
  return {
    extraEnhancers: [
      persistEnhancer()
    ],
  };
}

API

persistEnhancer(opts)
type opts = Object
opts

type key = String: storage 的 key,默认:model

type storage = Object: storage 对象,默认:sessionStorage,更多的支持可以引入store

//  使用 localStorage
import storage from 'dva-model-persist/storage';
//  使用 sessionStorage
import storage from 'dva-model-persist/storage/sission';

type blacklist = Array: 黑名单,当白名单为空时生效,默认:['@@dva','routing']

type whitelist = Array: 白名单,默认:[]

type keyPrefix = String: key 前缀,默认:persist

Other

目前会出现Unexpected key [你的异步model名] found in previous state received by the reducer. Expected to find one of the known reducer keys instead: "routing", "@@dva". Unexpected keys will be ignored.的错误,暂时没有找到解决方法,但不影响功能。

出现原因:dva-model-persist恢复数据到model时,异步的model由于没有加载而报出的错误,该错误是由redux抛出

当异步的model加载后,会优先恢复数据到model,所以并不影响使用。