npm.io
0.0.5 • Published 3 years ago

@tuya-miniapp/redux-connect-page

Licence
Version
0.0.5
Deps
0
Size
6 kB
Vulns
0
Weekly
0

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*/})