Is it possible to prevent LiveData
receive the last value when start observing?
I am considering to use LiveData
as events.
For example eve
There is no reason to use LiveData as something that it is not. If you need a separate behavior (something that doesn't retain the previous value), then you should use a component that doesn't retain the previous value -- instead of hacking around it ("remembering" that it had emitted and then forgetting to emit, etc.)
You can add event-emitter
library:
implementation 'com.github.Zhuinden:live-event:1.1.0'
from Jitpack: maven { url "https://jitpack.io" }
Then you can do
private val eventEmitter = EventEmitter()
val controllerEvents: EventSource = eventEmitter
and
controllerEvents.observe(viewLifecycleOwner) { event: WordController.Events ->
when (event) {
is WordController.Events.NewWordAdded -> showToast("Added ${event.word}")
}.safe()
}