OG
06/30/2020, 1:37 AMgildor
06/30/2020, 1:42 AMstill doesn’t fit with MVI/MVVM pattern of emitting a single state from your VM or w/eBecause navigation is event, it’s not state, there is no real solution, even with completely immutable ViewModel/State (like in unidirectional flow) you still have events to update state, so you have to emit some event in MVI it’s just some event (aka intent) to reducer to mutate state
mon
06/30/2020, 3:27 AMMiguel Coleto
06/30/2020, 6:24 AMpedro
06/30/2020, 10:05 AMOG
06/30/2020, 3:03 PMpedro
06/30/2020, 3:07 PMAnd this 100% looks horrific to me.I agree, that’s why I don’t send events to the reducer 😉 There are different alternatives to address that. I’d argue there’s no perfect solution. But here’s how two libraries address that: https://badoo.github.io/MVICore/features/news/ https://github.com/babylonhealth/orbit-mvi/ (Those links mention them and have different approaches)
OG
06/30/2020, 3:14 PMArkadii Ivanov
06/30/2020, 6:25 PMOG
06/30/2020, 11:14 PMgildor
07/01/2020, 1:29 AMtschuchort
07/01/2020, 1:23 PMOG
07/02/2020, 3:04 AMViktor Petrovski
07/05/2020, 5:46 AMConsumableData
. You can access the data by calling consumeData() and after that it is set to null and the data is consumed so you can’t access it again.
Another approach I adjusted is the SIngleLiveEvent for multiple observers:
class SingleLiveEvent<T> : MutableLiveData<T>() {
private val pending = AtomicBoolean(false)
private val observers = mutableSetOf<Observer<in T>>()
private val internalObserver = Observer<T> { t ->
if (pending.compareAndSet(true, false)) {
observers.forEach {
it.onChanged(t)
}
}
}
@MainThread
override fun observe(owner: LifecycleOwner, observer: Observer<in T>) {
observers.add(observer)
super.observe(owner, internalObserver)
}
override fun removeObservers(owner: LifecycleOwner) {
observers.clear()
super.removeObservers(owner)
}
override fun removeObserver(observer: Observer<in T>) {
observers.remove(observer)
super.removeObserver(observer)
}
@MainThread
override fun setValue(t: T) {
pending.set(true)
super.setValue(t)
}
}
Hope it helps 🤞OG
07/05/2020, 2:49 PM