Skip to content

Remove the need for null at the end of Promise<T> and GlobalEventHandlers lambdas #18

Open
@sdeleuze

Description

@sdeleuze

As seen in https://github.com/wasm-outbound-http-examples/kotlin/blob/main/browser/src/wasmJsMain/kotlin/Main.kt or some Spring + Kotlin/Wasm samples I have been working on, the requirement to return null as the latest statement of some lambdas in some APIs exposed by kotlinx-browser is a significant DevXP issue as it makes the Kotlin code IMO unnecessarily ugly and can block newcomers who will not understand that requirement. For example:

fun main() {
    window.fetch("https://httpbin.org/anything").then {
        if (it.ok) {
            it.text().then {
                println(it)
                null
            }
        }
        null
    }
}

It impacts at least Promise<T> based APIs and event handlers like those defined in GlobalEventHandlers, potentially other APIs too.

It would be a big DevXP improvement if that could be fixed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions