This is a pretty general question but the concept of “Live Objects” keeps coming up in the Realm DB docs. We are building an Electron app using Realm local nodejs. We haven’t been able to conceptually understand when the concept of Live Objects would apply to what we are doing with Realm / JS. Does this apply more if we were using something like React where Live Objects may “do something” / update the UI on its own? Because with our basic Electron app (no UI framework) we just pass back and forth between the main and renderer (UI) processes Realm _id primary keys to fetch and push the data back and forth to and from the UI. So we can’t seem to understand where the concept of a Live Object would apply?
Is it as simple as if we stored a Realm object as a global variable then if that Object updates/changes that global variable of that Realm Object would update and stay “live and up to date”? Sorry for the noob question!
@valentin_cournee It sounds like your use case, implementation and the actual question may be a bit different from the OP’s - I believe they were more asking in general what a ‘live object’ is. It sounds like you have more of a coding specific question. It may be best create a new question with your code and a description of what you’re attempting to do.
e.g. you asked
A better what to do what? What isn’t working with the way you’re doing it? Providing some additional details may result in an answer - or at least a suggestion.
Hi Jay , thank you for your answer. In my opinion we both have the same question. How to better apply the concept of live objects.
In their question :
“Because with our basic Electron app (no UI framework) we just pass back and forth between the main and renderer (UI) processes Realm _id primary keys to fetch and push the data back and forth to and from the UI. So we can’t seem to understand where the concept of a Live Object would apply?”
My project does actually … the same…
I have a Electron app wich is connected to a realm app,
I convert Realm Objects (live) to JSON…
send those JSON via IPC to the frontend UI (REACT)
then send back the data once modified , still via IPC to Electron
finally electron update the data in Realm.
i can add a listener in electron, and each time a change is detected send the new JSON to the UI
I guess our questions are quite the same (unless im wrong): How to make a better use of the “live” property of Realm Objects.?
Is it as simple as if we stored a Realm object as a global variable then if that Object updates/changes that global variable of that Realm Object would update and stay “live and up to date”? Sorry for the noob question!
→ If yes im interested in the answer (Can we create a global live object usable by both the back and frontend ?)
My idea was slightly different but has the same goal:
I obviously think that React is by nature made to be updated every time its data change. Its seems the perfect combination with Realm Objects. But we seems to loose this benefit by using Electron and IPCmessages…
→ Should we skip Electron and implement Realm directly in the UI ? (or in both ?)
In both our case we have to trigger an IPC event each time there is an update in the realm. Is there something better to do?
Understood. If you look at the OP’s question, there was no answer and no activity for 6 months, which is why I suggested posting something new with details on your more specific use case.
IMO It seems like there’s a lot of redundancy in what’s being described.
Realm has full node.js SDK support so supporting Javascript and the like is baked in. Cross platform development is part of what Realm is, including React Native support and a Web SDK
The act of converting Realm objects to JSON makes them not live objects (now it’s JSON!) but it’s not clear why that’s being done or what the use case it. Could it benefit from live objects? Maybe!
You’ve already got listeners in Electron so adding additional Realm listeners seems redundant - unless it provides additional functionality that you don’t already have - but again, it’s not clear what that would be.
Sure. But why? What would a global var do for you over say, in a friend-tracker all, observing friends within a 1-mile radius of you and being notified if a friend leaves or comes into your radius.
That sounds like you’re “manually” triggering an IPC event - for what purpose? We’re using event driven programming here so why not let the server do the heavy lifting? e.g. If a user updates their favorite food, that should trigger an event automatically and all other users who are interested in that user should know about it - and Realm does just that from the UI to the backend local storage to the synced data.
I am obviously speaking at the 10,000’ level but as you can see - there are a LOT of variable and use cases so how Realm can benefit any specific use case will depend on what’s needed.
That probably doesn’t help a lot (lol) but just food for thought if you do post a question.
Ipc communication in electron doesnt allow us to send live object.
If i try to send a live object to my UI i will just receive an empty one… That’s the reason for the conversion.
And that’s the biggest part of the problem in fact. It would be wonderful to send the live object to the UI and let them do thei magic (as React can update itself when data change).
Actually unless im wrong, if i want to use / read / update a live object in react the only solution is to use the WebSDK … in that case… the problem is reverted: electron wont be able to access the live objects.
Lets say i have a table of all the users in my UI.
Actually if a users change its data somewhere else (on another app) … i can listen to this change in electron (as its “connected” to realm and its lives objects)
But in order to update my UI i have to send the new data from electron to react through BrowserWindow.webcontent.send (IPC)… and to do that… convert it first toJSON…
Am i missing something?
So if i understood correctly :
either I keep doing that
either I use Realm directly in react with WebSdk (wich is less rich than the node)
either their is a way to pass the live object from electron to react that i dont know of…
At this point we’re getting into high level overall design, which really goes beyond what we can do here in the forums.
I think you have a better understand of the concept of Live Objects (which was the initial question) and how and what they do. The question still is though, do you even need that ability? It seems you have listeners already and are passing around JSON so ?
In a bigger picture, we don’t know what the use case is:
Why are you using Electron in the first place?
Can Realm via the Web SDK handle the entire project?
What are the design requirements?
Do you need live objects?
Why are the manual triggers for? How do they affect the data and the users experience?
Why pass around low level JSON data when there are other options?
As you can see, lots of questions we don’t have the answers to and honestly, even if we did, that barely scratches the surface of a total app design. So, don’t spend time answering those questions as it’s just an example of considerations of a project.
I would suggest digging into the Web SDK, node.js and the React SDK with a simple test project and see if it fits the bill - should only take a couple hours to eval those products and if it looks good, expand the project a bit. If it doesn’t then you’ve eliminated those variables.