hadilq/LiveEvent

Value set before observing question

andro-jedi opened this issue · 3 comments

Do we need to resend value that was set before we observe liveevent?

For example we set value to our live data and only after this we subscribe with observer.
With current implementation we will not receive current value to our observer

val event = LiveEvent<Boolean>()
event.value = true
event.observe(this, Observer {
           // no trigger
})

If there is no support for Voids we can check value in observe function and send it to newly subscribed observers if it's not null.

Sorry for being late. As you said this class is not supporting such behavior, because it cannot keep track of classes that observed the value. My assumption is that we observe the live data on onCreate method, so we always have an observer to trigger!

Hmm could we add something to the readme about this? I also expected it to act like LiveData and keep the last change to send to new observers. Great little lib by the way. A missing piece for sharing viewmodels.

Thank you @CarsonRedeye. Actually, the name of this class is LiveEvent, if we want to keep the data for new observers then we could use LiveData as well. The point for this class is to not keeping the last change. If you want to keep it you can use a LiveData instance beside the LiveEvent instance. However, creating a PR is always welcome to either modifying README file or implementing the class you think is useful.