-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
Current coverage is 97.49% (diff: 100%)@@ 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
|
9c4bcfc
to
e574250
Compare
可以 review 了 |
|
||
## 应用、框架和插件 | ||
|
||
egg 是一个底层框架,应用可以直接使用,但 egg 本身的插件比较少,应用需要自己配置插件增加各种特性,比如 mysql。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MySQL
} | ||
} | ||
|
||
// plugin.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config/plugin.js
+-----------------------------------+--------+ | ||
``` | ||
|
||
## loadUnit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
``` | ||
app | ||
| ├─- plugin2 (依赖 plugin3) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
请查看 Loader.getLoadUnits 方法
加上 init.js 说明就好了,没看出什么问题。 |
There was a problem hiding this 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。所以这个方法加载的文件是会在每次请求实例化的。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
所以这个类只有每次请求中首次访问到时才会实例化,实例化后会被缓存,同一个请求多次调用也只会实例化一次。
|
||
#### override [Boolean] | ||
|
||
是否覆盖已经存在的文件,如果出现同名文件会报错,默认为 false。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
遇到已经存在的文件时是直接覆盖还是抛出异常,默认为 false
这样好点?
Checklist
npm test
passesAffected core subsystem(s)
doc
Description of change
loader