UnPeek-LiveData icon indicating copy to clipboard operation
UnPeek-LiveData copied to clipboard

LiveData 数据倒灌:别问,问就是不可预期 - Perfect alternative to SingleLiveEvent, supporting multiple observers.

Results 8 UnPeek-LiveData issues
Sort by recently updated
recently updated
newest added

UnPeekLiveData 有个不适用的场景:不能利用官方的 map、filter 等方法进行变换,变换后变为了普通的 LiveData 解决方案详见 [livedata-no-sticky](https://github.com/groooooomit/livedata-no-sticky)

精华

## 如有 bug,请另外 new 一个 issue ⚠️⚠️⚠️ ## 本项目开 issue 规范: 1. 有任何 bug 都欢迎及时开 issue,我看到后予以处理。 2. 如有使用上的疑问,请先认真阅读 Readme 和源码 sample,在没有找到答案后,另外开 issue。 3. 如开 issue 是为了发表个人见解,请务必 客观、具体、严谨;严禁草率、乱入、带节奏: ## 务必注明观点所对应的场景,并附上完整可复现的代码, ##...

提问须知

public class EventMutableLiveData extends LiveData { private final AtomicInteger currentVersion = new AtomicInteger(-1); /** * 这个标志主要是是否忽略最新值, observe(@NonNull @NotNull LifecycleOwner owner, @NonNull @NotNull Observer

精华

当使用 removeObservers(@NonNull final LifecycleOwner owner) 的时候,回调过来已经是ObserverWrapper,又封装了一层,导致没有删除掉。应该是加一个判断,判断回调当前类是否已经是ObserverWrapper的类型,不是才需要包装删除,那时候没有测试想到。 @Override public void removeObserver(@NonNull @NotNull Observer

精华

observerStateMap 这个map 感觉没有存在的必要,可以更加精简 private final ConcurrentHashMap

精华

如题,反正LiveData已经通过mObservers持有了Observer,再多一次持有也无所谓吧? ProtectedUnPeekLiveData重写removeObserver()清理就好了嘛。

精华

目的为了降低创建时代码的耦合性,后续可以考虑添加一个“asResult”方法。 扩展方法: ![image](https://user-images.githubusercontent.com/49141931/191309627-6e4b73b3-6822-481b-937b-be4b9ce95b1f.png) 使用: ![image](https://user-images.githubusercontent.com/49141931/191309941-33c3d17d-c4a4-4304-a1b7-c470d777534e.png)

精华

举的例子,明明是完全不理解livedata会在observe时会回调已有数据的onchange,以及所谓共享ViewModel为了在fragment之间公用livedata,然后共用的数据在fragment退出不清理(根因),说得好像是livedata本身就有问题。 粘性这种大家都知道的概念,偏要说新手不知道,硬是写几篇长篇大论解释你的所谓数据倒灌。 就在livedata。obseverse加个版本记录,设置的时候更新版本,通知onchange前判断数据不是observe之前的版本你写了7个版本的代码,花这么多时间讲解,你这是在故意装神弄鬼骗星!!!