Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dva-model-persist

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dva-model-persist

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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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示例(或dva-cli@1.0.0.bate4版)

// 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,所以并不影响使用。

Keywords

FAQs

Package last updated on 29 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc