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.

Request: update example app to asynchronously open realm

See original GitHub issue

The current example initialises the realm in a seperate file (module) which is then exported and imported into the other files:

//realm.js
export default new Realm({schema: [Todo, TodoList]});

However, the docs state:

This is typically not recommended as it blocks and could potentially be a time consuming operation, especially if there are migrations to run or if the realm is synchronized and you don’t want to risk modifying data before it’s been completely downloaded. https://realm.io/docs/javascript/latest/#synchronously-opening-realms

Can the example app please be updated to show how to open the realm (with Realm.open) in a seperate file (module) which is then imported into the other components?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:24 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
kraenhansencommented, Dec 3, 2018

@MrHubble we’re working on an example app for React Native, until it’s merged you can have a look at the branch for the PR: https://github.com/realm/my-first-realm-app/tree/eric-rn/react-native/QueryBasedSync/ToDo

Here we’re using new Realm(config) to open a Realm instance when the user authenticates. Then we pass the realm instance to the apps router (in our case react-native-router-flux) to change into a “logged in” scene: https://github.com/realm/my-first-realm-app/blob/eric-rn/react-native/QueryBasedSync/ToDo/src/components/LoginForm.js#L61-L68

I hope this gives an idea on how this can be accomplished and I hope that we’ll soon be able to get better React Native examples published.

2reactions
knethcommented, Nov 26, 2018

Every new Realm or Realm.open must be paired with close. As React Native runs as 32 bit, you can easily run into memory issues (600-700 MB Realm files). It can be a good idea to compact the Realm when your app is launching (shouldCompactOnLaunch - https://realm.io/docs/javascript/2.20.0/api/Realm.html#~Configuration).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asynchronous API - Java SDK — Realm - MongoDB
The Java SDK lets you access network and disk resources in two ways: synchronously and asynchronously. While synchronous, or "sync", requests block ...
Read more >
How to use realm with async fetch request? - Stack Overflow
Finally ,I use realm like this: let realm = new Realm({schema:[JOB_SCHEMA.jobTrack],encryptionKey:getRealmKey()}); let objects ...
Read more >
The things I've learned using Realm | by Gabor Varadi - Medium
Observable async queries, change listeners, and lazy loading​​ So in practice, setting up a Realm query on the UI thread involves both defining...
Read more >
Build offline-first mobile application using MongoDB Realm ...
While these applications might make network requests when available, ... "Note: demo app supports offline sync, Open & Close a Local Realm ......
Read more >
4 Introduction to Developing Asynchronous Web Services
However, because request processing can be delayed, it is often useful for the client application to continue its work and handle the response...
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