-
Notifications
You must be signed in to change notification settings - Fork 194
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
Paging #630
Open
matt-ramotar
wants to merge
18
commits into
main
Choose a base branch
from
paging
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Paging #630
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
26b7baa
Add paging:core module
matt-ramotar 505ea5f
Remove LaunchPagingStore.kt
matt-ramotar c72ced9
Implement PagingKey and PagingData (#614)
matt-ramotar 4ff9da3
Define PagingSource (#615)
matt-ramotar f0d912c
Define PagingAction and PagingState (#616)
matt-ramotar 280da6a
Define Middleware, Reducer, and Effect (#617)
matt-ramotar 6425c83
Define PagingBuffer and MutablePagingBuffer (#618)
matt-ramotar 705539e
Define PagingConfig and Paging Strategies (#619)
matt-ramotar 0b901bc
Define Pager (#620)
matt-ramotar c38c694
Implement RealDispatcher and Related Classes (#621)
matt-ramotar f6df164
Define QueueManager and Implement RealQueueManager (#622)
matt-ramotar 4c190a2
Implement RealMutablePagingBuffer (#623)
matt-ramotar 5575a0b
Implement DefaultReducer (#624)
matt-ramotar cf30814
Implement Default Effects (#625)
matt-ramotar 9ad5b2e
Implement RealPager (#626)
matt-ramotar 76f7a76
Add PagerBuilder, DefaultReducerBuilder, and default paging strategie…
matt-ramotar 884cdd0
Add README (#628)
matt-ramotar f40c4a2
Cover RealPager (#629)
matt-ramotar 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
Define PagingConfig and Paging Strategies (#619)
Signed-off-by: mramotar <[email protected]>
- Loading branch information
commit 705539ea57352c9e1c3979e00e541134d20bcb1b
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
.../core/src/commonMain/kotlin/org/mobilenativefoundation/paging/core/AggregatingStrategy.kt
This file contains 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,31 @@ | ||
package org.mobilenativefoundation.paging.core | ||
|
||
/** | ||
* Represents a strategy for aggregating loaded pages of data into a single instance of [PagingItems]. | ||
* | ||
* The [AggregatingStrategy] determines how the loaded pages of data should be combined and ordered to form a coherent list of [PagingData.Single] items. | ||
* It takes into account the anchor position, prefetch position, paging configuration, and the current state of the paging buffer. | ||
* | ||
* @param Id The type of the unique identifier for each item in the paged data. | ||
* @param K The type of the key used for paging. | ||
* @param P The type of the parameters associated with each page of data. | ||
* @param D The type of the data items. | ||
*/ | ||
interface AggregatingStrategy<Id : Comparable<Id>, K : Any, P : Any, D : Any> { | ||
|
||
/** | ||
* Aggregates the loaded pages of data into a single instance of [PagingItems]. | ||
* | ||
* @param anchorPosition The current anchor position in the paged data. | ||
* @param prefetchPosition The position to prefetch data from, or `null` if no prefetching is needed. | ||
* @param pagingConfig The configuration of the pager, including page size and prefetch distance. | ||
* @param pagingBuffer The current state of the paging buffer, containing the loaded data. | ||
* @return The aggregated list of [PagingItems] representing the combined and ordered paging data. | ||
*/ | ||
fun aggregate( | ||
anchorPosition: PagingKey<K, P>, | ||
prefetchPosition: PagingKey<K, P>?, | ||
pagingConfig: PagingConfig, | ||
pagingBuffer: PagingBuffer<Id, K, P, D>, | ||
): PagingItems<Id, K, P, D> | ||
} |
25 changes: 25 additions & 0 deletions
25
...ore/src/commonMain/kotlin/org/mobilenativefoundation/paging/core/ErrorHandlingStrategy.kt
This file contains 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,25 @@ | ||
package org.mobilenativefoundation.paging.core | ||
|
||
/** | ||
* Represents different strategies for handling errors during the paging process. | ||
*/ | ||
sealed interface ErrorHandlingStrategy { | ||
/** | ||
* Ignores errors and continues with the previous state. | ||
*/ | ||
data object Ignore : ErrorHandlingStrategy | ||
|
||
/** | ||
* Passes the error to the UI layer for handling. | ||
*/ | ||
data object PassThrough : ErrorHandlingStrategy | ||
|
||
/** | ||
* Retries the last failed load operation. | ||
* | ||
* @property maxRetries The maximum number of retries before passing the error to the UI. Default is 3. | ||
*/ | ||
data class RetryLast( | ||
val maxRetries: Int = 3 | ||
) : ErrorHandlingStrategy | ||
} |
34 changes: 34 additions & 0 deletions
34
paging/core/src/commonMain/kotlin/org/mobilenativefoundation/paging/core/FetchingStrategy.kt
This file contains 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,34 @@ | ||
package org.mobilenativefoundation.paging.core | ||
|
||
/** | ||
* Represents a strategy for determining whether to fetch more data based on the current state of the pager. | ||
* The fetching strategy is responsible for deciding whether to fetch more data based on the anchor position, | ||
* prefetch position, paging configuration, and the current state of the paging buffer. | ||
* | ||
* Implementing a custom [FetchingStrategy] allows you to define your own logic for when to fetch more data. | ||
* For example, you can fetch more data when the user scrolls near the end of the currently loaded data, or when a certain number of items are remaining in the buffer. | ||
* | ||
* @param Id The type of the unique identifier for each item in the paged data. | ||
* @param K The type of the key used for paging. | ||
* @param P The type of the parameters associated with each page of data. | ||
* @param D The type of the data items. | ||
*/ | ||
interface FetchingStrategy<Id : Comparable<Id>, K : Any, P : Any, D : Any> { | ||
|
||
/** | ||
* Determines whether to fetch more data based on the current state of the pager. | ||
* The [shouldFetch] implementation should determine whether more data should be fetched based on the provided parameters. | ||
* | ||
* @param anchorPosition The current anchor position in the paged data. | ||
* @param prefetchPosition The position to prefetch data from, or `null` if no prefetching is needed. | ||
* @param pagingConfig The configuration of the pager, including page size and prefetch distance. | ||
* @param pagingBuffer The current state of the paging buffer, containing the loaded data. | ||
* @return `true` if more data should be fetched, `false` otherwise. | ||
*/ | ||
fun shouldFetch( | ||
anchorPosition: PagingKey<K, P>, | ||
prefetchPosition: PagingKey<K, P>?, | ||
pagingConfig: PagingConfig, | ||
pagingBuffer: PagingBuffer<Id, K, P, D>, | ||
): Boolean | ||
} |
34 changes: 34 additions & 0 deletions
34
paging/core/src/commonMain/kotlin/org/mobilenativefoundation/paging/core/PagingConfig.kt
This file contains 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,34 @@ | ||
package org.mobilenativefoundation.paging.core | ||
|
||
/** | ||
* Represents the configuration for paging behavior. | ||
* | ||
* @property pageSize The number of items to load per page. | ||
* @property prefetchDistance The distance from the edge of the loaded data at which to prefetch more data. | ||
* @property insertionStrategy The strategy for inserting new data into the paging buffer. | ||
*/ | ||
data class PagingConfig( | ||
val pageSize: Int, | ||
val prefetchDistance: Int, | ||
val insertionStrategy: InsertionStrategy | ||
) { | ||
/** | ||
* Represents different insertion strategies for adding new data to the paging buffer. | ||
*/ | ||
enum class InsertionStrategy { | ||
/** | ||
* Appends new data to the end of the buffer. | ||
*/ | ||
APPEND, | ||
|
||
/** | ||
* Prepends new data to the beginning of the buffer. | ||
*/ | ||
PREPEND, | ||
|
||
/** | ||
* Replaces the existing data in the buffer with the new data. | ||
*/ | ||
REPLACE, | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
paging/core/src/commonMain/kotlin/org/mobilenativefoundation/paging/core/PagingItems.kt
This file contains 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,14 @@ | ||
package org.mobilenativefoundation.paging.core | ||
|
||
/** | ||
* Represents a list of paging items. | ||
* | ||
* @param Id The type of the unique identifier for each item in the paged data. | ||
* @param K The type of the key used for paging. | ||
* @param P The type of the parameters associated with each page of data. | ||
* @param D The type of the data items. | ||
* @property data The list of [PagingData.Single] items representing the paging data. | ||
*/ | ||
data class PagingItems<Id : Comparable<Id>, K : Any, P : Any, D : Any>( | ||
val data: List<PagingData.Single<Id, K, P, D>> | ||
) |
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.
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 still prefer Key,Request,Response as the param names :-)