diff options
Diffstat (limited to 'android/arch/lifecycle/MediatorLiveData.java')
-rw-r--r-- | android/arch/lifecycle/MediatorLiveData.java | 39 |
1 files changed, 3 insertions, 36 deletions
diff --git a/android/arch/lifecycle/MediatorLiveData.java b/android/arch/lifecycle/MediatorLiveData.java index 58647394..672b3a3b 100644 --- a/android/arch/lifecycle/MediatorLiveData.java +++ b/android/arch/lifecycle/MediatorLiveData.java @@ -19,49 +19,16 @@ package android.arch.lifecycle; import android.arch.core.internal.SafeIterableMap; import android.support.annotation.CallSuper; import android.support.annotation.MainThread; -import android.support.annotation.NonNull; import android.support.annotation.Nullable; import java.util.Map; /** - * {@link LiveData} subclass which may observe other {@code LiveData} objects and react on + * {@link LiveData} subclass which may observer other {@code LiveData} objects and react on * {@code OnChanged} events from them. * <p> * This class correctly propagates its active/inactive states down to source {@code LiveData} * objects. - * <p> - * Consider the following scenario: we have 2 instances of {@code LiveData}, let's name them - * {@code liveData1} and {@code liveData2}, and we want to merge their emissions in one object: - * {@code liveDataMerger}. Then, {@code liveData1} and {@code liveData2} will become sources for - * the {@code MediatorLiveData liveDataMerger} and every time {@code onChanged} callback - * is called for either of them, we set a new value in {@code liveDataMerger}. - * - * <pre> - * LiveData<Integer> liveData1 = ...; - * LiveData<Integer> liveData2 = ...; - * - * MediatorLiveData<Integer> liveDataMerger = new MediatorLiveData<>(); - * liveDataMerger.addSource(liveData1, value -> liveDataMerger.setValue(value)); - * liveDataMerger.addSource(liveData2, value -> liveDataMerger.setValue(value)); - * </pre> - * <p> - * Let's consider that we only want 10 values emitted by {@code liveData1}, to be - * merged in the {@code liveDataMerger}. Then, after 10 values, we can stop listening to {@code - * liveData1} and remove it as a source. - * <pre> - * liveDataMerger.addSource(liveData1, new Observer<Integer>() { - * private int count = 1; - * - * {@literal @}Override public void onChanged(@Nullable Integer s) { - * count++; - * liveDataMerger.setValue(s); - * if (count > 10) { - * liveDataMerger.removeSource(liveData1); - * } - * } - * }); - * </pre> * * @param <T> The type of data hold by this instance */ @@ -82,7 +49,7 @@ public class MediatorLiveData<T> extends MutableLiveData<T> { * @param <S> The type of data hold by {@code source} LiveData */ @MainThread - public <S> void addSource(@NonNull LiveData<S> source, @NonNull Observer<S> onChanged) { + public <S> void addSource(LiveData<S> source, Observer<S> onChanged) { Source<S> e = new Source<>(source, onChanged); Source<?> existing = mSources.putIfAbsent(source, e); if (existing != null && existing.mObserver != onChanged) { @@ -104,7 +71,7 @@ public class MediatorLiveData<T> extends MutableLiveData<T> { * @param <S> the type of data hold by {@code source} LiveData */ @MainThread - public <S> void removeSource(@NonNull LiveData<S> toRemote) { + public <S> void removeSource(LiveData<S> toRemote) { Source<?> source = mSources.remove(toRemote); if (source != null) { source.unplug(); |