think-react-store
Version:
基于react hooks 和 context 实现的类似与 redux 的数据流工具
17 lines (15 loc) • 534 B
JavaScript
import pick from 'ramda/src/pick'
// import mergeDeepRight from 'ramda/src/mergeDeepRight'
/**
* 中间件参数
* @param {Object} store store
* @param {Object} prevState 更新前的state值
* @param {Object} nextState 更新后的state值
* @param {Object} action 派发的action
*/
export default function cache(store, prevState, nextState, action, actionAsync, asyncKey, cache){
const CACHE = 'react-store:cache';
if(cache && cache.length){
localStorage.setItem(CACHE, JSON.stringify(pick(cache, nextState)))
}
}