All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.react.EffectBuilder.kt Maven / Gradle / Ivy

@file:Suppress("NOTHING_TO_INLINE")

package react

import kotlinx.js.ReadonlyArray

// TODO: make external in IR
class EffectBuilder
private constructor() {
    inline fun cleanup(
        noinline block: Cleanup,
    ) {
        asDynamic().push(block)
    }
}

internal fun createEffectCallback(
    effect: EffectBuilder.() -> Unit,
): () -> Cleanup? = {
    val cleanups = arrayOf()
    effect(cleanups.unsafeCast())
    buildCleanup(cleanups)
}

private fun buildCleanup(
    cleanups: ReadonlyArray,
): Cleanup? {
    if (cleanups.isEmpty())
        return undefined

    return {
        for (cleanup in cleanups)
            cleanup()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy