🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

rematch-storage

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rematch-storage

### 安装

latest
npmnpm
Version
0.1.2
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

rematch-storage

安装

npm install rematch-storage --save

yarn add rematch-storage

介绍

把model的值同步到sessionStorage或者localStorage中,使得页面刷新的时候能从storage中取出对应的值进行数据的初始化

使用

example

const countModel = {
    state: 0,
    reducers: {
        increment: state => state + 1,
        decrement: state => state - 1,
    },
    effects: {
        async asyncIncrement() {
          await new Promise((resolve) => {
            setTimeout(resolve, 1000);
          });
          console.log('this click', this);
          this.increment();
        },
    },
    useSession: true,
    useLocal: true,
};


init

import storagePlugin from 'rematch-storage';

const store = init({
    ...
    
    models,
    plugins: [storagePlugin],
    
    ...
    
});
  • useSession: 将值同步到sessionStorage中
  • useLocal: 将值同步到localStorage中

sessionStorage的优先级高于localStorage,最好使用两者中的一个,如果两个值同时设置了,会优先使用sessionStorage。

FAQs

Package last updated on 17 Dec 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