-
Notifications
You must be signed in to change notification settings - Fork 572
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
Need a way to control listeners when realm.create #5864
Comments
It will be also great if we add a way to set debounce for listener. i present way it will listener trigger twice. |
@somasekharkakarla Can you write a code sample on what you would expect for the syntax of this feature? Would this be an extension on our current event listeners? It is currently possible to add a listener to a collection. The event listener callback lets you see what objects were recently created. Ref: https://www.mongodb.com/docs/realm-sdks/js/latest/Realm.Collection.html#addListener |
Hi @takameyer Yes, an extension on our current event listeners. Syntax example: Create/Update: Delete: Syntax should both ways |
If we were to do this, it would have to be done at the We will have to discuss internally if this is something we want to set aside resources for. It does make sense to be able to refine the event listeners so they aren't as noisy. What we could add, which is actually in core are "key path listeners". These would enable the user to provide which fields they are interested in and only fire the listener when they change. |
if we done at addListener there is a problem. Suppose i have a model called model 1 Adding listener to model 1 = > model. addListener (which will listen for an update) now i am add two objects to model1 in two situation like realm.create("model1", {uid:'1', name:'test1'}) => i want to listen this if we do it at addListener level how we achieve it |
hi @takameyer, |
@somasekharkakarla It is in our backlog, but we haven't gotten to it yet. Although we have recently released support for key path listeners. With this it would be possible to set which fields will fire the event listener. In the case above it could be used as a workaround by creating an optional field to listen to in the model. |
Problem
Standard way:
In this example we consider a case of Mobile and Server
For example, In Mobile there is collection called Tasks
Tasks has following fields
i added a change listener to this object.
whenever i change these fields from my mobile, change listener tiggers and object or list i got from it will be sent to the server.
Perfect till now.
Problem:
when i get response. Here there are 2 scenarios
1. Nothing changed at server side
eg: i changed status to 1.
Req:
Res:
so i take this response and update in realm. Because both Objects are same, change listener will not trigger
2. something changed at server side
eg: i changed status to 1. Before i sent the request, someone changed priorities to 1 in the server.
Req:
Res:
so i take this response and update in realm using realm.create. Because both Objects are not same. change listener will trigger and says priorities changed
As of now point of truth to send response to the server is the change listener.
In this second scenario, it will keep on calling the server till both mobile side and server side copies are same.
In some scenarios mobile side and server side copies must not be same where i can save the number of calls.
Solution
To stop this. we need to have control on listeners when we use realm.create, like we have Modified.update, we should also have listen true/false
Alternatives
No response
How important is this improvement for you?
Dealbreaker
Feature would mainly be used with
Local Database only
The text was updated successfully, but these errors were encountered: