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: add advanced/loader.md #198

Merged
merged 2 commits into from
Jan 9, 2017
Merged

docs: add advanced/loader.md #198

merged 2 commits into from
Jan 9, 2017

Conversation

popomore
Copy link
Member

@popomore popomore commented Jan 8, 2017

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

doc

Description of change

loader

@codecov-io
Copy link

codecov-io commented Jan 8, 2017

Current coverage is 97.49% (diff: 100%)

Merging #198 into master will decrease coverage by 0.18%

@@             master       #198   diff @@
==========================================
  Files            34         35     +1   
  Lines           863        959    +96   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            843        935    +92   
- Misses           20         24     +4   
  Partials          0          0          

Powered by Codecov. Last update 055c865...e574250

@popomore
Copy link
Member Author

popomore commented Jan 9, 2017

可以 review 了

@popomore popomore mentioned this pull request Jan 9, 2017
31 tasks

## 应用、框架和插件

egg 是一个底层框架,应用可以直接使用,但 egg 本身的插件比较少,应用需要自己配置插件增加各种特性,比如 mysql。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MySQL

}
}

// plugin.js
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config/plugin.js

+-----------------------------------+--------+
```

## loadUnit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

特殊字符

image


```
app
| ├─- plugin2 (依赖 plugin3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多了一个 -


plugin1 为 framework1 依赖的插件,配置合并后 object key 的顺序会优先级于 plugin2/plugin3。因为 plugin2 和 plugin3 的依赖关系,所以交换了位置。framework1 继承了 egg,顺序会晚于 egg。应用最后加载。

请查看 [Loader.getLoadUnits 方法](https://github.com/eggjs/egg-core/blob/65ea778a4f2156a9cebd3951dac12c4f9455e636/lib/loader/egg_loader.js#L233)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请查看 Loader.getLoadUnits 方法

请查看 Loader.getLoadUnits 方法

@fengmk2
Copy link
Member

fengmk2 commented Jan 9, 2017

加上 init.js 说明就好了,没看出什么问题。

Copy link
Member

@fengmk2 fengmk2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

});
```

加载后 `app.serviceClasses.user` 就是 UserService,当调用 `ctx.service.user` 时会实例化 UserService。所以这个方法加载的文件是会在每次请求实例化的。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所以这个类只有每次请求中首次访问到时才会实例化,实例化后会被缓存,同一个请求多次调用也只会实例化一次。


#### override [Boolean]

是否覆盖已经存在的文件,如果出现同名文件会报错,默认为 false。
Copy link
Member

@dead-horse dead-horse Jan 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

遇到已经存在的文件时是直接覆盖还是抛出异常,默认为 false

这样好点?

@dead-horse dead-horse merged commit df3d7d4 into master Jan 9, 2017
@dead-horse dead-horse deleted the doc-loader branch January 9, 2017 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants