Skip to content

Move from return false to m.capture(event) for event handlers #2681

@dead-claudia

Description

@dead-claudia

Mithril version:

Platform and OS:

Project:

Is this something you're interested in implementing yourself?

Description

m.capture = event => {
    event.preventDefault()
    event.stopPropagation()
}

And also remove the return value handling logic from this section.

Why

I want to see this idiom die, just as it's largely died elsewhere:

m("button", {
    onclick() {
        doStuff()
        return false
    }
}, "bottom text")

Also, it's not compatible with async functions as event handlers.

m("button", {
    async onclick() {
        await doStuff()
        return false // Doesn't work like it looks like it does!
    }
}, "bottom text")

Oh, and it'll likely result in a small but measurable net reduction in size compared to what we already do to support return false.

Possible Implementation

See description.

Open Questions

I think the real discussion is should we continue to support the return false that standards bodies have effectively declared as legacy?

Metadata

Metadata

Assignees

Labels

Area: CoreFor anything dealing with Mithril core itselfType: Breaking ChangeFor any feature request or suggestion that could reasonably break existing codeType: EnhancementFor any feature request or suggestion that isn't a bug fix

Type

No type

Projects

Status

Completed/Declined

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions