1
0
Fork 0
fenix/app/src/main/java/org/mozilla/fenix/home/sessions/SessionsComponent.kt

47 lines
1.4 KiB
Kotlin
Raw Normal View History

2019-01-28 17:46:39 +01:00
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.home.sessions
import android.view.ViewGroup
import mozilla.components.browser.session.Session
2019-01-30 17:36:14 +01:00
import org.mozilla.fenix.mvi.Action
import org.mozilla.fenix.mvi.ActionBusFactory
import org.mozilla.fenix.mvi.Change
import org.mozilla.fenix.mvi.UIComponent
import org.mozilla.fenix.mvi.ViewState
2019-01-28 17:46:39 +01:00
class SessionsComponent(
private val container: ViewGroup,
2019-01-31 07:49:41 +01:00
bus: ActionBusFactory,
2019-01-28 17:46:39 +01:00
override var initialState: SessionsState = SessionsState(emptyList())
) :
2019-01-31 07:49:41 +01:00
UIComponent<SessionsState, SessionsAction, SessionsChange>(
bus.getManagedEmitter(SessionsAction::class.java),
bus.getSafeManagedObservable(SessionsChange::class.java)
) {
2019-01-28 17:46:39 +01:00
2019-01-30 17:36:14 +01:00
override val reducer: (SessionsState, SessionsChange) -> SessionsState = { state, change ->
2019-01-28 17:46:39 +01:00
when (change) {
is SessionsChange.Changed -> state // copy state with changes here
2019-01-28 17:46:39 +01:00
}
}
2019-01-31 07:49:41 +01:00
override fun initView() = SessionsUIView(container, actionEmitter, changesObservable)
2019-01-28 17:46:39 +01:00
init {
2019-01-28 17:46:39 +01:00
render(reducer)
}
}
data class SessionsState(val sessions: List<Session>) : ViewState
sealed class SessionsAction : Action {
object Select : SessionsAction()
}
sealed class SessionsChange : Change {
object Changed : SessionsChange()
2019-01-28 17:46:39 +01:00
}