0.0.5 • Published 12 months ago

@tuya-miniapp/redux-connect-page v0.0.5

Weekly downloads
-
License
-
Repository
-
Last release
12 months ago

miniapp-redux-connect-page

小程序中用于替代 Page 方法,直接关联 redux 状态,类似于 redux 中 connect 方法

安装

yarn add @tuya-miniapp/redux-connect-page

使用

单 store 配置

// app.js
import { setGlobalStore } from '@tuya-miniapp/redux-connect-page';
import { store } from 'path/to/store';
setGlobalStore(store);

App({
    ...
})

多 store 配置

// page.js
import { store } from 'path/to/store';
ty.ConnectPage({
    onLoad: function() {

    },
    ...
}, [/*mapStateToData*/], () => {/*mapDispatchToProps*/}, store)

重载 Page

若所有 Page 下都使用到了 redux,可通过重载 Page 方法的形式处理每个页面,这样就不再需要每个页面都导入 ConnectPage 了。

import { setGlobalStore } from '@tuya-miniapp/redux-connect-page';
import { store } from 'path/to/store';

Page = ty.ConnectPage;
setGlobalStore(store);

Page({
    onLoad: function() {

    },
    ...
}, [/*mapStateToData*/], () => {/*mapDispatchToProps*/})