Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android:
licenses:
- android-sdk-license-.+
script:
- "./gradlew check --stacktrace"
- "./gradlew clean cleanBuildCache check --stacktrace"
after_success:
- tools/release/deploy_snapshot.sh
- bash <(curl -s https://codecov.io/bash)
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ Let's start by looking at what a fully configured Store looks like. We will then
```kotlin
StoreBuilder
.from(
fetcher = nonFlowValueFetcher { api.fetchSubreddit(it, "10").data.children.map(::toPosts) },
sourceOfTruth = SourceOfTruth.from(
fetcher = Fetcher.of { api.fetchSubreddit(it, "10").data.children.map(::toPosts) },
sourceOfTruth = SourceOfTruth.of(
reader = db.postDao()::loadPosts,
writer = db.postDao()::insertPosts,
delete = db.postDao()::clearFeed,
Expand All @@ -81,7 +81,7 @@ You create a Store using a builder. The only requirement is to include a `Fetche

```kotlin
val store = StoreBuilder
.from(valueFetcher { articleId -> api.getArticle(articleId) }) // api returns Flow<Article>
.from(Fetcher.ofFlow { articleId -> api.getArticle(articleId) }) // api returns Flow<Article>
.build()
```

Expand Down Expand Up @@ -186,8 +186,8 @@ allows you to create offline first applications that can be used without an acti
```kotlin
StoreBuilder
.from(
fetcher = nonFlowValueFetcher { api.fetchSubreddit(it, "10").data.children.map(::toPosts) },
sourceOfTruth = SourceOfTruth.from(
fetcher = Fetcher.of { api.fetchSubreddit(it, "10").data.children.map(::toPosts) },
sourceOfTruth = SourceOfTruth.of(
reader = db.postDao()::loadPosts,
writer = db.postDao()::insertPosts,
delete = db.postDao()::clearFeed,
Expand Down Expand Up @@ -215,8 +215,8 @@ You can configure in-memory cache with the `MemoryPolicy`:
```kotlin
StoreBuilder
.from(
fetcher = nonFlowValueFetcher { api.fetchSubreddit(it, "10").data.children.map(::toPosts) },
sourceOfTruth = SourceOfTruth.from(
fetcher = Fetcher.of { api.fetchSubreddit(it, "10").data.children.map(::toPosts) },
sourceOfTruth = SourceOfTruth.of(
reader = db.postDao()::loadPosts,
writer = db.postDao()::insertPosts,
delete = db.postDao()::clearFeed,
Expand Down Expand Up @@ -244,8 +244,10 @@ You can delete a specific entry by key from a store, or clear all entries in a s

```kotlin
val store = StoreBuilder
.from(nonFlowValueFetcher { api.fetchData(key) })
.build()
.from(
fetcher = Fetcher.of { key: String ->
api.fetchData(key)
}).build()
```

The following will clear the entry associated with the key from the in-memory cache:
Expand All @@ -267,8 +269,8 @@ When store has a sourceOfTruth, you'll need to provide the `delete` and `deleteA
```kotlin
StoreBuilder
.from(
fetcher = nonFlowValueFetcher { api.fetchData(key) },
sourceOfTruth = SourceOfTruth.from(
fetcher = Fetcher.of { api.fetchData(key) },
sourceOfTruth = SourceOfTruth.of(
reader = dao::loadData,
writer = dao::writeData,
delete = dao::clearDataByKey,
Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/com/dropbox/android/sample/Graph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import com.dropbox.android.external.fs3.FileSystemPersister
import com.dropbox.android.external.fs3.PathResolver
import com.dropbox.android.external.fs3.SourcePersisterFactory
import com.dropbox.android.external.fs3.filesystem.FileSystemFactory
import com.dropbox.android.external.store4.Fetcher
import com.dropbox.android.external.store4.StoreBuilder
import com.dropbox.android.external.store4.MemoryPolicy
import com.dropbox.android.external.store4.Persister
import com.dropbox.android.external.store4.Store
import com.dropbox.android.external.store4.SourceOfTruth
import com.dropbox.android.external.store4.legacy.BarCode
import com.dropbox.android.external.store4.nonFlowValueFetcher
import com.squareup.moshi.Moshi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand Down Expand Up @@ -46,10 +46,10 @@ object Graph {
val db = provideRoom(context)
return StoreBuilder
.from(
nonFlowValueFetcher { key: String ->
Fetcher.of { key: String ->
provideRetrofit().fetchSubreddit(key, 10).data.children.map(::toPosts)
},
sourceOfTruth = SourceOfTruth.from(
sourceOfTruth = SourceOfTruth.of(
reader = db.postDao()::loadPosts,
writer = db.postDao()::insertPosts,
delete = db.postDao()::clearFeedBySubredditName,
Expand All @@ -63,11 +63,11 @@ object Graph {
val db = provideRoom(context)
return StoreBuilder
.from<Pair<String, RedditConfig>, List<Post>, List<Post>>(
nonFlowValueFetcher { (query, config) ->
Fetcher.of { (query, config) ->
provideRetrofit().fetchSubreddit(query, config.limit)
.data.children.map(::toPosts)
},
sourceOfTruth = SourceOfTruth.from(
sourceOfTruth = SourceOfTruth.of(
reader = { (query, _) -> db.postDao().loadPosts(query) },
writer = { (query, _), posts -> db.postDao().insertPosts(query, posts) },
delete = { (query, _) -> db.postDao().clearFeedBySubredditName(query) },
Expand Down Expand Up @@ -99,12 +99,12 @@ object Graph {
val adapter = moshi.adapter<RedditConfig>(RedditConfig::class.java)
return StoreBuilder
.from<Unit, RedditConfig, RedditConfig>(
nonFlowValueFetcher {
Fetcher.of {
delay(500)
RedditConfig(10)
},
sourceOfTruth = SourceOfTruth.fromNonFlow(
reader = {
sourceOfTruth = SourceOfTruth.of(
nonFlowReader = {
runCatching {
val source = fileSystemPersister.read(Unit)
source?.let { adapter.fromJson(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.dropbox.android.external.store4.Fetcher
import com.dropbox.android.external.store4.MemoryPolicy
import com.dropbox.android.external.store4.StoreBuilder
import com.dropbox.android.external.store4.StoreRequest
import com.dropbox.android.external.store4.fresh
import com.dropbox.android.external.store4.get
import com.dropbox.android.external.store4.nonFlowValueFetcher
import com.dropbox.android.sample.R
import kotlinx.android.synthetic.main.fragment_stream.*
import kotlinx.coroutines.CoroutineScope
Expand Down Expand Up @@ -51,7 +51,7 @@ class StreamFragment : Fragment(), CoroutineScope {
var counter = 0

val store = StoreBuilder
.from(nonFlowValueFetcher { key: Int ->
.from(Fetcher.of { key: Int ->
(key * 1000 + counter++).also { delay(1_000) }
})
.cachePolicy(
Expand Down
1 change: 1 addition & 0 deletions buildsystem/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ext.versions = [
ktlint : '0.36.0',

// Plugins
androidGradlePlugin : '4.0.0',
androidGradlePlugin : '4.0.0-beta05',
dokkaGradlePlugin : '0.10.0',
ktlintGradle : '9.1.1',
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-milestone-1-bin.zip
16 changes: 8 additions & 8 deletions store-rx2/api/store-rx2.api
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
public final class com/dropbox/store/rx2/RxFetcherKt {
public static final fun flowableFetcher (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
public static final fun flowableValueFetcher (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
public static final fun singleFetcher (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
public static final fun singleValueFetcher (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function1;
public static final fun ofFlowable (Lcom/dropbox/android/external/store4/Fetcher$Companion;Lkotlin/jvm/functions/Function1;)Lcom/dropbox/android/external/store4/Fetcher;
public static final fun ofResultFlowable (Lcom/dropbox/android/external/store4/Fetcher$Companion;Lkotlin/jvm/functions/Function1;)Lcom/dropbox/android/external/store4/Fetcher;
public static final fun ofResultSingle (Lcom/dropbox/android/external/store4/Fetcher$Companion;Lkotlin/jvm/functions/Function1;)Lcom/dropbox/android/external/store4/Fetcher;
public static final fun ofSingle (Lcom/dropbox/android/external/store4/Fetcher$Companion;Lkotlin/jvm/functions/Function1;)Lcom/dropbox/android/external/store4/Fetcher;
}

public final class com/dropbox/store/rx2/RxSourceOfTruthKt {
public static final fun fromFlowable (Lcom/dropbox/android/external/store4/SourceOfTruth$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Lcom/dropbox/android/external/store4/SourceOfTruth;
public static synthetic fun fromFlowable$default (Lcom/dropbox/android/external/store4/SourceOfTruth$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lcom/dropbox/android/external/store4/SourceOfTruth;
public static final fun fromMaybe (Lcom/dropbox/android/external/store4/SourceOfTruth$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Lcom/dropbox/android/external/store4/SourceOfTruth;
public static synthetic fun fromMaybe$default (Lcom/dropbox/android/external/store4/SourceOfTruth$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lcom/dropbox/android/external/store4/SourceOfTruth;
public static final fun ofFlowable (Lcom/dropbox/android/external/store4/SourceOfTruth$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Lcom/dropbox/android/external/store4/SourceOfTruth;
public static synthetic fun ofFlowable$default (Lcom/dropbox/android/external/store4/SourceOfTruth$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lcom/dropbox/android/external/store4/SourceOfTruth;
public static final fun ofMaybe (Lcom/dropbox/android/external/store4/SourceOfTruth$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Lcom/dropbox/android/external/store4/SourceOfTruth;
public static synthetic fun ofMaybe$default (Lcom/dropbox/android/external/store4/SourceOfTruth$Companion;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lcom/dropbox/android/external/store4/SourceOfTruth;
}

public final class com/dropbox/store/rx2/RxStoreBuilderKt {
Expand Down
17 changes: 8 additions & 9 deletions store-rx2/src/main/kotlin/com/dropbox/store/rx2/RxFetcher.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.dropbox.store.rx2
import com.dropbox.android.external.store4.Fetcher
import com.dropbox.android.external.store4.FetcherResult
import com.dropbox.android.external.store4.Store
import com.dropbox.android.external.store4.valueFetcher
import io.reactivex.Flowable
import io.reactivex.Single
import kotlinx.coroutines.reactive.asFlow
Expand All @@ -19,9 +18,9 @@ import kotlinx.coroutines.reactive.asFlow
*
* @param flowableFactory a factory for a [Flowable] source of network records.
*/
fun <Key : Any, Output : Any> flowableFetcher(
fun <Key : Any, Output : Any> Fetcher.Companion.ofResultFlowable(
flowableFactory: (key: Key) -> Flowable<FetcherResult<Output>>
): Fetcher<Key, Output> = { key: Key -> flowableFactory(key).asFlow() }
): Fetcher<Key, Output> = ofResultFlow { key: Key -> flowableFactory(key).asFlow() }

/**
* "Creates" a [Fetcher] from a [singleFactory].
Expand All @@ -34,9 +33,9 @@ fun <Key : Any, Output : Any> flowableFetcher(
*
* @param singleFactory a factory for a [Single] source of network records.
*/
fun <Key : Any, Output : Any> singleFetcher(
fun <Key : Any, Output : Any> Fetcher.Companion.ofResultSingle(
singleFactory: (key: Key) -> Single<FetcherResult<Output>>
): Fetcher<Key, Output> = { key: Key -> singleFactory(key).toFlowable().asFlow() }
): Fetcher<Key, Output> = ofResultFlowable { key: Key -> singleFactory(key).toFlowable() }

/**
* "Creates" a [Fetcher] from a [flowableFactory] and translate the results to a [FetcherResult].
Expand All @@ -50,9 +49,9 @@ fun <Key : Any, Output : Any> singleFetcher(
*
* @param flowFactory a factory for a [Flowable] source of network records.
*/
fun <Key : Any, Output : Any> flowableValueFetcher(
fun <Key : Any, Output : Any> Fetcher.Companion.ofFlowable(
flowableFactory: (key: Key) -> Flowable<Output>
): Fetcher<Key, Output> = valueFetcher { key: Key -> flowableFactory(key).asFlow() }
): Fetcher<Key, Output> = ofFlow { key: Key -> flowableFactory(key).asFlow() }

/**
* Creates a new [Fetcher] from a [singleFactory] and translate the results to a [FetcherResult].
Expand All @@ -66,6 +65,6 @@ fun <Key : Any, Output : Any> flowableValueFetcher(
*
* @param singleFactory a factory for a [Single] source of network records.
*/
fun <Key : Any, Output : Any> singleValueFetcher(
fun <Key : Any, Output : Any> Fetcher.Companion.ofSingle(
singleFactory: (key: Key) -> Single<Output>
): Fetcher<Key, Output> = flowableValueFetcher { key: Key -> singleFactory(key).toFlowable() }
): Fetcher<Key, Output> = ofFlowable { key: Key -> singleFactory(key).toFlowable() }
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import kotlinx.coroutines.rx2.await
* @param deleteAll function for deleting all records in the source of truth
*
*/
fun <Key : Any, Input : Any, Output : Any> SourceOfTruth.Companion.fromMaybe(
fun <Key : Any, Input : Any, Output : Any> SourceOfTruth.Companion.ofMaybe(
reader: (Key) -> Maybe<Output>,
writer: (Key, Input) -> Completable,
delete: ((Key) -> Completable)? = null,
Expand All @@ -26,8 +26,8 @@ fun <Key : Any, Input : Any, Output : Any> SourceOfTruth.Companion.fromMaybe(
val deleteFun: (suspend (Key) -> Unit)? =
if (delete != null) { key -> delete(key).await() } else null
val deleteAllFun: (suspend () -> Unit)? = deleteAll?.let { { deleteAll().await() } }
return fromNonFlow(
reader = { key -> reader.invoke(key).await() },
return of(
nonFlowReader = { key -> reader.invoke(key).await() },
writer = { key, output -> writer.invoke(key, output).await() },
delete = deleteFun,
deleteAll = deleteAllFun
Expand All @@ -44,7 +44,7 @@ fun <Key : Any, Input : Any, Output : Any> SourceOfTruth.Companion.fromMaybe(
* @param deleteAll function for deleting all records in the source of truth
*
*/
fun <Key : Any, Input : Any, Output : Any> SourceOfTruth.Companion.fromFlowable(
fun <Key : Any, Input : Any, Output : Any> SourceOfTruth.Companion.ofFlowable(
reader: (Key) -> Flowable<Output>,
writer: (Key, Input) -> Completable,
delete: ((Key) -> Completable)? = null,
Expand All @@ -53,7 +53,7 @@ fun <Key : Any, Input : Any, Output : Any> SourceOfTruth.Companion.fromFlowable(
val deleteFun: (suspend (Key) -> Unit)? =
if (delete != null) { key -> delete(key).await() } else null
val deleteAllFun: (suspend () -> Unit)? = deleteAll?.let { { deleteAll().await() } }
return from(
return of(
reader = { key -> reader.invoke(key).asFlow() },
writer = { key, output -> writer.invoke(key, output).await() },
delete = deleteFun,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.dropbox.android.external.store4.ResponseOrigin
import com.dropbox.android.external.store4.StoreBuilder
import com.dropbox.android.external.store4.StoreRequest
import com.dropbox.android.external.store4.StoreResponse
import com.dropbox.store.rx2.singleFetcher
import com.dropbox.store.rx2.ofResultSingle
import com.google.common.truth.Truth.assertThat
import io.reactivex.Single
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -30,7 +30,7 @@ class HotRxSingleStoreTest {
3 to FetcherResult.Data("three-1"),
3 to FetcherResult.Data("three-2")
)
val pipeline = StoreBuilder.from(singleFetcher<Int, String> { fetcher.fetch(it) })
val pipeline = StoreBuilder.from(Fetcher.ofResultSingle<Int, String> { fetcher.fetch(it) })
.scope(testScope)
.build()

Expand Down
Loading