-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6af0312
commit 2463962
Showing
7 changed files
with
104 additions
and
76 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Joiner.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,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<Id : Any, K : StoreKey<Id>, SO : StoreData.Single<Id>> { | ||
suspend operator fun invoke(data: Map<K, PagingData<Id, SO>>): PagingData<Id, SO> | ||
} |
9 changes: 9 additions & 0 deletions
9
paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/KeyFactory.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,9 @@ | ||
package org.mobilenativefoundation.store.paging5 | ||
|
||
import org.mobilenativefoundation.store.core5.ExperimentalStoreApi | ||
import org.mobilenativefoundation.store.core5.StoreKey | ||
|
||
@ExperimentalStoreApi | ||
interface KeyFactory<Id : Any, SK : StoreKey.Single<Id>> { | ||
fun createFor(id: Id): SK | ||
} |
62 changes: 62 additions & 0 deletions
62
paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Pager.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,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<Id : Any, K : StoreKey<Id>, SO : StoreData.Single<Id>> { | ||
val state: StateFlow<PagingData<Id, SO>> | ||
fun load(key: K) | ||
|
||
companion object { | ||
fun <Id : Any, SK : StoreKey.Single<Id>, K : StoreKey<Id>, SO : StoreData.Single<Id>, O : StoreData<Id>> create( | ||
scope: CoroutineScope, | ||
store: Store<K, O>, | ||
joiner: Joiner<Id, K, SO>, | ||
keyFactory: KeyFactory<Id, SK> | ||
): Pager<Id, K, SO> { | ||
|
||
val streamer = object : Streamer<Id, K, O> { | ||
override fun invoke(key: K): Flow<StoreReadResponse<O>> { | ||
return store.stream(StoreReadRequest.fresh(key)) | ||
} | ||
} | ||
|
||
return RealPager( | ||
scope, | ||
streamer, | ||
joiner, | ||
keyFactory | ||
) | ||
} | ||
|
||
fun <Id : Any, SK : StoreKey.Single<Id>, K : StoreKey<Id>, SO : StoreData.Single<Id>, O : StoreData<Id>> create( | ||
scope: CoroutineScope, | ||
store: MutableStore<K, O>, | ||
joiner: Joiner<Id, K, SO>, | ||
keyFactory: KeyFactory<Id, SK> | ||
): Pager<Id, K, SO> { | ||
|
||
val streamer = object : Streamer<Id, K, O> { | ||
override fun invoke(key: K): Flow<StoreReadResponse<O>> { | ||
return store.stream<Any>(StoreReadRequest.fresh(key)) | ||
} | ||
} | ||
|
||
return RealPager( | ||
scope, | ||
streamer, | ||
joiner, | ||
keyFactory | ||
) | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/PagingData.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,9 @@ | ||
package org.mobilenativefoundation.store.paging5 | ||
|
||
import org.mobilenativefoundation.store.core5.ExperimentalStoreApi | ||
import org.mobilenativefoundation.store.core5.StoreData | ||
|
||
@ExperimentalStoreApi | ||
data class PagingData<Id : Any, SO : StoreData.Single<Id>>( | ||
val items: List<SO> | ||
) |
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
12 changes: 12 additions & 0 deletions
12
paging/src/commonMain/kotlin/org/mobilenativefoundation/store/paging5/Streamer.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,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<Id : Any, K : StoreKey<Id>, O : StoreData<Id>> { | ||
operator fun invoke(key: K): Flow<StoreReadResponse<O>> | ||
} |
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