Skip to content

Commit

Permalink
Move SavedStateHandle into constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
3yebMB committed Oct 18, 2024
1 parent ab34463 commit d89e04f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ val applicationModule = module {
viewModel {
CreatePostViewModel(
postRepository = get(),
savedStateHandle = get(),
dispatchers = get(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import kotlinx.coroutines.withContext

class CreatePostViewModel(
private val postRepository: PostRepository,
private val savedStateHandle: SavedStateHandle,
private val dispatchers: CoroutineDispatchers,
) : ViewModel() {

private companion object {
private const val SCREEN_STATE_KEY = "createPostScreenState"
}

private val savedStateHandle = SavedStateHandle()
val screenState: LiveData<CreateNewPostScreenState> = savedStateHandle.getLiveData(SCREEN_STATE_KEY)

fun createPost(postText: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.m13d.somenet.postcomposer

import androidx.lifecycle.SavedStateHandle
import dev.m13d.somenet.InstantTaskExecutorExtension
import dev.m13d.somenet.app.TestDispatchers
import dev.m13d.somenet.domain.post.InMemoryPostsCatalog
Expand Down Expand Up @@ -33,6 +34,7 @@ class CreatePostTest {
clock = clock,
)
),
SavedStateHandle(),
TestDispatchers(),
)

Expand All @@ -56,6 +58,7 @@ class CreatePostTest {
clock = clock,
)
),
SavedStateHandle(),
TestDispatchers(),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.m13d.somenet.postcomposer

import androidx.lifecycle.SavedStateHandle
import dev.m13d.somenet.InstantTaskExecutorExtension
import dev.m13d.somenet.app.TestDispatchers
import dev.m13d.somenet.domain.post.OfflinePostCatalog
Expand All @@ -25,6 +26,7 @@ class FailedPostCreationTest {
InMemoryUserDataStore("userId"),
UnavailablePostCatalog()
),
SavedStateHandle(),
TestDispatchers(),
)

Expand All @@ -40,6 +42,7 @@ class FailedPostCreationTest {
InMemoryUserDataStore("userId"),
OfflinePostCatalog()
),
SavedStateHandle(),
TestDispatchers(),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.m13d.somenet.postcomposer

import androidx.lifecycle.SavedStateHandle
import dev.m13d.somenet.InstantTaskExecutorExtension
import dev.m13d.somenet.app.TestDispatchers
import dev.m13d.somenet.domain.post.InMemoryPostsCatalog
Expand Down Expand Up @@ -31,8 +32,9 @@ class RenderingCreatePostStateTest {
private val postCatalog = InMemoryPostsCatalog(idGenerator = idGenerator, clock = clock)
private val userData = InMemoryUserDataStore(loggedInUserId)
private val postRepository = PostRepository(userData, postCatalog)
private val savedStateHandle = SavedStateHandle()
private val dispatchers = TestDispatchers()
private val viewModel = CreatePostViewModel(postRepository, dispatchers)
private val viewModel = CreatePostViewModel(postRepository, savedStateHandle, dispatchers)

@Test
fun uiStatesAreDeliveredInParticularOrder() {
Expand Down

0 comments on commit d89e04f

Please sign in to comment.