objectbox / objectbox/objectbox-java
Enable DataObserver to observe T?, not only List<T>
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 4.6k
- 派生
- 311
- PR 合并指标
- 30 天内没有已合并 PR
描述
I came across the DataObservers today and noticed, that when you call subscribe on a Query<T>, you will end in a List<T> as result which in my opinion is not what you want, e.g. if you want to find an entity by its id BUT also want to track the changes of this object, you would normally do this: boxStore.boxFor(T::class.java).query {}.findFirst() which would result in a T? result type. Now when i also want to track changes here, i wrap it in a flow (i use kotlin) like this:
@ExperimentalCoroutinesApi
fun <T> Query<T>.asFlow() = callbackFlow {
val subscription =
this@asFlow.subscribe()
.onError { cancel("Database error", it) }
.observer { data -> offer(data) }
awaitClose { subscription.cancel() }
}
Suddenly i have to deal with a List<T> due to the fact, that the SubscriptionBuilder returns a SubscriptionBuilder<List<T>>.
Please add a more precise way to differ between single and multiple values. Currently i need to implement workarounds for this, but that should be a standard behaviour
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从 Query.subscribe、DataObserver 和 SubscriptionBuilder 入手,了解为什么 subscription 目前会暴露 List 结果,然后将该行为与 Query.findFirst() 和 Kotlin asFlow 示例进行比较。当提供一种有文档说明的方式来观察单个 nullable T,同时保留现有的多结果观察行为时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java, kotlin
- 领域
- database
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 38/100