Skip to content

Commit

Permalink
docs(app-start): generator -> async (#1662)
Browse files Browse the repository at this point in the history
  • Loading branch information
atian25 authored and dead-horse committed Nov 14, 2017
1 parent 12c0a8a commit fb2d96a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 7 additions & 5 deletions docs/source/en/basics/app-start.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit fb2d96a

Please sign in to comment.