Skip to content

Commit

Permalink
Merge pull request #2642 from BubbleSci/master
Browse files Browse the repository at this point in the history
增加中文翻译和修复一些小问题
  • Loading branch information
Gcaufy committed Jul 8, 2020
2 parents c283b2f + c6b376c commit feda5b8
Show file tree
Hide file tree
Showing 14 changed files with 415 additions and 6 deletions.
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -14,6 +14,7 @@ WePY (发音: /'wepi/)是一款让小程序支持组件化开发的框架,通

同时 WePY 也是一款成长中的框架,大量吸收借鉴了一些优化前端工具以及框架的设计理念和思想。如果 WePY 有不足地方,或者你有更好的想法,欢迎提交 ISSUE 或者 PR。


### 特性:

- 类 Vue 开发风格
Expand All @@ -30,18 +31,18 @@ WePY (发音: /'wepi/)是一款让小程序支持组件化开发的框架,通

```html
<style lang="less">
@color: #4D926F;
.num {
color: @color;
}
@color: #4D926F;
.num {
color: @color;
}
</style>
<template>
<div class="container">
<div class="num" @tap="num++">
{{num}}
</div>
<div>{{text}}</div>
<input v-model="text"></input>
<input v-model="text"/>
</div>
</template>
<config>
Expand Down
2 changes: 2 additions & 0 deletions packages/babel-plugin-import-regenerator/README.md
@@ -1,3 +1,5 @@
English | [简体中文](./README_CN.md)

# @wepy/babel-plugin-import-regenerator

Allow wepy to use `Async Functions`.
Expand Down
41 changes: 41 additions & 0 deletions packages/babel-plugin-import-regenerator/README_CN.md
@@ -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
2 changes: 2 additions & 0 deletions packages/plugin-define/README.md
@@ -1,3 +1,5 @@
English | [简体中文](./README_CN.md)

# wepy define plugin

## Install
Expand Down
35 changes: 35 additions & 0 deletions packages/plugin-define/README_CN.md
@@ -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/)



2 changes: 2 additions & 0 deletions packages/redux/README.md
@@ -1,3 +1,5 @@
English | [简体中文](./README_CN.md)

# Redux in WePY 2.0

## Install
Expand Down
103 changes: 103 additions & 0 deletions packages/redux/README_CN.md
@@ -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)
2 changes: 2 additions & 0 deletions packages/use-intercept/README.md
@@ -1,3 +1,5 @@
English | [简体中文](./README_CN.md)

# @wepy/use-intercept

weapp APIs intercept factory.
Expand Down
44 changes: 44 additions & 0 deletions packages/use-intercept/README_CN.md
@@ -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;
}
})
```

2 changes: 2 additions & 0 deletions packages/use-promisify/README.md
@@ -1,3 +1,5 @@
English | [简体中文](./README_CN.md)

# @wepy/use-promisify

Promisfy all weapp APIs.
Expand Down
95 changes: 95 additions & 0 deletions packages/use-promisify/README_CN.md
@@ -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)
2 changes: 2 additions & 0 deletions packages/x/README.md
@@ -1,3 +1,5 @@
English | [简体中文](./README_CN.md)

# Vuex in WePY 2.0

## Install
Expand Down

0 comments on commit feda5b8

Please sign in to comment.