-
Notifications
You must be signed in to change notification settings - Fork 215
Yigit/move fetcher factories to fetcher #168
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
Conversation
store/src/main/java/com/dropbox/android/external/store4/Fetcher.kt
Outdated
Show resolved
Hide resolved
store/src/main/java/com/dropbox/android/external/store4/Fetcher.kt
Outdated
Show resolved
Hide resolved
Fetcher factories were global methods, which made them hard to discover since IDE cannot easily auto-complete. This PR moves them into the companion of Fetcher while also making Fetcher a real interface instead of a typealias. Even though it is a bit more code for the developer, now they can easily discover how to create a Fetcher by typing Fetcher. Fixes: #167
Create Fetcher.fromFlow for the flowing version. Rename both SourceOfTruth builder methods to . Rely on param names to disambiguate
|
pushed another attempt. now SoT has
The name for the flowable reader in I'm still not super happy but idk what to do and i really think we should avoid the global fetcher builders as they are hard to discover. So I strongly believe we need a solution, i'm not super confident this is it. |
f90cf5d to
9a56e8e
Compare
What are your thought about making One the one hand using |
store/src/main/java/com/dropbox/android/external/store4/Fetcher.kt
Outdated
Show resolved
Hide resolved
store/src/main/java/com/dropbox/android/external/store4/Fetcher.kt
Outdated
Show resolved
Hide resolved
| * @param deleteAll function for deleting all records in the source of truth | ||
| */ | ||
| fun <Key : Any, Input : Any, Output : Any> fromNonFlow( | ||
| fun <Key : Any, Input : Any, Output : Any> from( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After reading through your diff and thinking more, I think that your original approach was right - lets use the names to point people to the most common defaults and the the RTFM if they need something different. In this case I'm landing on the side that the confusion of having name overload with different parameter names outweighs the consistency benefits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to make sure i understand correctly, you mean keep SoT methods as from for both cases? (like in this CL?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no. I've come around to you're original approach of naming the SoT methods from and fromNonFlow Overload separation by named properties seems very subtle. It is what you would do in Swift, but there the names are mandatory, not optional.
i was thinking the most common case should have the best name hence i thought |
We should probably get rid of StoreBuilder.from and make it Store.builder()
README.md
Outdated
| reader = db.postDao()::loadPosts, | ||
| fetcher = Fetcher.of { api.fetchSubreddit(it, "10").data.children.map(::toPosts) }, | ||
| sourceOfTruth = SourceOfTrue.of( | ||
| flowReader = db.postDao()::loadPosts, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not sure how discoverable it is to use parameter names do distinguish between the 2 functions. what happens if you call it without parameter names?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without names this does work:
sourceOfTruth = SourceOfTruth.of(
db.postDao()::loadPosts,
db.postDao()::insertPosts,
db.postDao()::clearFeedBySubredditName,
db.postDao()::clearAllFeeds
)
While this doesn't:
sourceOfTruth = SourceOfTruth.of(
{
db.postDao().loadPosts(it)
},
db.postDao()::insertPosts,
db.postDao()::clearFeedBySubredditName,
db.postDao()::clearAllFeeds
)
re-naming: part of the challange is that this receives 4 methods, only 1 parameter's type is different so ofFlow wouldn't look very good imo either :/.
store/src/main/java/com/dropbox/android/external/store4/Fetcher.kt
Outdated
Show resolved
Hide resolved
store/src/main/java/com/dropbox/android/external/store4/Fetcher.kt
Outdated
Show resolved
Hide resolved
| reader: (Key) -> Flow<Output?>, | ||
| @JvmName("ofFlow") | ||
| fun <Key : Any, Input : Any, Output : Any> of( | ||
| flowReader: (Key) -> Flow<Output?>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assuming you land on "this is discoverable" should we call the flow one reader and the non flow one nonFlowReader to highlight the better default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated. i hate it for anyone needs to call it but i think it is the right call.
These appeared after i rebased, missed them completely. Also fixed some tests, appearantly IJ parameter name refactor does not always work
without this, multicaster cannot resolve to the base StoreResponse type
…fetcher' into yigit/move-fetcher-factories-to-fetcher # Conflicts: # store-rx2/src/test/kotlin/com/dropbox/store/rx2/test/RxFlowableStoreTest.kt
Codecov Report
@@ Coverage Diff @@
## master #168 +/- ##
=========================================
Coverage ? 86.01%
Complexity ? 230
=========================================
Files ? 54
Lines ? 951
Branches ? 149
=========================================
Hits ? 818
Misses ? 76
Partials ? 57
Continue to review full report at Codecov.
|
* Move Fetcher factories into companion Fetcher factories were global methods, which made them hard to discover since IDE cannot easily auto-complete. This PR moves them into the companion of Fetcher while also making Fetcher a real interface instead of a typealias. Even though it is a bit more code for the developer, now they can easily discover how to create a Fetcher by typing Fetcher. Fixes: #167 * make rx methods start w/ from too for consistency * Rename fether factories to be more clear, hopefully :/ * remove fetch method, use invoke instead * Make Fetcher.from the one that receives a suspend fun. Create Fetcher.fromFlow for the flowing version. Rename both SourceOfTruth builder methods to . Rely on param names to disambiguate * use .of instead, this seems better to me. We should probably get rid of StoreBuilder.from and make it Store.builder() * fix jvm name for SourceOfTruth.of with flow function * fix RxSourceOfTruth name to match original class * specify bounds for FactoryFetcher * updates per PR review * update graph per SoT rename * update rxjava3 APIs as well These appeared after i rebased, missed them completely. Also fixed some tests, appearantly IJ parameter name refactor does not always work * supress wrong unnecessary cast warning without this, multicaster cannot resolve to the base StoreResponse type * upgade gradle, try to fix build by disabling caching * split subscribers * resubscribe Co-authored-by: miken <[email protected]>
|
oh looks like this got merged into the master branch not main. |
* Move Fetcher factories into companion Fetcher factories were global methods, which made them hard to discover since IDE cannot easily auto-complete. This PR moves them into the companion of Fetcher while also making Fetcher a real interface instead of a typealias. Even though it is a bit more code for the developer, now they can easily discover how to create a Fetcher by typing Fetcher. Fixes: #167 * make rx methods start w/ from too for consistency * Rename fether factories to be more clear, hopefully :/ * remove fetch method, use invoke instead * Make Fetcher.from the one that receives a suspend fun. Create Fetcher.fromFlow for the flowing version. Rename both SourceOfTruth builder methods to . Rely on param names to disambiguate * use .of instead, this seems better to me. We should probably get rid of StoreBuilder.from and make it Store.builder() * fix jvm name for SourceOfTruth.of with flow function * fix RxSourceOfTruth name to match original class * specify bounds for FactoryFetcher * updates per PR review * update graph per SoT rename * update rxjava3 APIs as well These appeared after i rebased, missed them completely. Also fixed some tests, appearantly IJ parameter name refactor does not always work * supress wrong unnecessary cast warning without this, multicaster cannot resolve to the base StoreResponse type * upgade gradle, try to fix build by disabling caching * split subscribers * resubscribe Co-authored-by: miken <[email protected]> Co-authored-by: miken <[email protected]>
…obileNativeFoundation#181) * Move Fetcher factories into companion Fetcher factories were global methods, which made them hard to discover since IDE cannot easily auto-complete. This PR moves them into the companion of Fetcher while also making Fetcher a real interface instead of a typealias. Even though it is a bit more code for the developer, now they can easily discover how to create a Fetcher by typing Fetcher. Fixes: MobileNativeFoundation#167 * make rx methods start w/ from too for consistency * Rename fether factories to be more clear, hopefully :/ * remove fetch method, use invoke instead * Make Fetcher.from the one that receives a suspend fun. Create Fetcher.fromFlow for the flowing version. Rename both SourceOfTruth builder methods to . Rely on param names to disambiguate * use .of instead, this seems better to me. We should probably get rid of StoreBuilder.from and make it Store.builder() * fix jvm name for SourceOfTruth.of with flow function * fix RxSourceOfTruth name to match original class * specify bounds for FactoryFetcher * updates per PR review * update graph per SoT rename * update rxjava3 APIs as well These appeared after i rebased, missed them completely. Also fixed some tests, appearantly IJ parameter name refactor does not always work * supress wrong unnecessary cast warning without this, multicaster cannot resolve to the base StoreResponse type * upgade gradle, try to fix build by disabling caching * split subscribers * resubscribe Co-authored-by: miken <[email protected]> Co-authored-by: miken <[email protected]>
No description provided.