Daniel
05/25/2021, 5:40 PMTash
05/25/2021, 6:54 PMDaniel
05/25/2021, 6:54 PM/** Updates when style changes (and not when position changes)
* When style changes it will be combined with the latest position
*/
@OptIn(ExperimentalCoroutinesApi::class)
val book: Flow<Book?> = style.mapLatest { style ->
val epub = epub.await()
// TODO: This is a bad architecture. Style actually causes position update
val position = position.await()
if (epub != null && style != null && position != null) {
Book(bookId, epub, style, position)
} else {
null
}
}
/** Will not cause a change to the position of the book flow */
fun updatePosition(position: BookPosition) {
launch {
repo.updatePosition(position)
}
}
Daniel
05/25/2021, 6:56 PMTash
05/25/2021, 6:57 PMval book: Flow<Book?> = combine(epubUpdates(), positionUpdates()) { Book(...) }
Tash
05/25/2021, 6:58 PMfun books(): Flow<Book> { /** put all the smarts here **/ }
Daniel
05/25/2021, 6:59 PMDaniel
05/25/2021, 7:00 PMTash
05/25/2021, 7:02 PMThe reason that’s not in the repo is some views need a flow of the position, and some views need only an initial positionCould you elaborate?
Daniel
05/25/2021, 7:05 PMDaniel
05/25/2021, 7:06 PMTash
05/25/2021, 7:47 PMTash
05/25/2021, 7:54 PMDaniel
05/25/2021, 8:02 PMTash
05/25/2021, 8:56 PMmutableStateOf
(or Flow
) and others are non-observable. The entire UI still sees only one overall state but the individual Composables can hook into the observable/non-observable fields as needed.Daniel
05/25/2021, 8:57 PM