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

fix: lifecycle hook should trigger only one time #168

Merged
merged 2 commits into from
Aug 16, 2022

Conversation

whxaxes
Copy link
Member

@whxaxes whxaxes commented Aug 11, 2022

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Description of change

生命周期的 hooks 应该只执行一次。

举例:使用 ts-node 跑 artus 应用,ctrl + c 的时候,SIGINT 触发两次会触发两次 beforeClose

@codecov-commenter
Copy link

codecov-commenter commented Aug 11, 2022

Codecov Report

Merging #168 (b69018e) into master (364a65e) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #168   +/-   ##
=======================================
  Coverage   89.59%   89.60%           
=======================================
  Files          51       51           
  Lines        1096     1097    +1     
  Branches      181      181           
=======================================
+ Hits          982      983    +1     
  Misses        114      114           
Impacted Files Coverage Δ
src/lifecycle/index.ts 82.85% <100.00%> (+0.50%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@noahziheng
Copy link
Member

改动思路或许有点过重了?

而且按照 Spec,生命周期中的 emitHook 其实应该只允许执行一次且必须按照 insert 的顺序执行;

是因为历史问题而没有加校验,是不是应该在 LifecycleManager 里面补全校验逻辑,既能解决问题,也无需引入新概念,反正都是 BREAKING CHANGE

@whxaxes
Copy link
Member Author

whxaxes commented Aug 11, 2022

@noahziheng 阔以,我去改一下 LifecycleManager ,state 这个我也不确定是不是合适,先提出来给大家 review

@whxaxes whxaxes force-pushed the feat-add-state-control branch from 789ef01 to 8acdeb9 Compare August 11, 2022 06:53
@whxaxes whxaxes changed the title feat: add state control feat: lifecycle hook should trigger only one time Aug 11, 2022
@whxaxes
Copy link
Member Author

whxaxes commented Aug 11, 2022

@noahziheng 妥了

Copy link
Member

@noahziheng noahziheng left a comment

Choose a reason for hiding this comment

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

LGTM,@hyj1991 Need review together.

@whxaxes whxaxes changed the title feat: lifecycle hook should trigger only one time fix: lifecycle hook should trigger only one time Aug 11, 2022
Copy link
Collaborator

@DuanPengfei DuanPengfei left a comment

Choose a reason for hiding this comment

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

LGTM;

@@ -68,6 +68,8 @@ export class LifecycleManager {
if (!Array.isArray(fnList)) {
return;
}
// lifecycle hook should only trigger one time
this.hookFnMap.delete(hookName);
Copy link
Member

Choose a reason for hiding this comment

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

不是所有的 hook 都只执行一次吧?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

有需要执行多次的 hook 吗?好像也没有把?

Copy link
Member

Choose a reason for hiding this comment

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

设计上确实应该执行一次,如果有多次触发的类似事件分发机制的场景,就不该通过 Lifecycle 做,应该考虑 Trigger 或者 EventEmitter

@noahziheng noahziheng force-pushed the feat-add-state-control branch from 8acdeb9 to a670349 Compare August 12, 2022 07:12
@hyj1991 hyj1991 merged commit 57fa1ff into master Aug 16, 2022
@whxaxes whxaxes deleted the feat-add-state-control branch August 16, 2022 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants