-
Notifications
You must be signed in to change notification settings - Fork 97
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
Track active observables #309
base: master
Are you sure you want to change the base?
Conversation
Definitely going to need to ponder this a bit.
I don't think we need to go full Proxy. You can just monkeypatch the method. If you wanted to use Proxy, you should probably Proxy the entire Observable object and then trap the particular methods in the Proxy handlers. |
What is your suggestion so I could try implementing it? One problem I had before was that |
Ultimately not terribly different from what you have, except instead of returning a proxy, you return a new function.
Not 100% sure I follow; if you have an example, that would be helpful. But if we're wrapping the method, because we still end up calling the underlying method, I don't think it'll be an issue. |
Ok, I'll update this PR soon.
I misunderstood what you said earlier, I thought you had suggested we wouldn't call the original method. 👍 |
Okay, so I've pushed another code which does not use Proxy, now there is something weird happening, the following test would not unsubscribe the observable:
The following observable is still tracked by
I don't understand yet why this observable has not been removed from the array, but I'll debug it further. P.S.: Would you rather use |
- [x] mocha 7.0.0: dropped support for node v6.x - [x] mocha 8.0.0: dropped support for node v8.x - [x] mocha 8.0.0: deprecated mocha.opts - [x] mocha 9.0.0: dropped support for node v10.x
29100bf
to
d9b7257
Compare
@mAAdhaTTah I've finally come back to this PR and while there are commits that I need to extract into smaller PRs (some I already have), this is ready for review. I have a commit where I had to brute-force subscription deactivation because unless I missed it, I don't think there is another way to handle it with the existing code. I'm not sure if it's worth exporting the onAny function on |
a7aa6ff
to
48c1e92
Compare
78992b8
to
9402930
Compare
@mAAdhaTTah I'm thinking that maybe we shouldn't introduce a new dev dist and just include these methods on the normal distributed files? |
Maybe I should ask more generally: what's the purpose of this? Why do you need to track active observables? |
I think the main purpose of this would be to track memory leaks (or observable leaks). An usage example:
It's very easy to make a mistake and forget to unsubscribe an observable when using |
If the primary goal is testing, I think something like this might be more suited to the |
We could, though I think that tracking observables during a test environment is not the only usage. We could for instance want to run this on our browser window and make sure that while navigating from one page to another the number of observables is corresponding to what we expect. I was thinking about using a configurable environment variable that would default to the test environment so that users could opt in and out in any environment.
P.S.: I'm happy to move it to |
Hey all, first of all thanks for creating and managing this library.
I'd like to discuss adding support for tracking active observables so that we may support features like this on tests:
and to eventually create a browser extension or even simpler to do a
$K.activeObservables
on the browser console - assuming you've bound kefir to windowwindow.$K = Kefir
- and see if there are any memory leaks on your code.P.S.: I've pushed two commits labeled "remove me" with the intention to diff the modified dist files (see second commit), these commits are going to be removed before merging this PR.