Skip to content

Commit c6bf972

Browse files
authored
Improve instructions for lazy functions (#109)
1 parent c79d4fd commit c6bf972

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,41 @@ plugins {
2828

2929
## Lazy functions
3030

31+
Puts a function in a separate JS chunk. The chunk will be loaded when the function is called the first time.
32+
33+
#### Setup
34+
35+
Add the dependency `kotlin-js` of [Kotlin Wrappers](https://github.com/JetBrains/kotlin-wrappers) to your project.
36+
37+
```kotlin
38+
// root settings.gradle.kts
39+
dependencyResolutionManagement {
40+
repositories {
41+
mavenCentral()
42+
}
43+
44+
versionCatalogs {
45+
create("kotlinWrappers") {
46+
val wrappersVersion = "2025.6.0"
47+
from("org.jetbrains.kotlin-wrappers:kotlin-wrappers-catalog:$wrappersVersion")
48+
}
49+
}
50+
}
51+
```
52+
53+
```kotlin
54+
// build.gradle.kts
55+
sourceSets {
56+
jsMain {
57+
dependencies {
58+
implementation(kotlinWrappers.js)
59+
}
60+
}
61+
}
62+
```
63+
64+
#### Usage
65+
3166
```kotlin
3267
// App.kt
3368
suspend fun main() {
@@ -43,9 +78,11 @@ suspend fun main() {
4378
}
4479

4580
// createCalculationWithHeavyLibrary.kt
81+
import js.lazy.Lazy
82+
import js.lazy.LazyFunction
83+
4684
/**
47-
* - Function will be located in separate JS chunk
48-
* - Chunk will be loaded when function will be called first time
85+
* Function will be located in separate JS chunk
4986
*/
5087
@Lazy
5188
val createCalculationWithHeavyLibrary = LazyFunction<Int> {

0 commit comments

Comments
 (0)