You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For frameworks like RxJava (#865) and others that work better with value type semantics, being able to specify a RealmObject as @Immutable would go a long way.
The semantics of this would be that marking a RealmObject as @Immutable would change the requirements of getters and setters to instead requiring a constructor with all fields + only getters. Like so
@Immutable
public class Foo extends RealmObject {
private int bar;
// Only legal constructor
public Foo(int bar) {
this.bar = bar;
}
public int getBar() {
return bar;
}
}
There are corner cases to consider though, eg. comparing a RealmObject with Standalone object, and possible others.
The text was updated successfully, but these errors were encountered:
Having used Reactive Programming extensively for an application where thread safety is key, I'm thinking of a variant of this.
Need
In a highly reactive context, we need to represent data with immutable objects that can be safely passed through observables, whatever the consuming thread.
This is true also when the underlying data changes! In that case we need each time another immutable object representing the updated data.
Consequence
This calls for a different pattern: instead of instantiating one RealmObject descendant class and updating the fields when data changes, instantiate immutable RealmObject descendant class each time one is needed.
Optionally (because in my experience it was not necessary), a method can be called on such an object to see if it's still up-to-date.
This pattern could be implemented as an option, since it's not the default Realm behavior.
For frameworks like RxJava (#865) and others that work better with value type semantics, being able to specify a RealmObject as
@Immutable
would go a long way.The semantics of this would be that marking a RealmObject as
@Immutable
would change the requirements of getters and setters to instead requiring a constructor with all fields + only getters. Like soThere are corner cases to consider though, eg. comparing a RealmObject with Standalone object, and possible others.
The text was updated successfully, but these errors were encountered: