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)
}

For state of update changes, a list with the updated field names from the previous version is provided.

Inheritors

Properties

Link copied to clipboard
abstract override val obj: O?

Returns the newest state of object being observed. null is returned if the object has been deleted.