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

feat: use singleton model insteadof context #89

Merged
merged 5 commits into from
Feb 1, 2023

Conversation

elrrrrrrr
Copy link
Contributor

@elrrrrrrr elrrrrrrr commented Jan 30, 2023

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
  • @eggjs/tegg-orm-plugin
Description of change

Adherence to the principles of tegg@3.
Use Singleton instead of Context for @model.

@codecov
Copy link

codecov bot commented Jan 30, 2023

Codecov Report

Base: 92.75% // Head: 92.75% // No change to project coverage 👍

Coverage data is based on head (dff0a1f) compared to base (fec8a3a).
Patch coverage: 94.11% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##           master      #89   +/-   ##
=======================================
  Coverage   92.75%   92.75%           
=======================================
  Files         214      214           
  Lines        4512     4512           
  Branches      460      458    -2     
=======================================
  Hits         4185     4185           
  Misses        327      327           
Impacted Files Coverage Δ
plugin/orm/lib/SingletonModelObject.ts 74.19% <88.88%> (ø)
plugin/orm/app.ts 96.96% <100.00%> (ø)
plugin/orm/lib/SingletonModelProto.ts 74.07% <100.00%> (ø)

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

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@killagu
Copy link
Contributor

killagu commented Jan 30, 2023

加个 tracer 的单测,保证下 ctx 正常工作吧。

@killagu
Copy link
Contributor

killagu commented Jan 31, 2023

后续 model 还要支持 Context 模式吗? 现在强制使用 Singleton 了

Singleton 里可以获取到当前上下文的。

@killagu
Copy link
Contributor

killagu commented Jan 31, 2023

就看 leoric emit 出来的事件,ctx 是否正常。

@elrrrrrrr
Copy link
Contributor Author

👌🏻 之前理解错了 我以为要同时支持 context 和 singleton 注入

import { EGG_CONTEXT } from '@eggjs/egg-module-common';

export class ContextModeObject implements EggObject {
export class SingletonModelObject implements EggObject {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

命名改为 Model 之前似乎是 typo

@@ -36,13 +40,13 @@ export class ContextModeObject implements EggObject {
}

static get ctx() {
return ctx?.get(EGG_CONTEXT);
return self.getContext();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

需要改为实时获取,防止 Model 在不同 Service 中通过不同 ContextProto 或 SingletonProto 引入

Copy link
Contributor

@killagu killagu left a comment

Choose a reason for hiding this comment

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

LGTM

@killagu killagu merged commit cfdfc05 into eggjs:master Feb 1, 2023
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.

2 participants