Skip to content

支付宝小程序状态数据管理实践(redux、redux-saga、connect)

Notifications You must be signed in to change notification settings

zhengxif/qn-dva

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

qn-dva

简单抽离dva中的model逻辑, 用法和dva一样

运用场景

  • 结合reducer和saga,方便开发
  • 利用connect 连接组件

使用方式

  • model 配置
export default {
    namespace: 'xx',
    reducers: {
        aa(action, state){}
    },
    effects: {
        *syncaa(action, {put, take, select,takeEvery}) {

        }
    }
}
  • 引入dva并初始化

注意调用start会返回store,此store就是redux创建好的;connect方法可以连接组件和page

import dva from 'qn-dva'
import models from './models' 

const app = dva();
models.forEach(app.model);
let { store, connect } = app.start();
export {
    store,
    connect
}
  • 连接组件或者page
import { connect } from '../../store'
const config = {
    mixins: [],
    data: {
        
    },
    props: {
    },
    didMount() { }, // 此生命周期一定要有
    didUnmount() { }, // 此生命周期一定要有
    methods: {
        aa() {
            this.dispatch({
                type: 'xx/xx',
                payload: {
                    xxx
                }
            })
        }
    },
}
const mapState = state => {
    return {
        xxx: state[命名空间名称]
    }
}
Component(connect(mapState, config));

About

支付宝小程序状态数据管理实践(redux、redux-saga、connect)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published