-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
93 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 2 additions & 7 deletions
9
core/ui/mvi/src/commonMain/kotlin/com/stslex/wizard/core/ui/mvi/v2/Handler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
package com.stslex.wizard.core.ui.mvi.v2 | ||
|
||
import com.stslex.wizard.core.ui.mvi.Store.Action | ||
import com.stslex.wizard.core.ui.mvi.Store.Event | ||
import com.stslex.wizard.core.ui.mvi.Store.State | ||
import kotlin.reflect.KClass | ||
|
||
abstract class Handler<S : State, A : StoreAction, E : Event, StoreAction : Action>(val actionKClass: KClass<*>) { | ||
fun interface Handler<A : Action, TStore : HandlerStore<*, *, *>> { | ||
|
||
inline fun checkAction(action: StoreAction): Boolean = actionKClass.isInstance(action) | ||
|
||
abstract fun HandlerStore<S, StoreAction, E>.invoke(action: A) | ||
fun TStore.invoke(action: A) | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
core/ui/mvi/src/commonMain/kotlin/com/stslex/wizard/core/ui/mvi/v2/HandlerCreator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.stslex.wizard.core.ui.mvi.v2 | ||
|
||
import com.stslex.wizard.core.ui.mvi.Store.Action | ||
import com.stslex.wizard.core.ui.mvi.Store.Event | ||
import com.stslex.wizard.core.ui.mvi.Store.State | ||
|
||
fun interface HandlerCreator<S : State, A : Action, E : Event, HStore : HandlerStore<S, A, E>> { | ||
|
||
operator fun invoke(action: A): Handler<*, HStore> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
...re/profile/src/commonMain/kotlin/com/stslex/wizard/feature/profile/mvi/ClickersHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +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.handler | ||
import com.stslex.wizard.feature.profile.ui.store.ProfileHandlerStore | ||
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 | ||
|
||
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) | ||
class ClickersHandler : Handler<Action.Click, ProfileHandlerStore> { | ||
|
||
override fun ProfileHandlerStore.invoke(action: Action.Click) { | ||
when (action) { | ||
Action.Click.BackButtonClick -> sendAction(Action.Navigation.Back) | ||
Action.Click.FavouriteClick -> sendAction(Action.Navigation.Favourite(state.value.uuid)) | ||
Action.Click.FollowersClick -> sendAction(Action.Navigation.Followers(state.value.uuid)) | ||
Action.Click.FollowingClick -> sendAction(Action.Navigation.Following(state.value.uuid)) | ||
Action.Click.SettingsClick -> sendAction(Action.Navigation.Settings) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...e/src/commonMain/kotlin/com/stslex/wizard/feature/profile/ui/store/ProfileHandlerStore.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.stslex.wizard.feature.profile.ui.store | ||
|
||
import com.stslex.wizard.core.ui.mvi.v2.HandlerStore | ||
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 | ||
|
||
interface ProfileHandlerStore : ProfileStore, HandlerStore<State, Action, Event> |
31 changes: 16 additions & 15 deletions
31
...file/src/commonMain/kotlin/com/stslex/wizard/feature/profile/ui/store/ProfileStoreImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,31 @@ | ||
package com.stslex.wizard.feature.profile.ui.store | ||
|
||
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 | ||
|
||
class ProfileStoreImpl( | ||
interactor: ProfileInteractor, | ||
userStore: UserStore, | ||
navigator: Navigator | ||
) : ProfileStore, BaseStore<State, Action, Event>( | ||
initStorageHandler: InitStorageHandler, | ||
logoutHandler: LogoutHandler, | ||
repeatLastActionHandler: RepeatLastActionHandler, | ||
clickersHandler: ClickersHandler, | ||
navigationHandler: NavigationHandler | ||
) : ProfileHandlerStore, BaseStore<State, Action, Event, ProfileHandlerStore>( | ||
initialState = State.INITIAL, | ||
handlers = setOf( | ||
InitStorageHandler(interactor, userStore), | ||
LogoutHandler(interactor), | ||
RepeatLastActionHandler(), | ||
clickersHandler(), | ||
NavigationHandler(navigator) | ||
) | ||
handlerCreator = { action -> | ||
when (action) { | ||
is Action.Init -> initStorageHandler | ||
is Action.Logout -> logoutHandler | ||
is Action.RepeatLastAction -> repeatLastActionHandler | ||
is Action.Click -> clickersHandler | ||
is Action.Navigation -> navigationHandler | ||
} | ||
} | ||
) | ||
|