Skip to content

Commit

Permalink
fun test function handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
stslex committed Dec 9, 2024
1 parent 952190f commit 1bfba22
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ interface Store<out S : State, in A : Action, out E : Event> {

interface State

interface Event {

data class Handler(val action: Action) : Event
}
interface Event

interface Action {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,8 @@ import kotlin.reflect.KClass

abstract class Handler<S : State, A : StoreAction, E : Event, StoreAction : Action>(val actionKClass: KClass<*>) {

val handlerName: String = requireNotNull(actionKClass.simpleName) {
"Action class name is null"
}

inline fun checkAction(action: StoreAction): Boolean = actionKClass.isInstance(action)

abstract fun HandlerStore<S, StoreAction, E>.invoke(action: A)

override fun toString(): String = handlerName

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is Handler<*, *, *, *>) return false
return handlerName == other.handlerName
}

override fun hashCode(): Int = handlerName.hashCode()

}
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package com.stslex.wizard.feature.profile.mvi

import com.stslex.wizard.core.ui.mvi.v2.Handler
import com.stslex.wizard.core.ui.mvi.v2.HandlerStore
import com.stslex.wizard.core.ui.mvi.v2.handler
import com.stslex.wizard.feature.profile.ui.store.ProfileStore.Action
import com.stslex.wizard.feature.profile.ui.store.ProfileStore.Action.Click
import com.stslex.wizard.feature.profile.ui.store.ProfileStore.Event
import com.stslex.wizard.feature.profile.ui.store.ProfileStore.State

class ClickersHandler : Handler<State, Click, Event, Action>(Click::class) {

override fun HandlerStore<State, Action, Event>.invoke(action: Click) {
when (action) {
Click.BackButtonClick -> sendAction(Action.Navigation.Back)
Click.FavouriteClick -> sendAction(Action.Navigation.Favourite(state.value.uuid))
Click.FollowersClick -> sendAction(Action.Navigation.Followers(state.value.uuid))
Click.FollowingClick -> sendAction(Action.Navigation.Following(state.value.uuid))
Click.SettingsClick -> sendAction(Action.Navigation.Settings)
}
fun clickersHandler(): Handler<State, Click, Event, Action> = handler { action ->
when (action) {
Click.BackButtonClick -> sendAction(Action.Navigation.Back)
Click.FavouriteClick -> sendAction(Action.Navigation.Favourite(state.value.uuid))
Click.FollowersClick -> sendAction(Action.Navigation.Followers(state.value.uuid))
Click.FollowingClick -> sendAction(Action.Navigation.Following(state.value.uuid))
Click.SettingsClick -> sendAction(Action.Navigation.Settings)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import com.stslex.wizard.core.database.store.UserStore
import com.stslex.wizard.core.navigation.navigator.Navigator
import com.stslex.wizard.core.ui.mvi.v2.BaseStore
import com.stslex.wizard.feature.profile.domain.interactor.ProfileInteractor
import com.stslex.wizard.feature.profile.mvi.ClickersHandler
import com.stslex.wizard.feature.profile.mvi.InitStorageHandler
import com.stslex.wizard.feature.profile.mvi.LogoutHandler
import com.stslex.wizard.feature.profile.mvi.NavigationHandler
import com.stslex.wizard.feature.profile.mvi.RepeatLastActionHandler
import com.stslex.wizard.feature.profile.mvi.clickersHandler
import com.stslex.wizard.feature.profile.ui.store.ProfileStore.Action
import com.stslex.wizard.feature.profile.ui.store.ProfileStore.Event
import com.stslex.wizard.feature.profile.ui.store.ProfileStore.State
Expand All @@ -23,7 +23,8 @@ class ProfileStoreImpl(
InitStorageHandler(interactor, userStore),
LogoutHandler(interactor),
RepeatLastActionHandler(),
ClickersHandler(),
clickersHandler(),
NavigationHandler(navigator)
)
)

0 comments on commit 1bfba22

Please sign in to comment.