Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize HTML's Breakdown performance #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ object Dependencies {
const val KOTLIN_REACT = "org.jetbrains.kotlin-wrappers:kotlin-react:${Versions.KOTLIN_REACT}"
const val KOTLIN_REACT_DOM = "org.jetbrains.kotlin-wrappers:kotlin-react-dom-legacy:${Versions.KOTLIN_REACT}"
const val KOTLIN_REACT_ROUTER = "org.jetbrains.kotlin-wrappers:kotlin-react-router-dom:${Versions.KOTLIN_REACT_ROUTER}"
const val KOTLIN_REACT_VIRTUAL = "org.jetbrains.kotlin-wrappers:kotlin-react-virtual:${Versions.KOTLIN_REACT_VIRTUAL}"
const val KOTLIN_JS_EXTENSIONS = "org.jetbrains.kotlin-wrappers:kotlin-extensions:${Versions.KOTLIN_JS_EXTENSIONS}"
const val KOTLIN_REACT_FUNCTION = "com.bnorm.react:kotlin-react-function:${Versions.KOTLIN_REACT_FUNCTION}"

Expand Down Expand Up @@ -76,6 +77,7 @@ object Dependencies {

const val KOTLIN_REACT = "18.0.0-pre.330-kotlin-1.6.20" // https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-react
const val KOTLIN_REACT_ROUTER = "6.3.0-pre.330-kotlin-1.6.20" // https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-react-router-dom
const val KOTLIN_REACT_VIRTUAL = "2.10.4-pre.330-kotlin-1.6.20" // https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-react-virtual
const val KOTLIN_JS_EXTENSIONS = "1.0.1-pre.330-kotlin-1.6.20" // https://mvnrepository.com/artifact/org.jetbrains.kotlin-wrappers/kotlin-extensions

const val SELENIUM_WEBDRIVER = "4.1.3" // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
Expand Down
1 change: 1 addition & 0 deletions ruler-frontend/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies {
implementation(Dependencies.KOTLIN_JS_EXTENSIONS)
implementation(Dependencies.KOTLIN_REACT_FUNCTION)
implementation(Dependencies.KOTLINX_SERIALIZATION_JSON)
implementation(Dependencies.KOTLIN_REACT_VIRTUAL)

implementation(npm(Dependencies.REACT, Dependencies.Versions.REACT))
implementation(npm(Dependencies.REACT_DOM, Dependencies.Versions.REACT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ import com.spotify.ruler.models.AppComponent
import com.spotify.ruler.models.AppFile
import com.spotify.ruler.models.Measurable
import kotlinx.html.id
import org.w3c.dom.HTMLElement
import react.RBuilder
import react.dom.button
import react.dom.div
import react.dom.h2
import react.dom.h4
import react.dom.span
import react.useRef
import react.virtual.VirtualOptions
import react.virtual.useVirtual

@RFunction
fun RBuilder.breakdown(components: List<AppComponent>, sizeType: Measurable.SizeType) {
Expand All @@ -40,9 +44,23 @@ fun RBuilder.breakdown(components: List<AppComponent>, sizeType: Measurable.Size

@RFunction
fun RBuilder.componentList(components: List<AppComponent>, sizeType: Measurable.SizeType) {
val useRef = useRef<HTMLElement>()
val virtualOptions: VirtualOptions<HTMLElement> = js("{}")
val virtual = useVirtual(
options = virtualOptions.apply {
size = components.size
parentRef = useRef
}
)
div(classes = "accordion") {
components.forEachIndexed { index, component ->
componentListItem(index, component, sizeType, component.name)
ref = useRef
virtual.virtualItems.forEachIndexed { index, virtualItem ->
componentListItem(
virtualItem.index,
components[index],
sizeType,
components[index].name
)
}
}
}
Expand Down