objectbox / objectbox/objectbox-java
Enable DataObserver to observe T?, not only List<T>
Nessuno ha ancora preso questa issue.
- Lingua principale
- Java
- Stelle
- 4.6k
- Fork
- 311
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
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
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da Query.subscribe, DataObserver e SubscriptionBuilder per capire perché le subscription espongono attualmente risultati di tipo List, quindi confronta questo comportamento con Query.findFirst() e l’esempio Kotlin asFlow. Il lavoro è completato quando viene fornito un modo documentato per osservare un singolo T nullable, mantenendo al contempo il comportamento esistente di osservazione di più risultati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java, kotlin
- Ambito
- database
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100