-
Notifications
You must be signed in to change notification settings - Fork 576
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
Realm.Results.removeAllListeners() not working #6028
Comments
@rossicler-hostalky Thanks for posting this issue. We will investigate and get back to you. |
I have the same issue (realm-js 11.9.0).
Every time I call This creates many issues in my app. Any idea what is causing it? |
@rossicler-hostalky @mednche Hi there, the reason this is happening is that the listeners are applied to the instance of the returned collection. This is by design. Each time you call The collections returned from
|
Hi @takameyer, is there any other way to remove listeners previously created? Maybe it should have the option to return a unsub function when adding a new listener, kind of similar to web js listeners. My problem with this is that in the app I'm working we don't keep the "live" objects from realm, all results is always parsed to JSON objects, so changing that to keep the same instance of live objects between method calls will probably require some time to test and a lot of refactoring to work properly. Example of how it could work:
This way we don't really need to keep "live" objects instance, but keep the unsubscribe function instead. |
I was able to manage this by keeping the reference of the function my code:
Although this should work with no problems, I would recommend to consider my suggestion on the comment above. And thanks for the reply clarifying this issue. |
@rossicler-hostalky Happy you were able to find a workaround. Feel free to open a feature request. Aligning our event listeners on web js listeners sounds like an interesting enhancement. |
How frequently does the bug occur?
Always
Description
Expected result:
Remove all listeners from a collection when calling
results.removeAllListeners()
method.What actually happens:
When calling
results.removeAllListeners()
previously registered listeners are not removed.Stacktrace & log output
No response
Can you reproduce the bug?
Always
Reproduction Steps
Example code:
After calling this function for the second time, it duplicates the same listener.
Version
11.7.0
What services are you using?
Atlas Device Sync
Are you using encryption?
No
Platform OS and version(s)
macOS Monterey 12.6
Build environment
Electron ^23.0.0
Cocoapods version
No response
The text was updated successfully, but these errors were encountered: