Skip to content

Commit 0ffddeb

Browse files
committed
Correct StateFlow not updating with new List
Because the actual List pointer is the same, there is no difference between the value sent to emit and the value still in the StateFlow. To correct this, A new list is created by appending an immutable list with the new value, which is then saved internally and emitted. In response to work done: streetcomplete#5482
1 parent 1cce1a0 commit 0ffddeb

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

app/src/main/java/de/westnordost/streetcomplete/screens/about/LogsViewModelImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ class LogsViewModelImpl(
5959
filters.transformLatest { filters ->
6060
// get prior logs into a backing state
6161
// There will be duplication regardless.
62-
val logs = ArrayList(logsController.getLogs(filters))
62+
var logs: List<LogMessage> = logsController.getLogs(filters)
6363

6464
// emit the logs for the first view
6565
emit(logs)
6666

6767
// start listening to new logs
6868
getIncomingLogs(filters).collect {
69-
logs.add(it)
69+
logs = logs + it
7070
emit(logs)
7171
}
7272
}.stateIn(viewModelScope + Dispatchers.IO, SharingStarted.Eagerly, emptyList())

0 commit comments

Comments
 (0)