DataSnapShot.value == null
mgoodwin14 opened this issue · 0 comments
mgoodwin14 commented
given this sample(in kotlin):
fun getIsLiked(query: DatabaseQuery): Maybe<Boolean>{
return RxFirebaseDatabase.observeSingleValueEvent(query,
{snapShot -> (snapShot.value as Long).toInt() == 1})
}
I had an issue where the value was null. (which happens if it isn't in firebase)
I wasn't able to find a work around using this function with a mapper.
Instead, I used the single parameter call and did:
.filter( { snapShot -> snapShot.exists() } )
Not sure if this is by design or not but I don't think an empty DataSnapShot should be emitted?
My suggestion change source from
public void onDataChange(DataSnapshot dataSnapshot) {
emitter.onSuccess(dataSnapshot);
emitter.onComplete();
}
to
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists())
emitter.onSuccess(dataSnapshot);
emitter.onComplete();
}
Just my 2 cents.
P.S. great library, found this to be most helpful.