Whenever you call `.observe()` on LiveData, the Observer receives the last value of that LiveData. This may be useful in some cases, but not in mine. 

1. **Whenever I call `.observe()`, I want the Observer to receive only future LiveData changes, but not the value it holds when `.observe()` is called.**
2. **I may have more than one Observer for a LiveData instance. I want them all to receive LiveData updates when they happen.**
3. **I want each LiveData update to be consumed only once by each Observer.** I think is just a re-phrasing of the first requirement, but my head is spinning already and I'm not sure about it.

---

While googling this problem, I came upon two common approaches: 

1. Wrap the data in an `LiveData<SingleEvent<Data>>` and check in this `SingleEvent` class if it was already consumed.
2. Extend `MediatorLiveData` and use a look-up-map if the Observer already got the Event

Examples for these approaches can be found here:
<https://gist.github.com/JoseAlcerreca/5b661f1800e1e654f07cc54fe87441af#gistcomment-2783677>
<https://gist.github.com/hadilq/f095120348a6a14251a02aca329f1845#file-liveevent-kt>
<https://gist.github.com/JoseAlcerreca/5b661f1800e1e654f07cc54fe87441af#file-event-kt>

Unfortunately none of these examples solves *all* my requirements. Most of the time, the problem is that any new Observer still receives the last LiveData value upon subscribing. That means that a Snackbar which was already shown is displayed again and again whenever the user navigates between screens.

---

To give you some insights what I am talking about / what I am coding about:

I am following the LiveData MVVM design of the Android Architecture Componentns:

* 2 ListFragment are showing a list of entries.
* They are using 2 instances of the same ViewModel class to observe UI-related LiveData.
* The user can delete an entry in such a ListFragment. The deletion is done by the ViewModel calling `Repository.delete()`
* The ViewModel observes the Repository for `RepositoryEvents`.

So when the deletion is done, the Repository informs the ViewModel about it and the ViewModel inform the ListFragment about it.

Now, when the user switches to the second ListFragment the following happens: 

* The second Fragment gets created and calls `.observe()` on its ViewModel
* The ViewModel gets created and calls `.observe()` on the Repository
* The Repository sends its current `RepositoryEvent` to the ViewModel
* The ViewModel send the according UI Event to the Fragment
* The Fragment shows a confirmation Snackbar for a deletion that happened somewhere else.

Heres some simplified code:

**Fragment:**

```
viewModel.dataEvents.observe(viewLifecycleOwner, Observer { showSnackbar() })
viewModel.deleteEntry()

```

**ViewModel:** 

```
val dataEvents: LiveData<EntryListEvent> = Transformations.switchMap(repository.events, ::handleRepoEvent)
fun deleteEntry() = repository.deleteEntry()
private fun handleRepoEvent(event: RepositoryEvent): LiveData<EntryListEvent> {
    // convert the repository event to an UI event
}

```

**Repository:** 

```
private val _events = MutableLiveData<RepositoryEvent>()
val events: LiveData<RepositoryEvent>
    get() = _events

fun deleteEntry() {
    // delete it from database
    _events.postValue(RepositoryEvent.OnDeleteSuccess)
}

```