Skip to content

Commit

Permalink
Chore (gitignore, file_loader.test.js): Update files (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maledong authored and dead-horse committed Jan 28, 2019
1 parent b958870 commit 29118e5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ npm-debug.log
yarn.lock
test/fixtures/egg/node_modules/egg-core
.idea
.nyc_output
.nyc_output
package-lock.json
33 changes: 24 additions & 9 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ class EggCore extends KoaApplication {
}

/**
* Execute scope after loaded and before app start
* Execute scope after loaded and before app start.
*
* Notice:
* This method is now NOT recommanded and reguarded as a deprecated one,
* For plugin development, we should use `didLoad` instead.
* For application development, we should use `willReady` instead.
*
* @see https://eggjs.org/en/advanced/loader.html#beforestart
*
* @param {Function|GeneratorFunction|AsyncFunction} scope function will execute before app start
*/
Expand Down Expand Up @@ -249,8 +256,16 @@ class EggCore extends KoaApplication {
}

/**
* Register a function that will be called when app close
* @param {Function} fn - the function that can be generator function or async function
* Register a function that will be called when app close.
*
* Notice:
* This method is now NOT recommanded directly used,
* Developers SHOULDN'T use app.beforeClose directly now,
* but in the form of class to implement beforeClose instead.
*
* @see https://eggjs.org/en/advanced/loader.html#beforeclose
*
* @param {Function} fn - the function that can be generator function or async function.
*/
beforeClose(fn) {
this.lifecycle.registerBeforeClose(fn);
Expand Down Expand Up @@ -317,13 +332,13 @@ class EggCore extends KoaApplication {
* @param {Function} fn The inputted function.
* @return {AsyncFunction} An async promise-based function.
* @example
* ```javascript
* const fn = function* (arg) {
```javascript
const fn = function* (arg) {
return arg;
};
const wrapped = app.toAsyncFunction(fn);
wrapped(true).then((value) => console.log(value));
* ```
```
*/
toAsyncFunction(fn) {
if (!is.generatorFunction(fn)) return fn;
Expand All @@ -338,14 +353,14 @@ class EggCore extends KoaApplication {
* @param {Mixed} obj The inputted object.
* @return {Promise} A Promisable result.
* @example
* ```javascript
* const fn = function* (arg) {
```javascript
const fn = function* (arg) {
return arg;
};
const arr = [ fn(1), fn(2) ];
const promise = app.toPromise(arr);
promise.then(res => console.log(res));
* ```
```
*/
toPromise(obj) {
return co(function* () {
Expand Down
3 changes: 1 addition & 2 deletions lib/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const getReady = require('get-ready');
const { Ready } = require('ready-callback');
const { EventEmitter } = require('events');
const debug = require('debug')('egg-core:lifecycle');

const INIT = Symbol('Lifycycle#init');
const INIT_READY = Symbol('Lifecycle#initReady');
const DELEGATE_READY_EVENT = Symbol('Lifecycle#delegateReadyEvent');
Expand Down Expand Up @@ -83,7 +82,7 @@ class Lifecycle extends EventEmitter {

addFunctionAsBootHook(hook) {
assert(this[INIT] === false, 'do not add hook when lifecycle has been initialized');
// app.js is export as a funciton
// app.js is exported as a function
// call this function in configDidLoad
this[BOOT_HOOKS].push(class Hook {
constructor(app) {
Expand Down
2 changes: 1 addition & 1 deletion test/loader/file_loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('test/loader/file_loader.test.js', () => {
assert.deepEqual(instance.getUser(), { name: 'xiaochen.gaoxc' });
});

it.skip('should only load property match the filers', () => {
it('should only load property match the filers', () => {
const app = { middlewares: {} };
new FileLoader({
directory: [
Expand Down

0 comments on commit 29118e5

Please sign in to comment.