Skip to content

Commit

Permalink
feat: added default parameter in controller factory
Browse files Browse the repository at this point in the history
  • Loading branch information
y9san9 committed May 9, 2024
1 parent 67b093d commit fa7457a
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ androidx-lifecycle = "2.7.0"
ktgbotapi = "11.0.0"
mdi = "0.0.38"

ksm = "0.0.36"
ksm = "0.0.37"

[libraries]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package ksm.navigation.compose
import ksm.context.StateContext
import ksm.navigation.NavigationController
import ksm.plugin.PluginController
import ksm.plugin.factory.ControllerFactory
import ksm.plugin.factory.StateControllerFactory
import kotlin.reflect.KType
import kotlin.reflect.typeOf

public interface ComposeController : NavigationController {
public interface Builder : NavigationController.Builder

public companion object : ControllerFactory {
public companion object : StateControllerFactory {
override val type: KType = typeOf<ComposeController>()

override fun wrap(context: StateContext): PluginController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import ksm.navigation.stack.installStackPlugin
import ksm.navigation.state.name.installStateName
import ksm.navigation.state.parameters.installStateParameters
import ksm.navigation.state.route.installStateRoute
import ksm.plugin.factory.ControllerFactory
import ksm.plugin.factory.StateControllerFactory
import ksm.plugin.pluginRuntime
import kotlin.reflect.KType

@LibraryApi
public inline fun NavigationController.Builder.navigationRuntime(
controllerFactory: ControllerFactory,
controllerFactory: StateControllerFactory,
enableConfiguration: Boolean = true,
enableLifecycle: Boolean = true,
enableFinishOnce: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package ksm.plugin

import ksm.annotation.LibraryApi
import ksm.plugin.configuration.installConfiguration
import ksm.plugin.factory.ControllerFactory
import ksm.plugin.factory.StateControllerFactory
import ksm.plugin.factory.installControllerFactory
import ksm.plugin.finish.installFinishOnce
import ksm.plugin.lifecycle.installLifecycle
import kotlin.reflect.KType

@LibraryApi
public inline fun PluginController.Builder.pluginRuntime(
controllerFactory: ControllerFactory,
controllerFactory: StateControllerFactory,
enableConfiguration: Boolean = true,
enableLifecycle: Boolean = true,
enableFinishOnce: Boolean = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import ksm.plugin.factory.plugin.ControllerFactoryPlugin
import ksm.plugin.install

@OptIn(LibraryApi::class)
public fun PluginController.Builder.installControllerFactory(factory: ControllerFactory) {
public fun PluginController.Builder.installControllerFactory(factory: StateControllerFactory) {
install(ControllerFactoryPlugin(factory))
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ksm.plugin.PluginController
import ksm.plugin.factory.plugin.ControllerFactoryPlugin
import ksm.plugin.plugin

public val StateContext.controllerFactory: ControllerFactory
public val StateContext.controllerFactory: StateControllerFactory
get() = plugin(ControllerFactoryPlugin).factory

public inline fun <reified T : PluginController> StateContext.asController(): T {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ksm.context.StateContext
import ksm.plugin.PluginController
import kotlin.reflect.KType

public interface ControllerFactory {
public interface StateControllerFactory {
public val type: KType
public fun wrap(context: StateContext): PluginController
public fun wrap(context: StateContext = StateContext.Empty): PluginController
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package ksm.plugin.factory.plugin
import ksm.annotation.MutateContext
import ksm.context.StateContext
import ksm.plugin.Plugin
import ksm.plugin.factory.ControllerFactory
import ksm.plugin.factory.StateControllerFactory

public class ControllerFactoryPlugin(
public val factory: ControllerFactory
public val factory: StateControllerFactory
) : Plugin {
override val key: Companion = ControllerFactoryPlugin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import ksm.annotation.LibraryApi
import ksm.context.StateContext
import ksm.context.createChildContext
import ksm.plugin.PluginController
import ksm.plugin.factory.ControllerFactory
import ksm.plugin.factory.StateControllerFactory
import ksm.plugin.factory.asController
import kotlin.reflect.KType
import kotlin.reflect.typeOf

public interface ViewModelController : PluginController {
public interface Builder : PluginController.Builder

public companion object : ControllerFactory {
public companion object : StateControllerFactory {
override val type: KType = typeOf<ViewModelController>()

override fun wrap(context: StateContext): PluginController {
Expand Down

0 comments on commit fa7457a

Please sign in to comment.