ModuleLogic
Base class for module logic implementations.
Logic classes handle side effects, async operations, and complex business logic. Define public suspend methods for operations that can be called from Composables or other Logic classes.
Example:
class UserLogic(private val storeAccessor: StoreAccessor) : ModuleLogic() {
private val api = UserApi()
suspend fun loadUser(userId: String) {
storeAccessor.dispatch(UserAction.SetLoading(true))
try {
val user = api.fetchUser(userId)
storeAccessor.dispatch(UserAction.SetUser(user))
} catch (e: Exception) {
storeAccessor.dispatch(UserAction.SetError(e.message))
} finally {
storeAccessor.dispatch(UserAction.SetLoading(false))
}
}
suspend fun logout() {
api.logout()
storeAccessor.dispatch(UserAction.ClearUser)
}
}Content copied to clipboard
Parameters
A
The action type this logic handles