ObjectChange
This sealed interface describe the possible changes that can be observed to a Realm Object.
The specific states are represented by the specific subclasses InitialObject, UpdatedObject and DeletedObject.
Changes can thus be consumed in a number of ways:
// Variant 1: Switch on the sealed interface
realm.filter<Person>().first().asFlow()
.collect { objectChange: ObjectChange<Person> ->
when(objectChange) {
is InitialObject -> initPersonUI(objectChange.obj)
is UpdatedObject -> updatePersonUi(objectChange.obj, objectChange.changedFields)
is DeletedObject -> removePersonUi()
}
}
// Variant 2: Just pass on the object
realm.filter<Person>().first().asFlow()
.collect { objectChange: ObjectChange<Person> ->
handleChange(objectChange.obj)
}
Content copied to clipboard
For state of update changes, a list with the updated field names from the previous version is provided.