think-react-store
Version:
基于react hooks 和 context 实现的类似与 redux 的数据流工具
45 lines • 955 B
JavaScript
/**
* 日志中间件
* @param {*} store
* @param {*} prevState
* @param {*} nextState
* @param {*} action
* @param {*} actionAsync
* @param {*} asyncKey
*/
export default function loading(store, prevState, nextState, action, actionAsync, asyncKey){
if(action.type === 'hook-loading-clear'){
return {
...prevState,
loading: {
...prevState.loading,
[action.key]: {
...prevState.loading[action.key],
[action.payload]: true
}
}
}
}else if(actionAsync){
return {
...nextState,
loading: {
...nextState.loading,
[asyncKey]: {
...nextState.loading[asyncKey],
[actionAsync]: false
}
}
}
}else {
return {
...nextState,
loading: {
...nextState.loading,
[action.key]: {
...nextState.loading[action.key],
[action.type]: false
}
}
}
}
}