Giter VIP home page Giter VIP logo

kinzhal's People

Contributors

daugeldauge avatar kr1sis avatar vganin avatar zagayevskiy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

kinzhal's Issues

Support assisted injection

It would be convenient with library such as Decompose. Decompose Components are created by hand in factory lambda and must be initialized with ComponentContext provided from parent.

I'll demonstrate with example. Here what we must do with Decompose without auto DI

class RootComponent(
    componentContext: ComponentContext
) : ComponentContext by componentContext {

    val navigation = StackNavigation<Config>()

    val stack =
        childStack(
            source = navigation,
            initialConfiguration = Config.List,
            handleBackButton = true,
            childFactory = ::createChild,
        )

    fun createChild(config: Config, componentContext: ComponentContext): ComponentContext =
        // Here we must use provided componentContext to create child component
        when (config) {
            is Config.List -> ListComponent(componentContext, ???) // Where to get depA, depB, depC, etc.???
            is Config.Details -> // ...
        }

    sealed class Config : Parcelable {
        @Parcelize
        object List : Config()

        @Parcelize
        data class Details(val itemId: Long) : Config()
    }
}

class ListComponent(
    componentContext: ComponentContext,
    depA: DepA,
    depB: DepB,
    depC: DepC,
    // ...
) : ComponentContext by componentContext {
    // ...
} 

We can improve this example with assisted injection like so

class RootComponent @Inject constructor(
    componentContext: ComponentContext,
    listComponentFactory: ListComponentFactory,
    // Rest component factories
) : ComponentContext by componentContext {

    val navigation = StackNavigation<Config>()

    val stack =
        childStack(
            source = navigation,
            initialConfiguration = Config.List,
            handleBackButton = true,
            childFactory = ::createChild,
        )

    fun createChild(config: Config, componentContext: ComponentContext): ComponentContext =
        when (config) {
            is Config.List -> listComponentFactory.create(componentContext)
            is Config.Details -> // ...
        }
}

@AssistedFactory
interface ListComponentFactory {
    fun create(componentContext: ComponentContext): ListComponent
} 

class ListComponent @AssistedInject constructor(
    @Assisted componentContext: ComponentContext,
    depA: DepA,
    depB: DepB,
    depC: DepC,
    // ...
) : ComponentContext by componentContext {
    // ...
}

Support scope validation

It's possible to create component which provides dependencies with wrong scopes, because there are no such checks here:

https://github.com/daugeldauge/kinzhal/blob/master/kinzhal-processor/src/jvmMain/kotlin/com/daugeldauge/kinzhal/processor/KinzhalSymbolProcessor.kt#L12

https://github.com/daugeldauge/kinzhal/blob/64f84c2dd0c251a89f3c66703858e5b627dddf9d/kinzhal-processor/src/jvmMain/kotlin/com/daugeldauge/kinzhal/processor/generation/FactoryGenerator.kt#L29C4-L29C4

Example:

// Unscoped component, or component with some another scope
interface Component(modules = [FooModule::class]) {
    ...
}

object FooModule {
    @Foo // Some scope here
    fun provideFoo() : Foo{
        ...
    }
}

This compiles fine and scope will work for Foo, however it's confusing because this scope is not attached to the current component

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.