Skip to content

Commit

Permalink
Add Rx returning equivalents of get and fetch convenience functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mezpahlan committed Feb 23, 2020
1 parent 3c93b24 commit bba706b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions store-rx2/src/main/kotlin/com/dropbox/store/rx2/RxStore.kt
Expand Up @@ -5,6 +5,8 @@ import com.dropbox.android.external.store4.Store
import com.dropbox.android.external.store4.StoreBuilder
import com.dropbox.android.external.store4.StoreRequest
import com.dropbox.android.external.store4.StoreResponse
import com.dropbox.android.external.store4.fresh
import com.dropbox.android.external.store4.get
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.Maybe
Expand All @@ -19,6 +21,7 @@ import kotlinx.coroutines.rx2.asCoroutineDispatcher
import kotlinx.coroutines.rx2.asFlowable
import kotlinx.coroutines.rx2.await
import kotlinx.coroutines.rx2.rxCompletable
import kotlinx.coroutines.rx2.rxSingle

/**
* Return a flow for the given key
Expand Down Expand Up @@ -147,3 +150,13 @@ fun <Key : Any, Output : Any, NewOutput : Any> StoreBuilder<Key, Output>.withFlo
deleteAll = deleteAllFun
)
}

/**
* Helper factory that will return data as a [Single] for [key] if it is cached otherwise will return fresh/network data (updating your caches)
*/
fun <Key : Any, Output : Any> Store<Key, Output>.observeGet(key: Key) = rxSingle { this@observeGet.get(key) }

/**
* Helper factory that will return fresh data as a [Single] for [key] while updating your caches
*/
fun <Key : Any, Output : Any> Store<Key, Output>.observeFresh(key: Key) = rxSingle { this@observeFresh.fresh(key) }

0 comments on commit bba706b

Please sign in to comment.