Skip to content

Commit 26ade4c

Browse files
authored
Merge pull request #95 from joreilly/molecule
molecule events simplification
2 parents c4de99d + 920c4ab commit 26ade4c

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

composeApp/src/commonMain/kotlin/dev/johnoreilly/climatetrace/viewmodel/CountryDetailsViewModel.kt

+3-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import app.cash.molecule.RecompositionMode
1010
import app.cash.molecule.launchMolecule
1111
import com.rickclephas.kmp.observableviewmodel.ViewModel
1212
import com.rickclephas.kmp.observableviewmodel.coroutineScope
13-
import com.rickclephas.kmp.observableviewmodel.launch
1413
import dev.johnoreilly.climatetrace.data.ClimateTraceRepository
1514
import dev.johnoreilly.climatetrace.remote.Country
1615
import dev.johnoreilly.climatetrace.remote.CountryAssetEmissionsInfo
@@ -42,22 +41,18 @@ sealed interface CountryDetailsEvents {
4241
open class CountryDetailsViewModel : ViewModel(), KoinComponent {
4342
private val climateTraceRepository: ClimateTraceRepository by inject()
4443

45-
private val events = MutableSharedFlow<CountryDetailsEvents>()
44+
private val events = MutableSharedFlow<CountryDetailsEvents>(extraBufferCapacity = 20)
4645

4746
val viewState: StateFlow<CountryDetailsUIState> = viewModelScope.coroutineScope.launchMolecule(mode = RecompositionMode.Immediate) {
4847
CountryDetailsPresenter(events)
4948
}
5049

5150
fun setYear(year: String) {
52-
viewModelScope.launch {
53-
events.emit(CountryDetailsEvents.SetYear(year))
54-
}
51+
events.tryEmit(CountryDetailsEvents.SetYear(year))
5552
}
5653

5754
fun setCountry(country: Country) {
58-
viewModelScope.launch {
59-
events.emit(CountryDetailsEvents.SetCountry(country))
60-
}
55+
events.tryEmit(CountryDetailsEvents.SetCountry(country))
6156
}
6257

6358
@Composable

0 commit comments

Comments
 (0)