raamcosta / compose-destinations

Annotation processing library for type-safe Jetpack Compose navigation with no boilerplate.
https://composedestinations.rafaelcosta.xyz
Apache License 2.0
3.22k stars 133 forks source link

Compile time dependencies check #234

Open epool opened 2 years ago

epool commented 2 years ago

let's say I have a composable with some dependencies.

@RootNavGraph
@Composable
@Destination
fun SomeScreen(
    dependency1: Dependency1,
    dependency2: Dependency2,
)

...

DestinationsNavHost(
    navGraph = NavGraphs.root,
    dependenciesContainerBuilder = {
        dependency(dependency1)
        // dependency(dependency2) force a compile error if we forget to satisfy this dependency.
    },
)

is there a way to ensure that the dependencies of the above composable are satisfied at compile time like dagger/hilt does instead of doing it at runtime?

this to avoid forgetting to pass the dependency and realise about it once the whole project has been compiled and run.

raamcosta commented 2 years ago

Hi!

I already thought of this, but the thing is people can choose to manually call their Composables, at which point it's really impossible to tell at compile time whether there is a missing dependency or the developer is just doing that (calling it manually). Maybe we could use some other annotation to explicitly tell the library that we're doing that..

I'll keep this open as a possible future enhancement. I also don't think that this is a major issue as the app crashes at the earliest chance and the developer will surely notice it once they run the app. As you said, the only issue is losing some time for builds..