Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2642 from BubbleSci/master
增加中文翻译和修复一些小问题
- Loading branch information
Showing
14 changed files
with
415 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
English | [简体中文](./README_CN.md) | ||
|
||
# @wepy/babel-plugin-import-regenerator | ||
|
||
Allow wepy to use `Async Functions`. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
[English](./README.md) | [简体中文] | ||
|
||
# @wepy/babel-plugin-import-regenerator | ||
|
||
允许wepy使用 `Async Functions`. | ||
|
||
## 安装 | ||
|
||
``` | ||
# Install regenerator-runtime dependence | ||
$ npm install regenerator-runtime --save | ||
# Install babel plugin | ||
$ npm install @wepy/babel-plugin-import-regenerator --save-dev | ||
``` | ||
|
||
## 用法 | ||
|
||
在 wepy.config.js 中放入以下内容: | ||
|
||
|
||
```js | ||
|
||
{ | ||
.... | ||
compilers: { | ||
babel: { | ||
presets: [ | ||
'@babel/preset-env' | ||
], | ||
plugins: [ | ||
'@wepy/babel-plugin-import-regenerator' | ||
] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## License | ||
|
||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
English | [简体中文](./README_CN.md) | ||
|
||
# wepy define plugin | ||
|
||
## Install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
[English](./README.md) | 简体中文 | ||
|
||
# wepy define plugin | ||
|
||
## 安装 | ||
|
||
```bash | ||
npm install @wepy/plugin-define --save-dev | ||
``` | ||
|
||
## 配置方式 | ||
|
||
**wepy.config.js** | ||
|
||
```javascript | ||
const DefinePlugin = require('@wepy/plugin-define'); | ||
|
||
module.exports = { | ||
plugins: [ | ||
DefinePlugin({ | ||
BASE_URL: JSON.stringify('http://foobar.com'), | ||
'process.env.NODE_ENV': 'development', | ||
'typeof window': JSON.stringify('undefined'), | ||
DEV: true | ||
}) | ||
] | ||
}; | ||
``` | ||
|
||
## 参考网站 | ||
|
||
[webpack.DefinePlugin](https://webpack.js.org/plugins/define-plugin/) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
English | [简体中文](./README_CN.md) | ||
|
||
# Redux in WePY 2.0 | ||
|
||
## Install | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
[English](./README.md) | 简体中文 | ||
|
||
# WePY 2.0中的Redux | ||
|
||
## 安装 | ||
|
||
``` | ||
npm install @wepy/redux redux --save | ||
``` | ||
|
||
## 用法 | ||
|
||
1. 安装Redux | ||
|
||
``` | ||
// app.wpy | ||
import wepy from '@wepy/core'; | ||
import wepyRedux from '@wepy/redux'; | ||
wepy.use(wepyRedux); | ||
``` | ||
|
||
2. 初始化 Store | ||
|
||
``` | ||
// ~/store.js | ||
import { createStore, combineReducers } from 'redux'; | ||
export default createStore(combineReducers({ | ||
counter (state = { num: 0 }, action) { | ||
switch (action.type) { | ||
case 'ADD': | ||
return { | ||
...state, | ||
num: state.num + 1 | ||
}; | ||
} | ||
return state; | ||
} | ||
})); | ||
``` | ||
|
||
3. 映射到组件 | ||
|
||
``` | ||
// ~/counter.wpy | ||
<template> | ||
<div> {{counter.num}} </div> | ||
<button @tap="increment"> Increment </button> | ||
</template> | ||
<script> | ||
import wepy from '@wepy/core'; | ||
import { mapState } from '@wepy/redux'; | ||
import store from './store' | ||
wepy.component({ | ||
store, | ||
computed: { | ||
...mapState([ 'counter' ]) | ||
}, | ||
methods: { | ||
increment () { | ||
this.$store.dispatch({ type: 'ADD' }) | ||
} | ||
} | ||
}) | ||
``` | ||
|
||
## API | ||
|
||
* mapState(states) | ||
|
||
状态:字符串/数组/K-V对象.。需要映射的 state 属性。如: | ||
|
||
``` | ||
mapState('counter') | ||
mapState(['counter', 'somethingelse']) | ||
mapState({ alias: 'counter' }) | ||
mapState({ | ||
num: function (state) { | ||
return state.counter.num; | ||
} | ||
}) | ||
``` | ||
|
||
* mapActions(actions) | ||
|
||
actions: K-V Object. 需要映射的 action 。如: | ||
|
||
``` | ||
mapActions({ add: 'ADD' }); | ||
mapActions({ | ||
add: function () { | ||
return { | ||
type: 'ADD' | ||
}; | ||
} | ||
}); | ||
``` | ||
|
||
## Document | ||
|
||
[https://redux.jg.org](https://redux.js.org) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
English | [简体中文](./README_CN.md) | ||
|
||
# @wepy/use-intercept | ||
|
||
weapp APIs intercept factory. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[English](./README.md) | 简体中文 | ||
|
||
# @wepy/use-intercept | ||
|
||
weapp APIs intercept factory. | ||
|
||
## 安装 | ||
|
||
``` | ||
npm install @wepy/use-intercept --save | ||
``` | ||
|
||
## 用法 | ||
|
||
|
||
### 基本用法 | ||
|
||
``` | ||
import wepy from '@wepy/core'; | ||
import useIntercept from '@wepy/use-intercept'; | ||
wepy.use(useIntercept); | ||
const request = wepy.intercept(wepy.wx.request, { | ||
config(params) { | ||
console.log(params); | ||
if (!params.data) { | ||
params.data = {}; | ||
} | ||
params.data.t = +new Date(); | ||
return params; | ||
// return Promise.resolve(params); // support async config interceptor | ||
}, | ||
success(res) { | ||
console.log(res); | ||
return res; | ||
}, | ||
fail(e) { | ||
console.log(e); | ||
return e; | ||
} | ||
}) | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
English | [简体中文](./README_CN.md) | ||
|
||
# @wepy/use-promisify | ||
|
||
Promisfy all weapp APIs. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
[English](./README.md) | 简体中文 | ||
|
||
# @wepy/use-promisify | ||
|
||
Promisfy all weapp APIs. | ||
|
||
## 安装 | ||
|
||
``` | ||
npm install @wepy/use-promisify --save | ||
``` | ||
|
||
## 用法 | ||
|
||
|
||
### 基本用法 | ||
|
||
``` | ||
import wepy from '@wepy/core'; | ||
import promisify from '@wepy/use-promisify'; | ||
wepy.use(promisify); | ||
wepy.wx.getStorage('mykey').then(res => console.log(res)); | ||
``` | ||
|
||
### 忽略 APIs | ||
|
||
``` | ||
wepy.use(promisify, ['getStorage', 'getSystemInfo']); | ||
// passing object | ||
// wepy.use(promisify, { someNewAPI: false, getStorage: true }); | ||
wepy.wx.getStorage({ | ||
key: 'mykey', | ||
succuess (res) { console.log(res) } | ||
}) | ||
``` | ||
|
||
### 函数调用 | ||
|
||
Support to use `wepy.promisify` to promisify a callback function. | ||
|
||
``` | ||
/** | ||
* Promisify a callback function | ||
* @param {Function} fn callback function | ||
* @param {Object} caller caller | ||
* @param {String} type weapp-style|error-first, default to weapp-style | ||
* @return {Function} promisified function | ||
*/ | ||
wepy.promisify(fn, caller, type); | ||
``` | ||
|
||
#### weapp-style | ||
|
||
支持 weapp-style的所有功能: | ||
|
||
``` | ||
func({ | ||
success () {}, | ||
fail () {} | ||
}) | ||
wepy.promisify(func)({key: 'mykey'}).then(console.log).catch(console.error); | ||
``` | ||
|
||
#### 错误优先 | ||
|
||
支持所有 `error-first` 功能,例如: | ||
|
||
``` | ||
func(arg1, args2, function (err, data) {}); | ||
wepy.promisify(func, null, 'error-first')(arg1, arg2).then(console.log).catch(console.error); | ||
``` | ||
|
||
|
||
### 简化参数 | ||
|
||
`weapp-style` 函数始终需要一个Object参数,并且此插件将简化参数。例如: | ||
|
||
``` | ||
wepy.use(promisify); | ||
// wepy.wx.getStorage({ key: 'mykey' }); | ||
wepy.wx.getStorage('mykey'); | ||
// wepy.wx.request({ url: myurl }); | ||
wepy.wx.request(myurl); | ||
// wepy.wx.openLocation({ latitude: 0, longitude: 0 }); | ||
wepy.wx.openLocation(0, 0); | ||
``` | ||
|
||
在这里我们可以看到所有的简化列表 [Simplify List](https://github.com/Tencent/wepy/blob/2.0.x/packages/use-promisify/index.js#L86-L152) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
English | [简体中文](./README_CN.md) | ||
|
||
# Vuex in WePY 2.0 | ||
|
||
## Install | ||
|
Oops, something went wrong.