objectbox / objectbox/objectbox-java

Enable DataObserver to observe T?, not only List<T>

オープン
#986 コメント 2 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

enhancement
主要言語
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

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず Query.subscribe、DataObserver、SubscriptionBuilder を調べて、現在の subscription が List の結果を公開している理由を理解し、次にその動作を Query.findFirst() および Kotlin の asFlow の例と比較します。既存の複数結果の監視動作を維持しながら、単一の nullable な T を監視する方法が文書化されて提供されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java, kotlin
領域
database
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。