Skip to content

Commit 04b8684

Browse files
author
Horácio Comé
committed
making snapshot listener nullable to preserve original firestore API behavior
1 parent 0aada23 commit 04b8684

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

fireflow/src/main/java/io/github/horaciocome1/fireflow/Extensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import kotlin.coroutines.CoroutineContext
3232
inline fun <reified T> Query.asFlow(
3333
coroutineContext: CoroutineContext = Dispatchers.IO,
3434
): Flow<MutableList<T>> = snapshotAsFlow(coroutineContext).map {
35-
it.toObjects(T::class.java)
35+
it?.toObjects(T::class.java) ?: mutableListOf()
3636
}
3737

3838
/**
@@ -43,5 +43,5 @@ inline fun <reified T> Query.asFlow(
4343
inline fun <reified T> DocumentReference.asFlow(
4444
coroutineContext: CoroutineContext = Dispatchers.IO,
4545
): Flow<T?> = snapshotAsFlow(coroutineContext).map {
46-
it.toObject(T::class.java)
46+
it?.toObject(T::class.java)
4747
}

fireflow/src/main/java/io/github/horaciocome1/fireflow/Snapshot.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ import kotlin.coroutines.CoroutineContext
3838
@ExperimentalCoroutinesApi
3939
fun DocumentReference.snapshotAsFlow(
4040
coroutineContext: CoroutineContext = Dispatchers.IO,
41-
): Flow<DocumentSnapshot> = callbackFlow {
41+
): Flow<DocumentSnapshot?> = callbackFlow {
4242
try {
4343
val listener = EventListener<DocumentSnapshot> { snapshot, error ->
44-
if (error != null || snapshot == null) {
44+
if (error != null) {
4545
close(error)
4646
return@EventListener
4747
}
@@ -63,10 +63,10 @@ fun DocumentReference.snapshotAsFlow(
6363
@ExperimentalCoroutinesApi
6464
fun Query.snapshotAsFlow(
6565
coroutineContext: CoroutineContext = Dispatchers.IO,
66-
): Flow<QuerySnapshot> = callbackFlow {
66+
): Flow<QuerySnapshot?> = callbackFlow {
6767
try {
6868
val listener = EventListener<QuerySnapshot> { snapshot, error ->
69-
if (error != null || snapshot == null) {
69+
if (error != null) {
7070
close(error)
7171
return@EventListener
7272
}

0 commit comments

Comments
 (0)