-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- Thank you for your pull request. Please review below requirements. Bug fixes and new features should include tests and possibly benchmarks. Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md 感谢您贡献代码。请确认下列 checklist 的完成情况。 Bug 修复和新功能必须包含测试,必要时请附上性能测试。 Contributors guide: https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md --> ##### Checklist <!-- Remove items that do not apply. For completed items, change [ ] to [x]. --> - [ ] `npm test` passes - [ ] tests and/or benchmarks are included - [ ] documentation is changed or added - [ ] commit message follows commit guidelines ##### Affected core subsystem(s) <!-- Provide affected core subsystem(s). --> ##### Description of change <!-- Provide a description of the change below this comment. --> <!-- - any feature? - close https://github.com/eggjs/egg/ISSUE_URL --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced static lifecycle hooks for improved lifecycle management. - Added a `preLoad` method to enhance egg object initialization. - Implemented a `preLoad` method for module pre-loading operations. - Created a new class `Foo` to manage lifecycle events with various hooks. - **Bug Fixes** - Enhanced error handling in the `preLoad` function to provide clearer error messages. - **Tests** - Expanded test suite to validate the functionality of the new lifecycle methods and pre-loading behavior. - **Documentation** - Added metadata for the new lifecycle module in `package.json`. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information
1 parent
27fd9ff
commit 2b72163
Showing
11 changed files
with
173 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
SingletonProto, | ||
LifecyclePreLoad, | ||
LifecyclePostConstruct, | ||
LifecyclePreInject, | ||
LifecyclePostInject, | ||
LifecycleInit, | ||
LifecyclePreDestroy, | ||
LifecycleDestroy, | ||
} from '@eggjs/tegg'; | ||
import { Runner, MainRunner } from '@eggjs/tegg/standalone'; | ||
|
||
@Runner() | ||
@SingletonProto() | ||
export class Foo implements MainRunner<string[]> { | ||
|
||
static staticCalled: string[] = []; | ||
|
||
getLifecycleCalled() { | ||
return Foo.staticCalled; | ||
} | ||
|
||
@LifecyclePreLoad() | ||
static async _preLoad() { | ||
Foo.staticCalled.push('preLoad'); | ||
} | ||
|
||
constructor() { | ||
Foo.staticCalled.push('construct'); | ||
} | ||
|
||
@LifecyclePostConstruct() | ||
protected async _postConstruct() { | ||
Foo.staticCalled.push('postConstruct'); | ||
} | ||
|
||
@LifecyclePreInject() | ||
protected async _preInject() { | ||
Foo.staticCalled.push('preInject'); | ||
} | ||
|
||
@LifecyclePostInject() | ||
protected async _postInject() { | ||
Foo.staticCalled.push('postInject'); | ||
} | ||
|
||
protected async init() { | ||
Foo.staticCalled.push('init should not called'); | ||
} | ||
|
||
@LifecycleInit() | ||
protected async _init() { | ||
Foo.staticCalled.push('init'); | ||
} | ||
|
||
@LifecyclePreDestroy() | ||
protected async _preDestroy() { | ||
Foo.staticCalled.push('preDestroy'); | ||
} | ||
|
||
@LifecycleDestroy() | ||
protected async _destroy() { | ||
Foo.staticCalled.push('destroy'); | ||
} | ||
|
||
async main(): Promise<string[]> { | ||
return Foo.staticCalled; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "lifecycle", | ||
"eggModule": { | ||
"name": "lifecycle" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters