diff --git a/.gitignore b/.gitignore index dc6aa150..f699d161 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ npm-debug.log yarn.lock test/fixtures/egg/node_modules/egg-core .idea -.nyc_output \ No newline at end of file +.nyc_output +package-lock.json diff --git a/lib/egg.js b/lib/egg.js index b5edf430..39ce1a87 100644 --- a/lib/egg.js +++ b/lib/egg.js @@ -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 */ @@ -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); @@ -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; @@ -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* () { diff --git a/lib/lifecycle.js b/lib/lifecycle.js index 527de8e5..a5a82d90 100644 --- a/lib/lifecycle.js +++ b/lib/lifecycle.js @@ -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'); @@ -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) { diff --git a/test/loader/file_loader.test.js b/test/loader/file_loader.test.js index 3da37eec..47bfe89d 100644 --- a/test/loader/file_loader.test.js +++ b/test/loader/file_loader.test.js @@ -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: [