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

[NUI] Add WeakEventProxy class and improve invoke of WeakEvent #5424

Merged
merged 1 commit into from
Aug 1, 2023

Conversation

rabbitfor
Copy link
Collaborator

  • WeakEventProxy : The weak event connecting to a normal event.

Description of Change

API Changes

  • ACR:

@github-actions github-actions bot added the API10 Platform : Tizen 7.0 / TFM: tizen10.0 label Jul 28, 2023
@rabbitfor
Copy link
Collaborator Author

rabbitfor commented Jul 28, 2023

WeakEventProxy는 일반 이벤트를 weak event처럼 사용할 수 있게 proxy 역할을 하는 클래스입니다.
WeakEventManager는 버전 문제로 사용할 수 없는 것으로 보여 유사한 기능을 하는 간단한 클래스를 만들었습니다.

사용할 때는 아래와 같이 derived 클래스를 정의하고, 연결하려는 이벤트를 붙여줘야합니다.

class FontSizeChangedWeakEvent : WeakEventProxy<FontSizeChangedEventArgs>
{
    protected override void ConnectToEvent(EventHandler<FontSizeChangedEventArgs> handler)
    {
        SystemSettings.FontSizeChanged += handler;
    }

    protected override void DisconnectToEvent(EventHandler<FontSizeChangedEventArgs> handler)
    {
        SystemSettings.FontSizeChanged -= handler;
    }
}
static FontSizeChangedWeakEvent fontSizeChanged = new FontSizeChangedWeakEvent();

fontSizeChanged.Add((s, e) =>{
  // Write handler here
});

* WeakEventProxy : The weak event connecting to a normal event.

Signed-off-by: Jiyun Yang <[email protected]>
Copy link
Contributor

@hinohie hinohie left a comment

Choose a reason for hiding this comment

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

Looks good to me

{
handlers.RemoveAll(item => !item.IsAlive || item.Equals(handler));
}

public void Invoke(object sender, EventArgs args)
{
var copied = handlers.ToArray();
foreach (var item in copied)
var disposed = new HashSet<WeakHandler<T>>();
Copy link
Contributor

Choose a reason for hiding this comment

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

이렇게 사용하면 바로 Dispose가 호출되나요?

Copy link
Collaborator Author

@rabbitfor rabbitfor Aug 1, 2023

Choose a reason for hiding this comment

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

아뇨. 이 HashSet는 아래 foreach문을 돌때 IsAlive 가 false (이미 GC되어 reference에 닿을 수 없음을 뜻함)인 아이템들을 담기 위해 정의한 것이고 여기 담은 아이템들은 54라인에서 삭제합니다.

@rabbitfor rabbitfor merged commit 0c60cc1 into Samsung:API10 Aug 1, 2023
3 checks passed
@rabbitfor rabbitfor deleted the weakEventProxy branch August 1, 2023 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API10 Platform : Tizen 7.0 / TFM: tizen10.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants