kioba
06/24/2019, 4:32 PMclass ChatViewModel(private val messageManager: MessageManager): ViewModel {
private val binder: PublishProcessor<MessageEvent> = PublishProcessor.create()
private val state =
binder
.flatMap{ messageManager.editMessage(it.messageId, it.newText) }
// #1
.replay(1)
.autoConnect(0)
fun editMessageClick(messageId: Long, newText: String) {
binder.onNext(MessageEvent(messageId, newText))
}
override fun state(): Observable = state
}
class MessageManager {
fun editMessage(messageId, newText) =
database.update(messageId, newText, State.SENDING)
.flatMap { apiClient.editMessage(...)}
.flatMap { database.update(messageId, newText, State.SENT )}
.asEvents()
}
data class MessageEvent(val messageId: Long, val newText: String)
ursus
06/25/2019, 5:05 PMstate
, your subscrption would I presume be in the ui, and it would not stop because of the autocnnect, but you still need to dispose of this, otherwise you create leaks afaik?)kioba
06/26/2019, 8:43 AMursus
06/26/2019, 3:18 PMkioba
06/27/2019, 9:27 AMursus
06/27/2019, 12:42 PMkioba
06/27/2019, 1:46 PMwell I think the issue is the same, how do you update the store?As we described a hot observable receives events, reduce the events to state (map of elements) I would suggest a regular Unit function for propagating events.
if you have multiple edits going on, what do you emit, would you have multiple hot streams or a single one with a map of ongoing events?Map of ongoing events. You can always filter these events if you need to.
trouble is how to keep these mutations manager or appscopeddependency injection?
ursus
06/27/2019, 3:39 PM