-
Notifications
You must be signed in to change notification settings - Fork 842
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
[Ember]: Use native onclick #1608
[Ember]: Use native onclick #1608
Conversation
Thanks. I'll try to post results tomorrow. |
@@ -116,8 +116,8 @@ export default class MyTable extends Component { | |||
{{#each this.data key="id" as |item|}} | |||
<tr class={{if (eq item.id this.selected) 'danger'}}> | |||
<td class="col-md-1">{{item.id}}</td> | |||
<td class="col-md-4"><a {{on 'click' (fn this.select item)}}>{{item.label}}</a></td> | |||
<td class="col-md-1"><a {{on 'click' (fn this.remove item)}}><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td> | |||
<td class="col-md-4"><a onclick={{fn this.select item}}>{{item.label}}</a></td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NullVoxPopuli didn't know you could do this..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ye, it's very nice -- I made a little decision tree to help with deciding between native event handlers and "event handlers with cleanup (on)": emberjs/rfcs#1007 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is cleanup necessary? Like components that get removed from view? Or ssr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanup is needed when:
- dynamic modifier is used (via a condition)
- or when the handler could change (the function itself)
Meanwhile chrome 122 was released. So it'll be included in the chrome 122 results soon. |
Now they're available: https://krausest.github.io/js-framework-benchmark/2024/table_chrome_122.0.6261.69.html |
It's idiomatic to use
{{on}}
for event listening, and{{on}}
is the only way to have conditionally applied / dynamic event listeners, but for performance sensitive situations, we can do less by using the platform, and we don't need any cleanup behavior, so nativeonclick
should be sufficient, and I think I'm going to push for this being default in the ember learning materialsThe improvement to speed is noticeable
There was a concern mentioned by a community member about
onclick
only being able to be set once, but here is how this works in a real app, and it appears to update as one would expect.Results: