Created
December 21, 2021 01:53
-
-
Save dellisd/90a0d26ba49e620a5f7026e73ff6748d to your computer and use it in GitHub Desktop.
Compose for Web + kotlin-inject
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
abstract class AppComponent { | |
@Provides | |
protected fun test(): Test = Test("Inject") | |
abstract val application: Application | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias Application = @Composable () -> Unit | |
@Inject | |
@Composable | |
fun Application(test: Test) { | |
Div { | |
Text(test.giveThing()) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main() { | |
val component = AppComponent::class.create() | |
renderComposable(rootElementId = "root") { | |
// Displays "Hello Inject!" | |
component.application() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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