[React Native] subscription is a blank object?


#1

I wrote a demo app following “Partially synced Realms” on the documentation. However it doesn’t work as I imaged.

Here is code:

  async openDatabase() {
    const user = await Realm.Sync.User.login(REALM_SERVER, USERNAME, PASSWORD);
    const config = {
      schema: [heroSchema],
      sync: {
        user,
        url: 'realm://192.168.1.185:9080/heroes',
        partial: true,
        error: err => console.error(err),
      }
    }
    const db = await Realm.open(config);
    return db;
  }
    this.db = await this.openDatabase();

    const results = this.db.objects('Hero').sorted('name');
    const subscription = results.subscribe();

    results.addListener((collection, changes) => {
      console.log('listener fired');
      console.log('subscription', subscription);
      switch(subscription.state) {
        case Realm.Sync.SubscriptionState.Error:
          console.error('Sync error');
          break;
        case Realm.Sync.SubscriptionState.Complete:
          const heroes = collection.slice();
          console.log(heroes);
          this.setState({ heroes });
          break;
        default:
          console.log('Sync statue', subscription.state);
      }
    })

subscription is always a blank object {}, so subscription.state is always undefined.

did I miss something?