Slide 68
Slide 68 text
45
class MonsterListStateMachine(private val repository: MonsterRepository)
: StateMachine(
builder = {
state {
process { loadMonsterList(0, repository, ::emit) }
reduce { MonsterListState.Loading }
}
state {
reduce { MonsterListState.Stable.List(action.monsterList) }
reduce { MonsterListState.Error(action.error) }
}
state {
process { emit(MonsterListAction.NavigateDetails(intent.monster)) }
}
state {
process { loadMonsterList(state.currentOffset, repository, ::emit) }
reduce { MonsterListState.Stable.PageLoading(state.monsterList) }
}
state {
reduce { MonsterListState.Stable.List(state.monsterList + action.monsterList) }
reduce { MonsterListState.Stable.PageError(state.monsterList, action.error) }
}
state {
process { loadMonsterList(state.currentOffset, repository, ::emit) }
reduce { MonsterListState.Stable.PageLoading(state.monsterList) }
}
state {
process { loadMonsterList(0, repository, ::emit) }
reduce { MonsterListState.Loading }
}
}
)