Click.capture... ftw

I certainly hope this hasn’t changed in vNext…

TIL I can use click.capture to add content to the $event object
click.capture="$event['someVar'] = data"
then with…
click.delegate="someFunc($event)"
someFunc can access “someVar” on the event parameter! (As long as the .capture is on a bubbled container)

Simplistic example, but this creates some very interesting capabilities!

Thank you and +1 Aurelia team!
Kremnari

3 Likes

That looks ninja. Maybe, too ninja? I can see myself scratching a hole into my temple looking at that $event object in the view model thinking, where the heck did someVarproperty come from?

1 Like

A ninja practices one move at a time… until it is done as part of a dance of many…

In my code, I’m using a function to namespace those variables on $event, and it’ll eventually be abstracted a step up further and only added to elements during code execution/template generation.

1 Like

Out of curiosity, wouldn’t

click.delegate="someFunc($event, data)"

also work (and have one less moving part)?

Yes for simple use cases.

I’m working towards a multi-touch command/event dispatcher. I’m not just concerned about what data is, but what it’s representing; so separating those calls out to their respective elements makes it cleaner (to my eyes at least).

Wow. I’ve never really seen .capture used before, this is intriguing.