Replies: 1 comment 2 replies
-
I'm not convinced that Is there some way we could take the |
Beta Was this translation helpful? Give feedback.
-
I'm not convinced that Is there some way we could take the |
Beta Was this translation helpful? Give feedback.
-
One thing I hear from a lot of people who are new to Rx is they find it very hard to debug, and so I'd like to gauge the interest in the development of a new
Spy
operator that will improve people's ability to debug and/or log their Rx applications.First of all, I want to stress this is not my idea. All of this code has been adapted from this StackOverflow thread.
In my Q&D test projects, I use something very similar (with added events). It isn't optimal and won't work for everyone, but it is SO handy to be able to see the subscriptions and values and which thread they come on when trying to figure out why something Rx-related isn't working.
The idea is a new operator that will receive a callback interface to log each Rx event as it happens (including subscription and disposal). If there's interest and a suitable API can be made, then I'm happy to submit a PR for this.
The SO post does everything with strings, but that won't work for everyone. So, instead of just handling strings, I'm picturing something that uses an interface or some callback to handle the different events that can occur so that consumers can customize the logging or text that is associated with those events. At that point, if we want an overload that converts the events into a string and emit them to something like
Console.WriteLine
, then that would be easy to layer on top.A first draft of pulling out all of the events to be logged and putting them into an interface looks something like this:
And then a very basic implementation of
IObservableSpy
could be something like:Example Usage:
The only thing that I'm 100% sure about is that this approach has been very useful to me and I feel like others would benefit from it as well. Everything else is up in the air and I'd love to hear feedback and suggestions for improvement.
Beta Was this translation helpful? Give feedback.
All reactions