Skip to content

Commit

Permalink
Rename to launchPagingStore
Browse files Browse the repository at this point in the history
Signed-off-by: mramotar_dbx <mramotar@dropbox.com>
  • Loading branch information
matt-ramotar committed Oct 18, 2023
1 parent 10f8294 commit b975466
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ private class StopProcessingException : Exception()
* @param stream A lambda that invokes [Store.stream].
* @return A read-only [StateFlow] reflecting the state of the Store.
*/
private fun <Id : Any, Key : StoreKey<Id>, Output : StoreData<Id>> launchStore(
private fun <Id : Any, Key : StoreKey<Id>, Output : StoreData<Id>> launchPagingStore(
scope: CoroutineScope,
keys: Flow<Key>,
stream: (key: Key) -> Flow<StoreReadResponse<Output>>,
Expand Down Expand Up @@ -66,27 +66,27 @@ private fun <Id : Any, Key : StoreKey<Id>, Output : StoreData<Id>> launchStore(

/**
* Initializes and returns a [StateFlow] that reflects the state of the [Store], updating by a flow of provided keys.
* @see [launchStore].
* @see [launchPagingStore].
*/
fun <Id : Any, Key : StoreKey<Id>, Output : StoreData<Id>> Store<Key, Output>.launchStore(
fun <Id : Any, Key : StoreKey<Id>, Output : StoreData<Id>> Store<Key, Output>.launchPagingStore(
scope: CoroutineScope,
keys: Flow<Key>,
): StateFlow<StoreReadResponse<Output>> {
return launchStore(scope, keys) { key ->
return launchPagingStore(scope, keys) { key ->
this.stream(StoreReadRequest.fresh(key))
}
}

/**
* Initializes and returns a [StateFlow] that reflects the state of the [Store], updating by a flow of provided keys.
* @see [launchStore].
* @see [launchPagingStore].
*/
@OptIn(ExperimentalStoreApi::class)
fun <Id : Any, Key : StoreKey<Id>, Output : StoreData<Id>> MutableStore<Key, Output>.launchStore(
fun <Id : Any, Key : StoreKey<Id>, Output : StoreData<Id>> MutableStore<Key, Output>.launchPagingStore(
scope: CoroutineScope,
keys: Flow<Key>,
): StateFlow<StoreReadResponse<Output>> {
return launchStore(scope, keys) { key ->
return launchPagingStore(scope, keys) { key ->
this.stream<Any>(StoreReadRequest.fresh(key))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.test.assertEquals
import kotlin.test.assertIs

@OptIn(ExperimentalStoreApi::class)
class LaunchStoreTests {
class LaunchPagingStoreTests {
private val testScope = TestScope()

private val userId = "123"
Expand All @@ -34,7 +34,7 @@ class LaunchStoreTests {
fun `state transitions from Loading to Loaded Collection for valid Cursor key`() = testScope.runTest {
val key = PostKey.Cursor("1", 10)
val keys = flowOf(key)
val stateFlow = store.launchStore(this, keys)
val stateFlow = store.launchPagingStore(this, keys)

stateFlow.test {
val state1 = awaitItem()
Expand All @@ -52,7 +52,7 @@ class LaunchStoreTests {
val key1 = PostKey.Cursor("1", 10)
val key2 = PostKey.Cursor("11", 10)
val keys = flowOf(key1, key2)
val stateFlow = store.launchStore(this, keys)
val stateFlow = store.launchPagingStore(this, keys)

stateFlow.test {
val state1 = awaitItem()
Expand All @@ -77,7 +77,7 @@ class LaunchStoreTests {
fun `state remains consistent if the same key is emitted multiple times`() = testScope.runTest {
val key = PostKey.Cursor("1", 10)
val keys = flowOf(key, key)
val stateFlow = store.launchStore(this, keys)
val stateFlow = store.launchPagingStore(this, keys)

stateFlow.test {
val state1 = awaitItem()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PagingTests {
val key2 = PostKey.Cursor("11", 10)
val keys = flowOf(key1, key2)

val stateFlow = store.launchStore(this, keys)
val stateFlow = store.launchPagingStore(this, keys)
stateFlow.test {
val initialState = awaitItem()
assertIs<StoreReadResponse.Initial>(initialState)
Expand Down

0 comments on commit b975466

Please sign in to comment.