-
Notifications
You must be signed in to change notification settings - Fork 215
Support non exception errors from fetcher #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
1c0da31
Support non exception errors from fetcher
eyalgu 0075ada
revert parital changes to store builder to reduce noise
eyalgu 2fe7b7e
finish off diff
eyalgu 9e3801e
Merge remote-tracking branch 'origin/master' into errors
eyalgu d886e41
Allow to create a FetcherResult.Error without a Throwable. Add tests
eyalgu 47463e6
Add missing funcion and more tests
eyalgu 7279bdf
lint
eyalgu cae8faa
unflake RxFlowableStoreTest
eyalgu cea6e71
try to rename FakeFetcher to FakeRxFetcher to (maybe) solve missing c…
eyalgu 2e1b012
Merge remote-tracking branch 'origin/master' into errors
eyalgu 7bd21db
move SourceOfTruth out of impl package
eyalgu 44a5e15
Merge remote-tracking branch 'origin/master' into errors
eyalgu 03768e6
Rename accidental change of RxStoreBuilder.fromMaybe back to formSingle
eyalgu 81548bb
Introduce Fetcher from #139
eyalgu 3981d37
fix Rx artifact
eyalgu fb7c64d
Merge remote-tracking branch 'origin/master' into errors
eyalgu 738ed50
delete legacy presistor factory
eyalgu 1527bec
fix api file
eyalgu cb50d9c
move fetcher to be a typealias
eyalgu ed9d87f
code review comments + clean up documentation
eyalgu cff04b4
code review comments
eyalgu 3251fbb
Update store/src/main/java/com/dropbox/android/external/store4/Fetche…
eyalgu 5a2df2e
Merge remote-tracking branch 'origin/master' into errors
eyalgu a0edfcf
Revert "Update sample app's build.gradle to refer to the externally r…
eyalgu e883e5d
update releasing.md
eyalgu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ buildscript { | |
| } | ||
|
|
||
| ext.versions = [ | ||
| androidGradlePlugin : '4.0.0-beta01', | ||
| androidGradlePlugin : '3.6.0', | ||
|
||
| kotlin : '1.3.70', | ||
| dokkaGradlePlugin : '0.10.0', | ||
| ktlintGradle : '9.1.1', | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,26 @@ | ||
| public final class com/dropbox/store/rx2/RxFetcherKt { | ||
| public static final fun exceptionAsErrorsFlowable (Lcom/dropbox/android/external/store4/Fetcher$Companion;Lkotlin/jvm/functions/Function1;)Lcom/dropbox/android/external/store4/Fetcher; | ||
| public static final fun exceptionAsErrorsSingle (Lcom/dropbox/android/external/store4/Fetcher$Companion;Lkotlin/jvm/functions/Function1;)Lcom/dropbox/android/external/store4/Fetcher; | ||
| public static final fun fromFlowable (Lcom/dropbox/android/external/store4/Fetcher$Companion;Lkotlin/jvm/functions/Function1;)Lcom/dropbox/android/external/store4/Fetcher; | ||
| public static final fun fromSingle (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 final class com/dropbox/store/rx2/RxStoreBuilderKt { | ||
| public static final fun withScheduler (Lcom/dropbox/android/external/store4/StoreBuilder;Lio/reactivex/Scheduler;)Lcom/dropbox/android/external/store4/StoreBuilder; | ||
| } | ||
|
|
||
| public final class com/dropbox/store/rx2/RxStoreKt { | ||
| public static final fun freshSingle (Lcom/dropbox/android/external/store4/Store;Ljava/lang/Object;)Lio/reactivex/Single; | ||
| public static final fun fromFlowable (Lcom/dropbox/android/external/store4/StoreBuilder$Companion;Lkotlin/jvm/functions/Function1;)Lcom/dropbox/android/external/store4/StoreBuilder; | ||
| public static final fun fromSingle (Lcom/dropbox/android/external/store4/StoreBuilder$Companion;Lkotlin/jvm/functions/Function1;)Lcom/dropbox/android/external/store4/StoreBuilder; | ||
| public static final fun getSingle (Lcom/dropbox/android/external/store4/Store;Ljava/lang/Object;)Lio/reactivex/Single; | ||
| public static final fun observe (Lcom/dropbox/android/external/store4/Store;Lcom/dropbox/android/external/store4/StoreRequest;)Lio/reactivex/Flowable; | ||
| public static final fun observeClear (Lcom/dropbox/android/external/store4/Store;Ljava/lang/Object;)Lio/reactivex/Completable; | ||
| public static final fun observeClearAll (Lcom/dropbox/android/external/store4/Store;)Lio/reactivex/Completable; | ||
| public static final fun withFlowablePersister (Lcom/dropbox/android/external/store4/StoreBuilder;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Lcom/dropbox/android/external/store4/StoreBuilder; | ||
| public static synthetic fun withFlowablePersister$default (Lcom/dropbox/android/external/store4/StoreBuilder;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lcom/dropbox/android/external/store4/StoreBuilder; | ||
| public static final fun withScheduler (Lcom/dropbox/android/external/store4/StoreBuilder;Lio/reactivex/Scheduler;)Lcom/dropbox/android/external/store4/StoreBuilder; | ||
| public static final fun withSinglePersister (Lcom/dropbox/android/external/store4/StoreBuilder;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;)Lcom/dropbox/android/external/store4/StoreBuilder; | ||
| public static synthetic fun withSinglePersister$default (Lcom/dropbox/android/external/store4/StoreBuilder;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function0;ILjava/lang/Object;)Lcom/dropbox/android/external/store4/StoreBuilder; | ||
| } | ||
|
|
72 changes: 72 additions & 0 deletions
72
store-rx2/src/main/kotlin/com/dropbox/store/rx2/RxFetcher.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| 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.exceptionsAsErrors | ||
| import io.reactivex.Flowable | ||
| import io.reactivex.Single | ||
| import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
| import kotlinx.coroutines.FlowPreview | ||
| import kotlinx.coroutines.reactive.asFlow | ||
|
|
||
| /** | ||
| * Creates a new [Fetcher] from a [Flowable] fetcher. | ||
| * | ||
| * Use when creating a [Store] that fetches objects in an websocket-like multiple responses | ||
| * per request protocol. | ||
| * | ||
| * @param fetcher a function for fetching a flow of network records. | ||
| */ | ||
| @FlowPreview | ||
| @ExperimentalCoroutinesApi | ||
| @ExperimentalStdlibApi | ||
| fun <Key : Any, Output : Any> Fetcher.Companion.fromFlowable( | ||
| fetcher: (key: Key) -> Flowable<FetcherResult<Output>> | ||
| ): Fetcher<Key, Output> = from { key: Key -> fetcher(key).asFlow() } | ||
|
|
||
| /** | ||
| * Creates a new [Fetcher] from a [Flowable] fetcher. | ||
| * | ||
| * Use when creating a [Store] that fetches objects in an websocket-like multiple responses | ||
| * per request protocol. | ||
| * | ||
| * @param fetcher a function for fetching a flow of network records. | ||
| */ | ||
| @FlowPreview | ||
| @ExperimentalCoroutinesApi | ||
| @ExperimentalStdlibApi | ||
| fun <Key : Any, Output : Any> Fetcher.Companion.exceptionAsErrorsFlowable( | ||
| fetcher: (key: Key) -> Flowable<Output> | ||
| ): Fetcher<Key, Output> = exceptionsAsErrors { key: Key -> fetcher(key).asFlow() } | ||
|
|
||
| /** | ||
| * Creates a new [Fetcher] from a [Single] fetcher. | ||
| * | ||
| * Use when creating a [Store] that fetches objects from a [Single] source that emits one response | ||
| * | ||
| * @param fetcher a function for fetching a [Single] network response for a [Key] | ||
| */ | ||
| @FlowPreview | ||
| @ExperimentalCoroutinesApi | ||
| @ExperimentalStdlibApi | ||
| fun <Key : Any, Output : Any> Fetcher.Companion.fromSingle( | ||
| fetcher: (key: Key) -> Single<FetcherResult<Output>> | ||
| ): Fetcher<Key, Output> = | ||
| from { key: Key -> fetcher(key).toFlowable().asFlow() } | ||
|
|
||
| /** | ||
| * Creates a new [Fetcher] from a [Single] fetcher. | ||
| * | ||
| * Use when creating a [Store] that fetches objects from a [Single] source that emits one response | ||
| * | ||
| * @param fetcher a function for fetching a [Single] network response for a [Key] | ||
| * @param fetcherTransformer used to translate your fetcher's return value to success value | ||
| * or error in the case that your fetcher does not communicate errors through exceptions | ||
| */ | ||
| @FlowPreview | ||
| @ExperimentalCoroutinesApi | ||
| @ExperimentalStdlibApi | ||
| fun <Key : Any, Output : Any> Fetcher.Companion.exceptionAsErrorsSingle( | ||
| fetcher: (key: Key) -> Single<Output> | ||
| ): Fetcher<Key, Output> = exceptionAsErrorsFlowable { key: Key -> fetcher(key).toFlowable() } |
73 changes: 73 additions & 0 deletions
73
store-rx2/src/main/kotlin/com/dropbox/store/rx2/RxSourceOfTruth.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.dropbox.store.rx2 | ||
|
|
||
| import com.dropbox.android.external.store4.Store | ||
| import com.dropbox.android.external.store4.SourceOfTruth | ||
| import io.reactivex.Completable | ||
| import io.reactivex.Flowable | ||
| import io.reactivex.Maybe | ||
| import io.reactivex.Single | ||
| import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
| import kotlinx.coroutines.FlowPreview | ||
| import kotlinx.coroutines.reactive.asFlow | ||
| import kotlinx.coroutines.rx2.await | ||
|
|
||
| /** | ||
| * Creates a (Non Flow) [Single] source of truth that is accessible via [reader], [writer], | ||
| * [delete], and [deleteAll]. | ||
| * | ||
| * @see com.dropbox.android.external.store4.StoreBuilder.persister | ||
| */ | ||
| @FlowPreview | ||
| @ExperimentalCoroutinesApi | ||
| fun <Key : Any, Input : Any, Output : Any> SourceOfTruth.Companion.fromMaybe( | ||
| reader: (Key) -> Maybe<Output>, | ||
| writer: (Key, Input) -> Completable, | ||
| delete: ((Key) -> Completable)? = null, | ||
| deleteAll: (() -> Completable)? = null | ||
| ): SourceOfTruth<Key, Input, Output> { | ||
| 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() }, | ||
| writer = { key, output -> writer.invoke(key, output).await() }, | ||
| delete = deleteFun, | ||
| deleteAll = deleteAllFun | ||
| ) | ||
| } | ||
|
|
||
| /** | ||
| * Creates a ([Flowable]) source of truth that is accessed via [reader], [writer] and [delete]. | ||
| * | ||
| * For maximal flexibility, [writer]'s record type ([Input]] and [reader]'s record type | ||
| * ([Output]) are not identical. This allows us to read one type of objects from network and | ||
| * transform them to another type when placing them in local storage. | ||
| * | ||
| * A source of truth is usually backed by local storage. It's purpose is to eliminate the need | ||
eyalgu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * for waiting on network update before local modifications are available (via [Store.stream]). | ||
| * | ||
| * @param reader reads records from the source of truth | ||
| * @param writer writes records **coming in from the fetcher (network)** to the source of truth. | ||
| * Writing local user updates to the source of truth via [Store] is currently not supported. | ||
eyalgu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @param delete deletes records in the source of truth for the give key | ||
| * @param deleteAll deletes all records in the source of truth | ||
| * | ||
| */ | ||
| @FlowPreview | ||
| @ExperimentalCoroutinesApi | ||
| fun <Key : Any, Input : Any, Output : Any> SourceOfTruth.Companion.fromFlowable( | ||
| reader: (Key) -> Flowable<Output>, | ||
| writer: (Key, Input) -> Completable, | ||
| delete: ((Key) -> Completable)? = null, | ||
| deleteAll: (() -> Completable)? = null | ||
| ): SourceOfTruth<Key, Input, Output> { | ||
| val deleteFun: (suspend (Key) -> Unit)? = | ||
| if (delete != null) { key -> delete(key).await() } else null | ||
| val deleteAllFun: (suspend () -> Unit)? = deleteAll?.let { { deleteAll().await() } } | ||
| return from( | ||
| reader = { key -> reader.invoke(key).asFlow() }, | ||
| writer = { key, output -> writer.invoke(key, output).await() }, | ||
| delete = deleteFun, | ||
| deleteAll = deleteAllFun | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.