Skip to content
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

Merged
merged 1 commit into from
Feb 20, 2024

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Feb 17, 2024

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 native onclick should be sufficient, and I think I'm going to push for this being default in the ember learning materials

The 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:

Current This PR

image

image

image

image

OS: Ubuntu 23.10 mantic
Kernel: x86_64 Linux 6.5.0-15-generic
Uptime: 10d 1h 29m
Packages: 1863
Shell: bash 5.2.15
Resolution: 2256x1504
DE: GNOME 45.0
WM: Mutter
WM Theme: Adwaita
GTK Theme: Yaru-dark [GTK2/3]
Icon Theme: Yaru
Font: Ubuntu 11
Disk: 88G / 458G (21%)
CPU: AMD Ryzen 5 7640U w/ Radeon 760M Graphics @ 12x 4.971GHz
GPU: AMD/ATI
RAM: 14358MiB / 63474MiB

image

@krausest
Copy link
Owner

Thanks. I'll try to post results tomorrow.

@NullVoxPopuli NullVoxPopuli deleted the ember-use-native-on-click branch February 20, 2024 22:09
@@ -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>

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..

Copy link
Contributor Author

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)

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?

Copy link
Contributor Author

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)

@krausest
Copy link
Owner

Meanwhile chrome 122 was released. So it'll be included in the chrome 122 results soon.

@krausest
Copy link
Owner

Now they're available: https://krausest.github.io/js-framework-benchmark/2024/table_chrome_122.0.6261.69.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants