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

docs(app-start): generator -> async #1662

Merged
merged 1 commit into from Nov 14, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions docs/source/en/basics/app-start.md
Expand Up @@ -9,9 +9,9 @@ For example, we need to load a list of national cities from the remote server du
```js
// app.js
module.exports = app => {
app.beforeStart(function* () {
app.beforeStart(async () => {
// The lifecycle method runs before the application bootstraps
app.cities = yield app.curl('http://example.com/city.json', {
app.cities = await app.curl('http://example.com/city.json', {
method: 'GET',
dataType: 'json',
});
Expand All @@ -22,9 +22,11 @@ module.exports = app => {
`cities` attribute has attached on the global `app`. It can be accessed in the controller,

```js
// app/controller/city.js
module.exports = function* (ctx) {
// ctx.app.cities // access `cities` property on the global `ctx.app`
// app/controller/home.js
class HomeController extends Controller {
async index() {
// now you can use `ctx.app.cities`
}
}
```

Expand Down
12 changes: 7 additions & 5 deletions docs/source/zh-cn/basics/app-start.md
Expand Up @@ -8,9 +8,9 @@ title: 启动自定义
```js
// app.js
module.exports = app => {
app.beforeStart(function* () {
app.beforeStart(async () => {
// 应用会等待这个函数执行完成才启动
app.cities = yield app.curl('http://example.com/city.json', {
app.cities = await app.curl('http://example.com/city.json', {
method: 'GET',
dataType: 'json',
});
Expand All @@ -21,9 +21,11 @@ module.exports = app => {
在 Controller 中就可以使用了:

```js
// app/controller/city.js
module.exports = function* (ctx) {
// ctx.app.cities 在上面启动期间已经加载,可以直接使用
// app/controller/home.js
class HomeController extends Controller {
async index() {
// ctx.app.cities 在上面启动期间已经加载,可以直接使用
}
}
```

Expand Down