Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN Partial Subscription missing addListener #1886

Closed
sambwest opened this issue Jun 21, 2018 · 3 comments · Fixed by #1902
Closed

RN Partial Subscription missing addListener #1886

sambwest opened this issue Jun 21, 2018 · 3 comments · Fixed by #1902

Comments

@sambwest
Copy link

sambwest commented Jun 21, 2018

Background

I use realm on the server using Node and in React Native. On the server this issue doesn't happen, it is only in React native

Goals

Attach a listener to an object subscription

Expected Results

The listener is attached.

Actual Results

subscription.addListener is not a function. It does return an object, but it doesn't have any of the methods in the docs. The objects are subscribed to ok.

Steps to Reproduce

Try and add a listener to a object subscription in React Native

Code Sample

I'm actually using the listener function from your tests but the same thing happens using vanilla.

  subscribe (results) {
    const subscription = results.subscribe()
    return new Promise((resolve, reject) => {
      subscription.addListener((subscription, state) => {
        if (state === Realm.Sync.SubscriptionState.Complete) {
          resolve()
        }
        else if (state === Realm.Sync.SubscriptionState.Error) {
          reject()
        }
      })
      setTimeout(() => reject('listener never called'), 5000)
    })
  }

let objs = realm.objects('User');
await subscribe(objs);

Normal example

let objs = realm.objects('User');
let sub = objs.subscribe();
sub.addListener((subscription, state) => {
...
})

Version of Realm and Tooling

  • Realm JS SDK Version: 2.8.3
  • Node or React Native: 0.55.4
  • Client OS & Version:
  • Which debugger for React Native: Chrome
@kneth
Copy link
Member

kneth commented Jun 25, 2018

Just to clarify: subscribe() does not return an object which has methods like addListener()? And you only observe this with React Native?

@kneth kneth added the T-Help label Jun 25, 2018
@sambwest
Copy link
Author

Exactly. Only in react native. The exact same code works in node. The documentation here says it should return a Realm.Sync.Subscription. (https://realm.io/docs/javascript/latest/api/Realm.Results.html#subscribe). See comment in code below.

let objs = realm.objects('User');
let sub = objs.subscribe();

// here typeof sub.addListener === 'undefined' 

sub.addListener((subscription, state) => {
...
})

@kneth
Copy link
Member

kneth commented Jun 28, 2018

I have started implemented what is needed in #1902 but I don't expect to finish it until late next week.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants