Realm addListener methods called for zero modifications
See original GitHub issueGoals
I am trying to add listener on the realm result objects in the constructor method of the component using the below code to identify any modifications/deletions and insertions if made on the realm dB Object. https://realm.io/docs/javascript/2.29.0/api/Realm.Results.html#addListener
Eg: this.PositionDB.addListener(this.listenToPositionChanges);
and
listenToPositionChanges = (collection, changes) => { console.log(changes.insertions.length + "insertions"); console.log(changes.modifications.length + "modifications"); console.log(changes.newModifications.length + "newModifications"); console.log(changes.oldModifications.length + "oldModifications"); console.log(changes.deletions.length + "deletions"); console.log("new size of collection:"+ collection.length); }
Expected Results
The registered listener method should be called only when any changes are made to the specified Realm result object in realm dB
Actual Results
The method is called immediately after rendering the component - i.e, opening the page for the first time. The logs printed were as below which shows zero modifications to the realm object.
0insertions
0modifications
0newModifications
0oldModifications
0deletions
new size of collection:119
Steps to Reproduce
Add a listener on the realm result object and it is fired immediately after component mounts even if changes are not there
Code Sample
listenToPositionChanges = (collection, changes) => { console.log(changes.insertions.length + "insertions"); console.log(changes.modifications.length + "modifications"); console.log(changes.newModifications.length + "newModifications"); console.log(changes.oldModifications.length + "oldModifications"); console.log(changes.deletions.length + "deletions"); console.log("new size of collection:"+ collection.length); }
Version of Realm and Tooling
- Realm JS SDK Version: 2.29.0
- Node or React Native: 0.59.10
- Client OS & Version: Android - 7.1
- Which debugger for React Native: None
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (5 by maintainers)
@kneth I actually ended up finding the culprit. My code was actually recreating the listener and re initializing the query, so it only seemed like it kept firing.
@miwialex Can it be that you have empty write transactions?