Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Removed private WeakEventListener#4450

Open
puppetsw wants to merge 2 commits intoCommunityToolkit:main from
puppetsw:Issue_4059
Open

Removed private WeakEventListener #4450
puppetsw wants to merge 2 commits intoCommunityToolkit:main from
puppetsw:Issue_4059

Conversation

@puppetsw
Copy link
Contributor

@puppetsw puppetsw commented Jan 10, 2022

NetworkConnectionStateTrigger.cs had a private duplicate version of WeakEventListener. This has now been removed and uses the existing WeakEventListener in the toolkit.

Fixes

Issue #4059

PR Type

What kind of change does this PR introduce?

Bugfix

What is the current behavior?

"NetworkConnectionStateTrigger is using a private copy of WeakEventListener, it's identical to the one we already have in the Toolkit, so we should update the source to use the existing code within the Toolkit."

What is the new behavior?

"Use existing code over shadow copy."

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • New component
    • Pull Request has been submitted to the documentation repository instructions. Link:
    • Added description of major feature to project description for NuGet package (4000 total character limit, so don't push entire description over that)
    • If control, added to Visual Studio Design project
  • Sample in sample app has been added / updated (for bug fixes / features)
  • New major technical changes in the toolkit have or will be added to the Wiki e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

NetworkConnectionStateTrigger.cs had a private duplicate version of WeakEventListener. This has now been removed and uses the existing WeakEventListener in the toolkit.
Copy link

ghost commented Jan 10, 2022

Thanks puppetsw for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost requested review from azchohfi and michael-hawker January 10, 2022 00:39
Copy link
Member

@michael-hawker michael-hawker left a comment

Choose a reason for hiding this comment

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

Think this approach is still capturing the object.

OnDetachAction = listener => { NetworkInformation.NetworkStatusChanged -= OnNetworkEvent; }
};

NetworkInformation.NetworkStatusChanged += OnNetworkEvent;
Copy link
Member

@michael-hawker michael-hawker Jan 19, 2022

Choose a reason for hiding this comment

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

This should just be NetworkInformation.NetworkStatusChanged += _weakEvent.OnEvent - otherwise we capture the event and defeat the purpose of the WeakEventListener, no?

I wonder if we need to look at the history, the original developer probably had the copy because of the strange delegate from NetworkStatusChanged... Trying to think of how we can work around this...

Copy link
Member

@Arlodotexe Arlodotexe Jan 19, 2022
edited
Loading

Choose a reason for hiding this comment

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

NetworkInformation.NetworkStatusChanged += _weakEvent.OnEvent isn't possible because NetworkInformation.NetworkStatusChanged is a custom delgate, not a normal event handler.

We can probably use the sender to access fields on NetworkConnectionStateTrigger and make this method static, that might help?

michael-hawker and puppetsw reacted with thumbs up emoji
Copy link
Member

@Arlodotexe Arlodotexe Sep 8, 2022

Choose a reason for hiding this comment

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

@puppetsw Let's do the same thing for the OnDetachAction if we can.

Copy link
Contributor Author

@puppetsw puppetsw Sep 8, 2022

Choose a reason for hiding this comment

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

@Arlodotexe I'm sorry, but I'm not sure how to go about this, or I'm not understanding. If you could give a pointer I'm happy to make the change.

Copy link
Member

@Arlodotexe Arlodotexe Sep 13, 2022
edited
Loading

Choose a reason for hiding this comment

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

Dug into this a bit. Looks like OnDetachAction doesn't supply the access to the instance inside the delegate. Though it does null out the OnDetachAction after invoking it, so it should release the delegate and all references captured by it.

@michael-hawker does that sound right? Should be able to move forward if so.

@ghost ghost added the needs author feedback 📝 label Jan 19, 2022
Copy link

ghost commented Jan 19, 2022

This PR has been marked as "needs attention 👋" and awaiting a response from the team.

Copy link
Member

Copied from the original issue:

While closing #4450, we noticed that the code is not identical to what we have in the toolkit. It removes TEventArgs to allow us to do NetworkInformation.NetworkStatusChanged += weakEvent.OnEvent;.

After discussing with @michael-hawker, we won't be removing the private event listener for now. Instead, we'll use the more flexible CommunityToolkit/dotnet#404 when it arrives.

@michael-hawker michael-hawker modified the milestones: 7.1.3, 8.0 Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Arlodotexe Arlodotexe Arlodotexe approved these changes

@michael-hawker michael-hawker michael-hawker requested changes

@azchohfi azchohfi Awaiting requested review from azchohfi

+2 more reviewers

@LalithaNadimpalli LalithaNadimpalli LalithaNadimpalli approved these changes

@XAML-Knight XAML-Knight XAML-Knight approved these changes

Reviewers whose approvals may not affect merge requirements

Requested changes must be addressed to merge this pull request.

Projects

None yet

Milestone

8.0

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /