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.

Improve DataObserver reference holding

See original GitHub issue

I’m trying to use obervable queries to detect when the user is logged in my application in order to start fetching data in background with correct authorization token.

    ...
    userBox.query().build().subscribe().observe(users -> fetchUserData());
    ...
    boxStore.subscribe(User.class).observe(class -> fetchUserData());

First “live” query doesn’t work whilst the second works fine whenever I put(user) a new user in the userBox.

Is this correct? I’m not sure from which thread the user is being inserted, might this be an issue? Does it make sense to use a “live” query to observe the insertion of new objects or is it just for changes in existing objects? Live queries would be great, for my application and are the main feature that made me pick ObjectBox, hope I can get it working.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Onheironcommented, Oct 17, 2017

Thanks! Keeping the reference works, though it’s kind of a drag.

1reaction
greenrobot-teamcommented, Oct 17, 2017

The only difference to subscribing using boxStore directly is a call to .weak() and .onlyChanges() when the subscription is built. As the second doesn’t matter when subscribing to a query (the initial value is always published) I assume it has to be the weak reference.

@Onheiron Can you try keeping a reference to the Query (result of build()) or DataSubscription (result of observer()) instance, for example in a field? -ut

Read more comments on GitHub >

github_iconTop Results From Across the Web

Observers - Reference - Backtrader
This observer stores the returns of the strategy and the return of a reference asset which is one of the datas passed to...
Read more >
What type of reference does NSNotificationCenter keep for ...
I believe a weak reference, though that's just from memory (no pun intended). what are the best practices for removing observers from the...
Read more >
LiveData overview - Android Developers
Create an instance of LiveData to hold a certain type of data. This is usually done within your ViewModel class. Create an Observer...
Read more >
ESTIMATING OBSERVER AND DATA REPUTATION IN ... - IHR
Figure 9: Pre-correction observation and reference data depth (top; note depth is positive down in this view, so vertical axis is increasing ......
Read more >
The Observer Pattern and Creational Methods - RxJS inDepth
RxJS improves upon this classical observer pattern by introducing a more robust ... so nothing has been emitted yet. obs just holds a...
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