Skip to content

Commit

Permalink
Implement RealPager (#626)
Browse files Browse the repository at this point in the history
Signed-off-by: mramotar <mramotar@dropbox.com>
  • Loading branch information
matt-ramotar committed Mar 16, 2024
1 parent cf30814 commit 9ad5b2e
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.mobilenativefoundation.paging.core.impl

import kotlinx.coroutines.flow.StateFlow
import org.mobilenativefoundation.paging.core.Pager
import org.mobilenativefoundation.paging.core.PagingAction
import org.mobilenativefoundation.paging.core.PagingConfig
import org.mobilenativefoundation.paging.core.PagingKey
import org.mobilenativefoundation.paging.core.PagingState

class RealPager<Id : Comparable<Id>, K : Any, P : Any, D : Any, E : Any, A : Any>(
initialKey: PagingKey<K, P>,
stateManager: StateManager<Id, K, P, D, E>,
pagingConfigInjector: Injector<PagingConfig>,
private val dispatcher: Dispatcher<Id, K, P, D, E, A>,
) : Pager<Id, K, P, D, E, A> {

private val pagingConfig = lazy { pagingConfigInjector.inject() }

init {
if (pagingConfig.value.prefetchDistance > 0) {
dispatcher.dispatch(PagingAction.Load(initialKey))
}
}

override val state: StateFlow<PagingState<Id, K, P, D, E>> = stateManager.state

override fun dispatch(action: PagingAction.User<Id, K, P, D, E, A>) {
dispatcher.dispatch(action)
}
}

0 comments on commit 9ad5b2e

Please sign in to comment.