Patrick Jackson
08/28/2019, 2:15 PMtypealias SealedReducer<TState, TAction> = (state: TState, action: TAction) -> TState
typealias SealedReducer<TState, TAction> = (state: TState, action: TAction) -> TState
inline fun <TState, reified TAction> sealedReducer(crossinline reducer: SealedReducer<TState, TAction>): Reducer<TState> {
return {state, action ->
if (action is TAction) {
reducer(state, action)
} else {
state
}
}
}
sealed class LoginScreenAction
class LoginButtonTap: LoginScreenAction()
val loginScreenReducer = sealedReducer<TestState, LoginScreenAction> { state, action ->
when(action) {
is LoginButtonTap -> state
}
}
Patrick Jackson
08/28/2019, 2:49 PM