Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mobx优化 #1710

Merged
merged 2 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions docs/mobx.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ title: 使用 Mobx

> 下文中示例代码均在 [taro-mobx-sample](https://github.com/nanjingboy/taro-mobx-sample)

首先请安装 `mobx` 、 `@tarojs/mobx` 、 `@tarojs/mobx-h5` 和 `@tarojs/mobx-rn`
首先请安装 `mobx@4.8.0` 、 `@tarojs/mobx` 、 `@tarojs/mobx-h5` 和 `@tarojs/mobx-rn`

```bash
$ yarn add mobx @tarojs/mobx @tarojs/mobx-h5 @tarojs/mobx-rn
$ yarn add mobx@4.8.0 @tarojs/mobx @tarojs/mobx-h5 @tarojs/mobx-rn
# 或者使用 npm
$ npm install --save mobx @tarojs/mobx @tarojs/mobx-h5 @tarojs/mobx-rn
$ npm install --save mobx@4.8.0 @tarojs/mobx @tarojs/mobx-h5 @tarojs/mobx-rn
```

随后可以在项目 `src` 目录下新增一个 `store/counter.js` 文件
Expand Down Expand Up @@ -212,6 +212,13 @@ export default Index
)
```

* 如果使用 `@observable` 装饰器来定义可观察对象时,请确保该属性已经初始化(这是很多情况下属性值改变,页面没刷新的根源所在),比如:

```js
@observable counter // 错误
@observable counter = 0 // 正确
```

* 自`1.2.0-beta.5`后,`propTypes`已从`taro-mobx`、`taro-mobx-h5`、`taro-mobx-rn`中剥离,如需使用,请单独进行安装:

```bash
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-cli/templates/mobx/pkg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@tarojs/mobx": "^<%= version %>",
"@tarojs/mobx-h5": "^<%= version %>",
"@tarojs/mobx-rn": "^<%= version %>",
"mobx": "^5.5.2",
"mobx": "4.8.0",
"nervjs": "^1.3.9",
"nerv-devtools": "^1.3.9"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-mobx-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"clear": "rimraf dist"
},
"peerDependencies": {
"mobx": "^5.5.2"
"mobx": "4.8.0"
},
"devDependencies": {
"rimraf": "^2.6.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-mobx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"clear": "rimraf dist"
},
"peerDependencies": {
"mobx": "^5.5.2"
"mobx": "4.8.0"
},
"devDependencies": {
"rimraf": "^2.6.2"
Expand Down