File tree Expand file tree Collapse file tree 4 files changed +12
-8
lines changed
sample/app/src/main/java/com/hoc081098/channeleventbus/sample/android Expand file tree Collapse file tree 4 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package com.hoc081098.channeleventbus.sample.android
33import android.app.Application
44import com.hoc081098.channeleventbus.ChannelEventBus
55import com.hoc081098.channeleventbus.ChannelEventBusLogger
6+ import com.hoc081098.channeleventbus.sample.android.common.SingleEventChannel
67import com.hoc081098.channeleventbus.sample.android.ui.home.HomeModule
78import com.hoc081098.channeleventbus.sample.android.ui.register.RegisterModule
89import 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 }
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ internal sealed interface RegisterStepThreeUiState {
3838
3939class 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 ) {
You can’t perform that action at this time.
0 commit comments