ResultsChange

This sealed interface describe the possible changes that can happen to a query results collection.

The states are represented by the specific subclasses InitialResults and UpdatedResults.

Changes can thus be consumed in a number of ways:

// Variant 1: Switch on the sealed interface
realm.query<Person>().asFlow()
.collect { resultsChange: ResultsChange<Person> ->
when(resultsChange) {
is InitialResults -> setUIResults(resultsChange.list)
is UpdatedResults -> updateUIResults(resultsChange) // Android RecyclerView knows how to animate ranges
}
}


// Variant 2: Just pass on the list
realm.query<Person>().asFlow()
.collect { resultsChange: ResultsChange<Person> ->
handleChange(resultsChange.list)
}

When the query results change, extra information is provided describing the changes from the previous version. This information is formatted in a way that can be feed directly to drive animations on UI components like RecyclerView. In order to access this information, the ResultsChange must be cast to the appropriate subclass.

realm.query<Person>().asFlow()
.collect { resultsChange: ResultsChange<Person> ->
when(resultsChange) {
is InitialResults -> setList(resultsChange.list)
is UpdatedResults -> { // Automatic cast to UpdatedResults
updateResults(
resultsChange.list,
resultsChange.deletionRanges,
resultsChange.insertionRanges,
resultsChange.changeRanges
)
}
}
}

Inheritors

Properties

Link copied to clipboard
abstract val list: RealmResults<T>