All Projects → b5156 → mobx-wxapp

b5156 / mobx-wxapp

Licence: other
在小程序中使用mobx

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to mobx-wxapp

weapp.request
为微信小程序提供的网络请求组件,是 wx.request 的扩展,基于 Promise API,添加缓存控制
Stars: ✭ 29 (-46.3%)
Mutual labels:  weapp, wxapp, miniprogram
wxapp-computed
在微信小程序中使计算值(computed)
Stars: ✭ 20 (-62.96%)
Mutual labels:  weapp, wxapp, miniprogram
Wux Weapp
🐶 一套组件化、可复用、易扩展的微信小程序 UI 组件库
Stars: ✭ 4,706 (+8614.81%)
Mutual labels:  weapp, wxapp, miniprogram
ecommerce-react-native
The ideal starter kit / app script with all the needed UI elements alongwith MobX and NativeBase to build your iOS and Android e-commerce app like Mona / JackThreads / Canopy / Flipp
Stars: ✭ 86 (+59.26%)
Mutual labels:  mobx, mobx-react
quickstart-miniprogram
🎉微信小程序webpack模板
Stars: ✭ 32 (-40.74%)
Mutual labels:  wxapp, miniprogram
react-mobx-local-state-example
React MobX (for Local State) Example
Stars: ✭ 27 (-50%)
Mutual labels:  mobx, mobx-react
tinylog-ui
实时日志分析系统后台数据管理系统
Stars: ✭ 45 (-16.67%)
Mutual labels:  mobx, mobx-react
orkan
A content management toolkit for building and managing dynamic React applications with ease.
Stars: ✭ 25 (-53.7%)
Mutual labels:  mobx, mobx-react
todo-list
A simple todo list application with React and mobx and antd
Stars: ✭ 25 (-53.7%)
Mutual labels:  mobx, mobx-react
veact
Mutable state enhancer library for React based on @vuejs
Stars: ✭ 62 (+14.81%)
Mutual labels:  mobx, mobx-react
wxml-vscode
👾Vscode plugin -- wechat applets formatting and highlighting components (highly customized)
Stars: ✭ 31 (-42.59%)
Mutual labels:  weapp, miniprogram
jgb
小程序渐进式编译框架
Stars: ✭ 21 (-61.11%)
Mutual labels:  weapp, miniprogram
Wechat Weapp Mobx
微信小程序(wechat weapp) mobx 绑定, 跨页面通信的利器, 现已发布npm包
Stars: ✭ 208 (+285.19%)
Mutual labels:  mobx, weapp
weapp-OpenRadio
A base music weapp named OpenRadio for wechat. Can use on weapp getting started.
Stars: ✭ 14 (-74.07%)
Mutual labels:  weapp, wxapp
Weapp Bmscore
a weapp to count badminton game score
Stars: ✭ 17 (-68.52%)
Mutual labels:  mobx, weapp
mpapi
🐤 小程序API兼容插件,一次编写,多端运行。支持:微信小程序、支付宝小程序、百度智能小程序、字节跳动小程序
Stars: ✭ 40 (-25.93%)
Mutual labels:  weapp, miniprogram
mobx-react-docz
DEPRECATED Documentation site for MobX in React
Stars: ✭ 43 (-20.37%)
Mutual labels:  mobx, mobx-react
mobx-react-mvvm-example
React MVVM architecture powered by MobX.
Stars: ✭ 58 (+7.41%)
Mutual labels:  mobx, mobx-react
mobx-react-intl
A connector between mobx-react and react-intl
Stars: ✭ 32 (-40.74%)
Mutual labels:  mobx, mobx-react
react-mobx-router4-axios
react + less + webapck config + mobx(store)+ axios + router4
Stars: ✭ 24 (-55.56%)
Mutual labels:  mobx, mobx-react

mobx-wxapp

在小程序中使用mobxconnect函数可将被观察的数据高效的绑定到小程序视图。 旧的inject方式见v1

安装

npm install mobx-wxapp 安装项目到本地 或 直接拷贝文件(example/mobx-wxapp.js)到您的项目。

(案例使用了 mobx.js v4.6.0 ,因 mobx5 使用了小程序暂不支持的 ES6 proxy)

用法

pages/index.js:

import { connect, extract } from '../mobx-wxapp'
import { observable } from '../mobx'

const appStore = observable({
  title: 'mobx-wxapp'
})

const store = observable({

  // observable
  seconds: 0,

  // computed
  get color() {
    return this.seconds % 2 ? 'red' : 'green'
  },

  // actions
  tick() {
    this.seconds += 1
  }
})

// page
Page({
  onLoad() {
    connect(this, () => ({
        title: appStore.title,
        color: store.color,
        seconds: store.seconds
        // 或者使用 extract 一次性提取全部属性
        // ...extract(store)
      })
    )
  },
  add() {
    store.tick()
  }
})

pages/index.wxml:

<view>{{ title }} :</view>
<view style="color:{{ color }}"> seconds:{{ seconds }} </view>
<button bindtap="add">add</button>

当然,您也可在 Component 中使用:

Component({
  //..
  ready(){
    this.disposer = connect(this,mapDataToStore,options)
  },

  //请务必在组件生命周期结束前执行销毁器!
  detached(){
    this.disposer();
  }
  //...
})

API

connect(context,mapDataToStore,options?)

  • context:Object // 请传入this
  • mapDataToStore:Function //需要绑定到视图的映射函数
  • options:Object // 可选参数
options = {
  delay:Number,// setData的最小执行间隔,默认30ms
  setDataCallback:Function // setData的执行回调
}

返回值:connect返回一个销毁器函数(在 Page 中使用时将自动在 onUnload 生命周期执行,但在 Component 构造器中使用时请确保在生命周期结束时手动调用此函数)。

extract(store)

映射整个store的快捷方式

  • store:Object // 一个被观察的store对象

返回值:一个可被映射到data的对象

应用

License

ISC licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].