@@ -31,7 +31,8 @@ class FeedViewModel @Inject constructor(
3131 private val postService : PostServiceClient
3232) : BaseViewModel() {
3333 private lateinit var votesChannel: SendChannel <Vote >
34- private val posts = MutableStateFlow (emptyList<Post >())
34+ private val mPosts = MutableStateFlow (emptyList<Post >())
35+ val posts = mPosts.asStateFlow()
3536 val isEmpty = posts.map(List <Post >::isEmpty).asState(true )
3637 val emptyText = MutableStateFlow (R .string.feed_empty).asStateFlow()
3738 private val stalePostIds = mutableSetOf<ByteString >()
@@ -68,7 +69,7 @@ class FeedViewModel @Inject constructor(
6869 }
6970
7071 fun reset () {
71- posts .value = emptyList()
72+ mPosts .value = emptyList()
7273 stalePostIds.clear()
7374 }
7475
@@ -80,7 +81,7 @@ class FeedViewModel @Inject constructor(
8081 spread = spread
8182 )
8283 )
83- posts .value = posts.value.filter { it.id != postId }
84+ mPosts .value = posts.value.filter { it.id != postId }
8485 }
8586
8687 private suspend fun FlowCollector<List<Post>>.emitFeed (newPost : Post ) {
@@ -102,20 +103,20 @@ class FeedViewModel @Inject constructor(
102103 pruneStalePosts()
103104 }
104105
105- posts .value = newFeed
106+ mPosts .value = newFeed
106107 emit(newFeed)
107108 }
108109
109110 private fun pruneStalePosts () {
110111 for (id in stalePostIds) {
111- posts .value = posts.value.filter { it.id != id }
112+ mPosts .value = posts.value.filter { it.id != id }
112113 }
113114
114115 stalePostIds.clear()
115116 }
116117
117118 private fun incrementCommentCount (postId : ByteString ) {
118- posts .value = posts.value.map {
119+ mPosts .value = posts.value.map {
119120 when (it.id) {
120121 postId -> it.copy(comment_count = it.comment_count + 1 )
121122 else -> it
0 commit comments