v5 Request - Could you think about dropping the custom delegate types and just use normal EventHandler with models?
See original GitHub issueIssue 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:
- Created a year ago
- Comments:6 (6 by maintainers)
Top GitHub Comments
Overall looks good and aligns with what we discussed.
Overall I don’t have strong objections against this, however don’t have the bandwidth for this.