Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-343

Notifications should preserve the instance on which they are attached

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None

      This can be demonstrated with this sample code 
      myrealm.MyCustomValue = getValue();
      myrealm.addListener("change", (realm, notification) => {
      console.log(myrealm == realm); //false
      console.log(realm.MyCustomValue != undefined); //false
      })
      the realm instance inside the callback is a newly created realm instance just before invoking the callback. This is not only inefficient but also brakes logic and expectations as the above sample. 

      A better way would be to create a partially bound function which has the same myrealm instance as the first argument then preserve this bound function so notifications can be raised.

      The creation of newly created realm just before invoking the callback happen here 

      https://github.com/realm/realm-js/blob/73b3d0ad17e6ea9cbc0463154243cf292c7c8270/src/js_realm.hpp#L183

      Care should be taken not to create cycle retention of realm instances. ie the GC should be able to free the realm instance in any time.

            Assignee:
            Unassigned Unassigned
            Reporter:
            lubo.blagoev@mongodb.com Lubo Blagoev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: