hadilq/LiveEvent

Multiple instances of observer added if Observe or ObserveForever is called multiple times

rcrosbie-avaya opened this issue · 2 comments

If LiveEvent.observe or LiveEvent.observeForever is called multiple times, it will add the same observer multiple times. This is because ObserverWrapper is added around the observer and this negates the usefulness of having the ArraySet of observers since a unique entry is added each time.

data.observeForever(dataObserver)
data.observeForever(dataObserver)
data.observeForever(dataObserver)

data.postValue(value)

This results in dataObserver being notified 3 times. When using typical LiveData, adding the same observer (perhaps accidently) multiple times would not be an issue.

@rcrosbie-avaya does #40 make sense?

IMO, it's okay, so I just merged it.