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

realm.removeAllListeners() not clearing listeners already registered

      We have 2 components in our React Native app. HomeScreen and Settings screens which have listeners registered on Realm.Collection to update the UI.

      From the settings screen, the user can clean the RealmDB. Before cleaning the DB, we are trying to remove the listeners on the collections.

      HomeScreen has listener on Users table.
      Settings screen has listener on the AppConfig table.

      Goals

      Expected Results

      All listeners on the collections must be removed when we use realm.removeAllListeners()

      Actual Results

      We are able to unregister only the listener in the Settings screen, as we have reference to it. For listener on the HomeScreen, we don't have the reference, as the user is navigated to settings screen.

      If we use realm.removeAllListeners(), they are not being removed.

      Code Sample

      User table listener

      `this.users = realm.objects('Users');
      this.users.addListener(this.usersDataListener);
      `

      AppConfig table listener

      `this.appConfig = realm.objects('AppConfig');
      this.appConfig.addListener(this.appConfigListener);
      `

      In the settings screen, the reference of this.appConfig collection is available. And hence, we can use this.appConfig.removeListener(this.appConfigListener) method. This is working as expected.

      We are not able to remove the listener on the User table as we don't have reference to it in the settings screen. Hence we are using realm.removeAllListeners() to remove all the listeners. But, this is not removing all the listeners and the listeners are being triggered while cleaning the realm db which is causing a crash in the app.

      Can you please help how to unregister the listeners in the SettingsScreen?

      Version of Realm and Tooling

      • Realm JS SDK Version: 2.21.0
      • Node or React Native: React Native - 0.57
      • Client OS & Version: Android 8 (Oreo)
      • Which debugger for React Native: None.

            Assignee:
            kenneth.geisshirt@mongodb.com Kenneth Geisshirt (Inactive)
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: