Skip to content

Instantly share code, notes, and snippets.

@dellisd
Created December 21, 2021 01:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dellisd/90a0d26ba49e620a5f7026e73ff6748d to your computer and use it in GitHub Desktop.
Save dellisd/90a0d26ba49e620a5f7026e73ff6748d to your computer and use it in GitHub Desktop.
Compose for Web + kotlin-inject
@Component
abstract class AppComponent {
@Provides
protected fun test(): Test = Test("Inject")
abstract val application: Application
}
typealias Application = @Composable () -> Unit
@Inject
@Composable
fun Application(test: Test) {
Div {
Text(test.giveThing())
}
}
fun main() {
val component = AppComponent::class.create()
renderComposable(rootElementId = "root") {
// Displays "Hello Inject!"
component.application()
}
}
class Test(private val message: String) {
fun giveThing(): String = "Hello $message!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment