Skip to content

Commit

Permalink
Updated protected ViewModel.actions property to be ViewModel.actionEv…
Browse files Browse the repository at this point in the history
…ents
  • Loading branch information
Chris committed Apr 14, 2023
1 parent e09f4c3 commit 00fe6ed
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cycle-core/src/commonMain/kotlin/com.chrynan.cycle/ViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ abstract class ViewModel<State, Change>(
}

/**
* A [MutableStateFlow] of [Action]s that represent the [Action]s being performed via calls to the [perform]
* function.
* A [MutableStateFlow] of [Action] [Event]s that represent the [Action]s being performed via calls to the
* [perform] function.
*/
protected val actions = MutableStateFlow<Action<State, Change>?>(null)
protected val actionEvents = MutableStateFlow<Event<Action<State, Change>?>?>(null)

private lateinit var job: Job

Expand Down Expand Up @@ -157,7 +157,7 @@ abstract class ViewModel<State, Change>(
* producing a new [State].
*/
protected open fun perform(action: Action<State, Change>) {
actions.value = action
actionEvents.value = Event(action)
}

/**
Expand All @@ -178,7 +178,7 @@ abstract class ViewModel<State, Change>(
* Presenter is not already bound.
*/
protected open fun onBind() {
actions.filterNotNull()
actionEvents.mapNotNull { it?.value }
.flatMap(flatMapStrategy) { it.invoke(currentState) }
.onEach { stateStore.dispatch(it) }
.launchIn(coroutineScope)
Expand Down

0 comments on commit 00fe6ed

Please sign in to comment.