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: make dispose support disposing instance of useFactory #116

Merged

Conversation

zhangpanweb
Copy link
Contributor

@zhangpanweb zhangpanweb commented Nov 11, 2023

处理 #111

处理方式:把 instance 挂在 creator 上, 形式为一个 Set 。原 instanceDisposedEmitter 方法,不再以 instance 为参数,而是以 creator 作为参数。当 creator dispose 时,重置 creator.instance

同时解决以下问题:

  • useFactorydispose 时 instance 无法被删除
  • 在之前的情况下 class provider 为多例模式时,执行 dispose 时, 实例的 dispose 方法不会被调用。更新后, 多例的 class providerdispose 时,其所有实例的 dispose 方法都会被调用
  • hasInstance 无法判别 useFactory, 更新后,useFactory 的返回值,也可以通过 hasInstance 来进行判别。且多例 class providerinstance 同样可以被判别。

@CLAassistant
Copy link

CLAassistant commented Nov 11, 2023

CLA assistant check
All committers have signed the CLA.

src/declare.ts Show resolved Hide resolved
onceInstanceDisposed(instance: any, cb: () => void) {
const instanceId = this.getInstanceId(instance);
if (!instanceId) {
onceInstanceDisposed(creator: InstanceCreator, cb: () => void) {
Copy link
Member

Choose a reason for hiding this comment

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

这里的入参最好还是用 instance

@bytemain bytemain changed the base branch from main to next December 3, 2023 08:54
@bytemain bytemain merged commit 4a9e4a3 into opensumi:next Dec 3, 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.

3 participants