question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

v5 Request - Could you think about dropping the custom delegate types and just use normal EventHandler with models?

See original GitHub issue

Issue Type

  • Feature Request

Describe the issue Currently most of the events that you can hook into are custom delegates which at face value may seem useful but in real use cases it makes it trickier to do any sort of event proxying approaches. It also makes data more fragmented as there isnt a singular model representing the response data.

If normal EventHandler<SomeResponseModel> was used it simplifies the events and makes it simpler to just have a singular payload which contains the data you care about.

To give an example of why this is a problem, if you were to use RX to add things like event throttling or delays etc you cannot simply wrap them without doing a lot of legwork wrapping all the custom delegates and args, and if its has more than 1 response which contains complex models its a massive pain binding all that.

// Example binding to a custom delegate event i.e 
//  public delegate void CustomDelegate(A a, B b);
Observable
   .FromEvent<CustomDelegate, CustomOutput>(  // Need to handle both delegate and event/args, also need to make my own CustomOutput model
       h => (a, b) => h(new CustomOutput{ A= a, B = b }), // If there isnt a singular response arg its even more painful
       h => someObject.someEvent += h,
       h => someObject.someEvent -= h)
    .Select(x => x.EventArgs); // Outputs Observable<CustomOutput>

// Example binding to a EventHandler<CustomOutput> event
Observable
   .FromEventPattern<CustomOutput>( // Using normal EventHandler no need to faff
        h=> someObject.someEvent += h,
        h => someObject.someEvent -= h)
    .Select(x => x.EventArgs); // Outputs Observable<CustomOutput>

Versions OBS Version: N/A OBS WebSocket Version: 5.x OBS WebSocket Dotnet (this library) Version: 5.x OS: N/A

Additional context There was a PR which was done against the v4 which did this and many other things such as Async method handling but unfortunately due to the PR being one big thing vs lots of smaller chunks it was discarded, but for v4 I have had to use the fork of this library because it took me 10 minutes to wrap all existing events into observables when they were EventHandler<T> delegates, and I lost 2 hours trying to make all the required classes/wrapper logic for about 5 events with the custom delegates and gave up.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
BarRaidercommented, Sep 13, 2022

Overall looks good and aligns with what we discussed.

1reaction
BarRaidercommented, Sep 6, 2022

Overall I don’t have strong objections against this, however don’t have the bandwidth for this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Should I use EventHandler<T> and/or the EventArgs ...
I can see why sending the object could be useful, but not all the time - and a lot of the time, the...
Read more >
ASP.NET Core Blazor event handling
Learn about Blazor's event handling features, including event argument types, event callbacks, and managing default browser events.
Read more >
Clean event handler invocation with C# 6
However, this means having a different extension method for each delegate type. It's not too bad if you're using EventHandler but it's still ......
Read more >
Delegates | Unreal Engine 4.27 Documentation
Delegates can call member functions on C++ objects in a generic, type-safe way. A delegate can be ... To call your delegate, just...
Read more >
Events & Delegates in Unity
Learn how to connect scripts & objects using delegates, actions & Unity Events in my in-depth beginner's guide.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found