-
Notifications
You must be signed in to change notification settings - Fork 203
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
Fix launchPagingStore #603
Conversation
Signed-off-by: mramotar_dbx <[email protected]>
Signed-off-by: mramotar_dbx <[email protected]>
Signed-off-by: mramotar_dbx <[email protected]>
Signed-off-by: mramotar_dbx <[email protected]>
Signed-off-by: mramotar_dbx <[email protected]>
Signed-off-by: mramotar_dbx <[email protected]>
Signed-off-by: mramotar_dbx <[email protected]>
Signed-off-by: mramotar_dbx <[email protected]>
Signed-off-by: mramotar_dbx <[email protected]>
9bdae15
to
8ee88bb
Compare
childScope.launch { | ||
// Locking the streams map to check and manage stream jobs. | ||
mutexForAllStreams.withLock { | ||
// Checking if there's no active stream for the key. |
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.
just for readablility, it would be nicer to move these into helper methods.
especially, it is hard to visually track mutexForAllStreams
usages without separate methods.
launchChildCollectionLocked
kind of interface might be good.
alternatively, you can use a helper method to create the coroutine (lazily) and then only start it if you can get the lock (e.g. allStrams[key] is null).
val childJob = launch { | ||
initStreamAndHandleSingle(single, childKey, key) | ||
} |
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.
so, i'm guessing this is for individual item updates (just double checking).
This was a request in paging, the ability to notify single item changes. But we've never implemented it and it is really hard (since item data change might change ordering). Ideally, instead of observing each child individually, it would be better to let streamer do that job. Technically, I think the streamer should be responsible to emit a new value when any elements matching the data set is changed.
Since I've not looked at store for a while, i might be widely wrong :D. But it feels like better to avoid watching every single child individually, also knowing that, room/sqldelight both will send notification when anything in the table changes, not necessarily an individual item.
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.
another option for individual element watching is is to make streamer(key) return a list of ids and fetch those ids individually (that is how firebase paging works, or worked at some time :) ).
otherwise, i think it is better for streamer to invalidate everything properly instead.
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.
Moving the responsibility of listening for child updates from RealPager to the streamer makes sense. I also like that users will be able to decide for themselves what level of granularity in observing updates.
// Storing the main job and handling its completion. | ||
allStreams[key] = mainJob | ||
|
||
mainJob.invokeOnCompletion { |
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 think we shoiulda void child collectors. but if we cant, you can do this better by making their jobs a child of mainJob so that you won't need manual cleanup.
Signed-off-by: mramotar_dbx <[email protected]>
var combinedItems = mutableListOf<PostData.Post>() | ||
|
||
data.values.forEach { responseData -> | ||
responseData.items.let { items -> | ||
combinedItems = (combinedItems + items).distinctBy { it.postId }.toMutableList() | ||
} | ||
} |
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.
combinedItems
's type should be List.
And toMutableList
is unnecessary when using List type
Closing. See #611 |
Closes #602
Description
The cause of #602 is we were not synchronizing updates to single items with the collection they belong to. This PR fixes that by handling the streaming and updating of single item data within a collection.
Other changes:
Pager
,PagingData
,Joiner
,Streamer
, andKeyFactory
interfaces. I think this is cleaner, easier to reason about, easier to test.launchPagingStore
intoRealPager
implementation.PagingData
rather thanStoreReadResponse
. My thought is this will make it easier to support UI-level extensions, similar tocollectLazyPagingItems
.Type of Change
Test Plan
Checklist:
Before submitting your PR, please review and check all of the following:
Additional Notes: