diff --git a/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Joiner.kt b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Joiner.kt new file mode 100644 index 000000000..7a5da0967 --- /dev/null +++ b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Joiner.kt @@ -0,0 +1,10 @@ +package org.mobilenativefoundation.store.paging5 + +import org.mobilenativefoundation.store.core5.ExperimentalStoreApi +import org.mobilenativefoundation.store.core5.StoreData +import org.mobilenativefoundation.store.core5.StoreKey + +@ExperimentalStoreApi +interface Joiner, SO : StoreData.Single> { + suspend operator fun invoke(data: Map>): PagingData +} \ No newline at end of file diff --git a/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/KeyFactory.kt b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/KeyFactory.kt new file mode 100644 index 000000000..3d442c8df --- /dev/null +++ b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/KeyFactory.kt @@ -0,0 +1,9 @@ +package org.mobilenativefoundation.store.paging5 + +import org.mobilenativefoundation.store.core5.ExperimentalStoreApi +import org.mobilenativefoundation.store.core5.StoreKey + +@ExperimentalStoreApi +interface KeyFactory> { + fun createFor(id: Id): SK +} \ No newline at end of file diff --git a/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Pager.kt b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Pager.kt new file mode 100644 index 000000000..2ebdb71fb --- /dev/null +++ b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Pager.kt @@ -0,0 +1,62 @@ +package org.mobilenativefoundation.store.paging5 + +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow +import org.mobilenativefoundation.store.core5.ExperimentalStoreApi +import org.mobilenativefoundation.store.core5.StoreData +import org.mobilenativefoundation.store.core5.StoreKey +import org.mobilenativefoundation.store.store5.MutableStore +import org.mobilenativefoundation.store.store5.Store +import org.mobilenativefoundation.store.store5.StoreReadRequest +import org.mobilenativefoundation.store.store5.StoreReadResponse + +@ExperimentalStoreApi +interface Pager, SO : StoreData.Single> { + val state: StateFlow> + fun load(key: K) + + companion object { + fun , K : StoreKey, SO : StoreData.Single, O : StoreData> create( + scope: CoroutineScope, + store: Store, + joiner: Joiner, + keyFactory: KeyFactory + ): Pager { + + val streamer = object : Streamer { + override fun invoke(key: K): Flow> { + return store.stream(StoreReadRequest.fresh(key)) + } + } + + return RealPager( + scope, + streamer, + joiner, + keyFactory + ) + } + + fun , K : StoreKey, SO : StoreData.Single, O : StoreData> create( + scope: CoroutineScope, + store: MutableStore, + joiner: Joiner, + keyFactory: KeyFactory + ): Pager { + + val streamer = object : Streamer { + override fun invoke(key: K): Flow> { + return store.stream(StoreReadRequest.fresh(key)) + } + } + + return RealPager( + scope, + streamer, + joiner, + keyFactory + ) + } + } +} \ No newline at end of file diff --git a/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/PagingData.kt b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/PagingData.kt new file mode 100644 index 000000000..5e799b970 --- /dev/null +++ b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/PagingData.kt @@ -0,0 +1,9 @@ +package org.mobilenativefoundation.store.paging5 + +import org.mobilenativefoundation.store.core5.ExperimentalStoreApi +import org.mobilenativefoundation.store.core5.StoreData + +@ExperimentalStoreApi +data class PagingData>( + val items: List +) \ No newline at end of file diff --git a/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStore.kt b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/RealPager.kt similarity index 67% rename from paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStore.kt rename to paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/RealPager.kt index 422c69cf2..c445685c0 100644 --- a/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStore.kt +++ b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/RealPager.kt @@ -4,7 +4,6 @@ package org.mobilenativefoundation.store.paging5 import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job -import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow @@ -15,84 +14,11 @@ import kotlinx.coroutines.sync.withLock import org.mobilenativefoundation.store.core5.ExperimentalStoreApi import org.mobilenativefoundation.store.core5.StoreData import org.mobilenativefoundation.store.core5.StoreKey -import org.mobilenativefoundation.store.store5.MutableStore -import org.mobilenativefoundation.store.store5.Store -import org.mobilenativefoundation.store.store5.StoreReadRequest import org.mobilenativefoundation.store.store5.StoreReadResponse @ExperimentalStoreApi -data class PagingData>( - val items: List -) - -@ExperimentalStoreApi -interface Pager, SO : StoreData.Single> { - val state: StateFlow> - fun load(key: K) - - companion object { - fun , K : StoreKey, SO : StoreData.Single, O : StoreData> create( - scope: CoroutineScope, - store: Store, - joiner: Joiner, - keyFactory: KeyFactory - ): Pager { - - val streamer = object : Streamer { - override fun invoke(key: K): Flow> { - return store.stream(StoreReadRequest.fresh(key)) - } - } - - return RealPager( - scope, - streamer, - joiner, - keyFactory - ) - } - - fun , K : StoreKey, SO : StoreData.Single, O : StoreData> create( - scope: CoroutineScope, - store: MutableStore, - joiner: Joiner, - keyFactory: KeyFactory - ): Pager { - - val streamer = object : Streamer { - override fun invoke(key: K): Flow> { - return store.stream(StoreReadRequest.fresh(key)) - } - } - - return RealPager( - scope, - streamer, - joiner, - keyFactory - ) - } - } -} - -@ExperimentalStoreApi -interface Joiner, SO : StoreData.Single> { - suspend operator fun invoke(data: Map>): PagingData -} - -@ExperimentalStoreApi -interface Streamer, O : StoreData> { - operator fun invoke(key: K): Flow> -} - -@ExperimentalStoreApi -interface KeyFactory> { - fun createFor(id: Id): SK -} - -@ExperimentalStoreApi -class RealPager, K : StoreKey, SO : StoreData.Single, O : StoreData>( +internal class RealPager, K : StoreKey, SO : StoreData.Single, O : StoreData>( private val scope: CoroutineScope, private val streamer: Streamer, private val joiner: Joiner, diff --git a/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Streamer.kt b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Streamer.kt new file mode 100644 index 000000000..ccbf5e3e5 --- /dev/null +++ b/paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Streamer.kt @@ -0,0 +1,12 @@ +package org.mobilenativefoundation.store.paging5 + +import kotlinx.coroutines.flow.Flow +import org.mobilenativefoundation.store.core5.ExperimentalStoreApi +import org.mobilenativefoundation.store.core5.StoreData +import org.mobilenativefoundation.store.core5.StoreKey +import org.mobilenativefoundation.store.store5.StoreReadResponse + +@ExperimentalStoreApi +internal interface Streamer, O : StoreData> { + operator fun invoke(key: K): Flow> +} \ No newline at end of file diff --git a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStoreTests.kt b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/RealPagerTest.kt similarity index 99% rename from paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStoreTests.kt rename to paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/RealPagerTest.kt index 5e8346904..dd7cb3f74 100644 --- a/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/LaunchPagingStoreTests.kt +++ b/paging/src/commonTest/kotlin/org/mobilenativefoundation/store/paging5/RealPagerTest.kt @@ -22,7 +22,7 @@ import kotlin.test.Test import kotlin.test.assertEquals @OptIn(ExperimentalStoreApi::class, ExperimentalCoroutinesApi::class) -class LaunchPagingStoreTests { +class RealPagerTest { private val testScope = TestScope() private val userId = "123"