Skip to content

Conversation

@yigit
Copy link
Collaborator

@yigit yigit commented May 11, 2020

No description provided.

@yigit yigit requested review from digitalbuddha and eyalgu May 11, 2020 21:48
yigit added 5 commits May 25, 2020 21:17
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
@yigit
Copy link
Collaborator Author

yigit commented May 26, 2020

pushed another attempt. now SoT has from for both methods (relying on method names to disambiguate). Removed stream from fetchers.

Fetcher.from -> suspend fun T
Fetcher.fromFlow -> Flow<T>
Fetcher.fromFetcherResult -> suspend fun FetcherResult<T>
Fetcher.fromFetcherResutlFlow -> Flow<FetcherResult>

The name for the flowable reader in SoT still sounds weird (flowReader). looking for suggestions.

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.

@yigit yigit force-pushed the yigit/move-fetcher-factories-to-fetcher branch from f90cf5d to 9a56e8e Compare May 26, 2020 04:56
@eyalgu
Copy link
Contributor

eyalgu commented May 26, 2020

pushed another attempt. now SoT has from for both methods (relying on method names to disambiguate). Removed stream from fetchers.

Fetcher.from -> suspend fun T
Fetcher.fromFlow -> Flow<T>
Fetcher.fromFetcherResult -> suspend fun FetcherResult<T>
Fetcher.fromFetcherResutlFlow -> Flow<FetcherResult>

The name for the flowable reader in SoT still sounds weird (flowReader). looking for suggestions.

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.

What are your thought about making from and fromFetcherResult vs fromValues and from? The more generic case seems to be the one that takes FetcherResult while the other one seems to be a connivance (though the more common use case admittedly).

One the one hand using from for the generic use case feels more future proof. On the other hand using from for the common use case make the API clearer right now.

* @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(
Copy link
Contributor

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.

Copy link
Collaborator Author

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?)

Copy link
Contributor

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.

@yigit
Copy link
Collaborator Author

yigit commented May 26, 2020

pushed another attempt. now SoT has from for both methods (relying on method names to disambiguate). Removed stream from fetchers.
Fetcher.from -> suspend fun T
Fetcher.fromFlow -> Flow<T>
Fetcher.fromFetcherResult -> suspend fun FetcherResult<T>
Fetcher.fromFetcherResutlFlow -> Flow<FetcherResult>
The name for the flowable reader in SoT still sounds weird (flowReader). looking for suggestions.
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.

What are your thought about making from and fromFetcherResult vs fromValues and from? The more generic case seems to be the one that takes FetcherResult while the other one seems to be a connivance (though the more common use case admittedly).

One the one hand using from for the generic use case feels more future proof. On the other hand using from for the common use case make the API clearer right now.

i was thinking the most common case should have the best name hence i thought fromValues should be from. That being said, fromFetcherResult sounds very ugly :/.

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,
Copy link
Contributor

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?

Copy link
Collaborator Author

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 :/.

reader: (Key) -> Flow<Output?>,
@JvmName("ofFlow")
fun <Key : Any, Input : Any, Output : Any> of(
flowReader: (Key) -> Flow<Output?>,
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

eyalgu
eyalgu previously approved these changes Jun 5, 2020
digitalbuddha
digitalbuddha previously approved these changes Jun 5, 2020
These appeared after i rebased, missed them completely.
Also fixed some tests, appearantly IJ parameter name refactor does
not always work
yigit and others added 3 commits June 7, 2020 14:47
miken added 2 commits June 13, 2020 14:14
…fetcher' into yigit/move-fetcher-factories-to-fetcher

# Conflicts:
#	store-rx2/src/test/kotlin/com/dropbox/store/rx2/test/RxFlowableStoreTest.kt
@codecov
Copy link

codecov bot commented Jun 13, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@a5c29ff). Click here to learn what that means.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #168   +/-   ##
=========================================
  Coverage          ?   86.01%           
  Complexity        ?      230           
=========================================
  Files             ?       54           
  Lines             ?      951           
  Branches          ?      149           
=========================================
  Hits              ?      818           
  Misses            ?       76           
  Partials          ?       57           
Impacted Files Coverage Δ Complexity Δ
.../android/external/store4/impl/FetcherController.kt 100.00% <ø> (ø) 6.00 <0.00> (?)
...src/main/kotlin/com/dropbox/store/rx2/RxFetcher.kt 50.00% <50.00%> (ø) 0.00 <0.00> (?)
...src/main/kotlin/com/dropbox/store/rx3/RxFetcher.kt 50.00% <50.00%> (ø) 0.00 <0.00> (?)
...in/kotlin/com/dropbox/store/rx2/RxSourceOfTruth.kt 70.00% <100.00%> (ø) 0.00 <0.00> (?)
...in/kotlin/com/dropbox/store/rx3/RxSourceOfTruth.kt 70.00% <100.00%> (ø) 0.00 <0.00> (?)
...ava/com/dropbox/android/external/store4/Fetcher.kt 100.00% <100.00%> (ø) 0.00 <0.00> (?)
...m/dropbox/android/external/store4/SourceOfTruth.kt 88.23% <100.00%> (ø) 0.00 <0.00> (?)
...va/com/dropbox/android/external/fs3/FSAllEraser.kt 100.00% <0.00%> (ø) 2.00% <0.00%> (?%)
... and 51 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a5c29ff...fdb26ba. Read the comment docs.

@eyalgu eyalgu merged commit 1a954e4 into master Jun 16, 2020
@eyalgu eyalgu deleted the yigit/move-fetcher-factories-to-fetcher branch June 16, 2020 23:52
yigit added a commit that referenced this pull request Jun 19, 2020
* 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]>
@yigit
Copy link
Collaborator Author

yigit commented Jun 19, 2020

oh looks like this got merged into the master branch not main.

digitalbuddha pushed a commit that referenced this pull request Jun 19, 2020
* 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]>
itsandreramon pushed a commit to itsandreramon/Store that referenced this pull request Feb 26, 2025
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants