-
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
Paging #630
base: main
Are you sure you want to change the base?
Paging #630
Conversation
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
* Define PagingBuffer Signed-off-by: mramotar <[email protected]> * Define MutablePagingBuffer Signed-off-by: mramotar <[email protected]> --------- Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
* Implement RealDispatcher and Related Classes Signed-off-by: mramotar <[email protected]> * Implement RealOptionalInjector Signed-off-by: mramotar <[email protected]> * Implement DefaultLogger Signed-off-by: mramotar <[email protected]> --------- Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
#627) Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
Signed-off-by: mramotar <[email protected]>
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(libs.kotlin.stdlib) | ||
implementation(project(":store")) | ||
implementation(project(":cache")) |
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.
is cache not needed anymore?
@@ -57,27 +44,11 @@ kotlin { | |||
} | |||
|
|||
android { | |||
namespace = "org.mobilenativefoundation.store.paging5" | |||
namespace = "org.mobilenativefoundation.paging.core" |
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.
you can also do org.mobilenativefoundation.store5.paging.core
in case you want to ever have something like 5/6 at same time
* @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> { |
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 :-)
Any updates on this? |
Context:
launchPagingStore
Does Not Reflect Latest Writes in Mutable Store #602Description
Introducing a solution for paging in KMP projects. Motivations:
Type of Change
Test Plan
Unit tests
Checklist:
Before submitting your PR, please review and check all of the following:
Additional Notes:
Paging Technical Design Doc
1. Overview
Modular and flexible architecture. Using builder, reducer, middleware, and post-reducer effect patterns. Unidirectional
data flow. The
Pager
is the main component. Actions are dispatched through thePager
. ThePagerBuilder
createsthe
Pager
. It allows configuration of the paging behavior. ThePagingSource
defines the data loading logic. TheFetchingStrategy
determines when to fetch the next page. TheAggregatingStrategy
combines loaded pages into a single list. TheReducer
handles state changes based on actions. When an action is dispatched, it goes through the middleware pipeline. The middleware can modify the action. The reducer then updates the state based on the action. After the reducer, we invoke post-reducer effects associated with the action and new state. The updated state is sent back thePager
and emitted to the UI.2. Key Components
Pager
: The main entry point for the paging library. It coordinates the paging process and provides access to the paging state and data.PagingState
: Represents the current state of the paging data, including loaded pages, errors, and loading status.PagingAction
: Defines the actions that can be dispatched to modify the paging state.Reducer
: Responsible for taking the current paging state and a dispatched action, and producing a new paging state based on the action and the current state.Middleware
: Intercepts and modifies paging actions before they reach the reducer, allowing for pre-processing, logging, or any other custom logic.Effect
: Represents side effects or additional actions that need to be performed after the state has been reduced based on a dispatched action.PagingSource
: Represents a data source that provides paged data, emitting a stream of load results.PagingBuffer
: A custom data structure for efficiently storing and retrieving paging data.3. Customizations
Providing many extension points and customization options to tailor behavior. Main customization points:
PagingConfig
: Allows configuring the paging behavior, such as page size, prefetch distance, and insertion strategy.FetchingStrategy
: Determines whether to fetch more data based on the current state of the pager.AggregatingStrategy
: Defines how loaded pages of data should be combined and ordered to form a coherent list of paging items.ErrorHandlingStrategy
: Specifies different strategies for handling errors during the paging process.UserCustomActionReducer
: Allows defining custom reducers for handling user-defined actions.4. Data Flow
Unidirectional data flow. Main steps:
Pager
is configured usingPagerBuilder
and provided an initial key, flow of anchor position, and paging config.Pager
subscribes to thePagingSource
to receive paging data updates.PagingAction
is dispatched, it goes through the configuredMiddleware
chain. This enables interception and modification of the action.Reducer
, which reduces the currentPagingState
based on the action and returns a newPagingState
.Effect
instances are launched, enabling side effects to be performed based on the newPagingState
.Pager
updatesStateManager
with the newPagingState
.FetchingStrategy
determines when to fetch the next page of data based on thePagingConfig
and currentPagingState
.QueueManager
enqueues the page key, and theJobCoordinator
coordinates the execution of the paging job.PagingSource
loads the requested page and emits the loaded data through thePagingSourceStreamProvider
.MutablePagingBuffer
for efficient retrieval and aggregation.AggregatingStrategy
aggregates the loaded pages into a single list, which is then emitted through thePager
for consumption by the UI.5. Sample Code
See https://github.com/MobileNativeFoundation/Store/tree/paging/paging