Skip to content

Commit a528e46

Browse files
committed
fix and update sample
1 parent c4a3bd9 commit a528e46

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

sample/app/src/main/java/com/hoc081098/channeleventbus/sample/android/MyApp.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.hoc081098.channeleventbus.sample.android
33
import android.app.Application
44
import com.hoc081098.channeleventbus.ChannelEventBus
55
import com.hoc081098.channeleventbus.ChannelEventBusLogger
6+
import com.hoc081098.channeleventbus.sample.android.common.SingleEventChannel
67
import com.hoc081098.channeleventbus.sample.android.ui.home.HomeModule
78
import com.hoc081098.channeleventbus.sample.android.ui.register.RegisterModule
89
import org.koin.android.ext.koin.androidContext
@@ -46,6 +47,9 @@ class MyApp : Application() {
4647
ChannelEventBusModule,
4748
RegisterModule,
4849
HomeModule,
50+
module {
51+
factory { SingleEventChannel<Any?>() }
52+
},
4953
)
5054
}
5155
}

sample/app/src/main/java/com/hoc081098/channeleventbus/sample/android/common/SingleEventChannel.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface HasSingleEventFlow<E> {
2121
* Must collect in [Dispatchers.Main.immediate][kotlinx.coroutines.MainCoroutineDispatcher.immediate].
2222
* Safe to call in the coroutines launched by [androidx.lifecycle.lifecycleScope].
2323
*/
24-
val eventFlow: Flow<E>
24+
val singleEventFlow: Flow<E>
2525
}
2626

2727
@MainThread
@@ -30,7 +30,7 @@ interface SingleEventFlowSender<E> {
3030
* Must call in [Dispatchers.Main.immediate][kotlinx.coroutines.MainCoroutineDispatcher.immediate].
3131
* Safe to call in the coroutines launched by [androidx.lifecycle.viewModelScope].
3232
*/
33-
suspend fun send(event: E)
33+
suspend fun sendEvent(event: E)
3434
}
3535

3636
@MainThread
@@ -40,7 +40,7 @@ class SingleEventChannel<E> constructor() :
4040
SingleEventFlowSender<E> {
4141
private val _eventChannel = Channel<E>(Channel.UNLIMITED)
4242

43-
override val eventFlow: Flow<E> by lazy(NONE) {
43+
override val singleEventFlow: Flow<E> by lazy(NONE) {
4444
if (BuildConfig.DEBUG) {
4545
flow {
4646
debugCheckImmediateMainDispatcher()
@@ -61,7 +61,7 @@ class SingleEventChannel<E> constructor() :
6161
* use `withContext(Dispatchers.Main.immediate) { eventChannel.send(event) }`
6262
*/
6363
@MainThread
64-
override suspend fun send(event: E) {
64+
override suspend fun sendEvent(event: E) {
6565
debugCheckImmediateMainDispatcher()
6666

6767
_eventChannel

sample/app/src/main/java/com/hoc081098/channeleventbus/sample/android/ui/register/stepthree/RegisterStepThreeScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fun RegisterStepThreeScreen(
4747
val currentNavigateToHome by rememberUpdatedState(navigateToHome)
4848
val context = rememberStableWrapperOf(LocalContext.current)
4949

50-
vm.eventFlow.CollectWithLifecycleEffect { event ->
50+
vm.singleEventFlow.CollectWithLifecycleEffect { event ->
5151
when (event) {
5252
is RegisterStepThreeSingleEvent.Failure -> {
5353
Toast

sample/app/src/main/java/com/hoc081098/channeleventbus/sample/android/ui/register/stepthree/RegisterStepThreeVM.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ internal sealed interface RegisterStepThreeUiState {
3838

3939
class RegisterStepThreeVM(
4040
private val singleEventChannel: SingleEventChannel<RegisterStepThreeSingleEvent>,
41-
) : ViewModel(),
41+
) : ViewModel(singleEventChannel),
4242
HasSingleEventFlow<RegisterStepThreeSingleEvent> by singleEventChannel {
4343
private val _registerFlow = MutableSharedFlow<RegisterUiState.Filled>(extraBufferCapacity = 1)
4444

@@ -61,10 +61,10 @@ class RegisterStepThreeVM(
6161
Unit
6262

6363
is RegisterStepThreeUiState.Failure ->
64-
singleEventChannel.send(RegisterStepThreeSingleEvent.Failure(state.throwable))
64+
singleEventChannel.sendEvent(RegisterStepThreeSingleEvent.Failure(state.throwable))
6565

6666
RegisterStepThreeUiState.Success ->
67-
singleEventChannel.send(RegisterStepThreeSingleEvent.Success)
67+
singleEventChannel.sendEvent(RegisterStepThreeSingleEvent.Success)
6868
}
6969

7070
internal fun register(state: RegisterUiState) {

0 commit comments

Comments
 (0)