question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Realm addListener methods called for zero modifications

See original GitHub issue

Goals

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:closed
  • Created 4 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
miwialexcommented, Aug 10, 2021

@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.

0reactions
knethcommented, Aug 10, 2021

@miwialex Can it be that you have empty write transactions?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Realm.Object - MongoDB
Add a listener callback which will be called when a live object instance changes. Parameters: callback. Type: function. A function to be called...
Read more >
How do i get old modification values in Realm Javascript ...
Use .snapshot() method to get the old value. import Realm from 'realm'; /* Use "let" not "const" */ let userdata ...
Read more >
How to use the realm.Sync function in realm - Snyk
To help you get started, we've selected a few realm.Sync examples, based on popular ways it is used in public projects.
Read more >
Realm Database
Realm Database is a fast, easy to use, and open source alternative to SQLite and Core Data. Pick your language. Java · Swift...
Read more >
Realm JavaScript for React Native applications - YouTube
In this event, Andrew Meyer, Software Engineer, on the Realm JavaScript team, will walk us through the React Native ecosystem as it relates ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found