Skip to content

[Ember]: Use native onclick #1608

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

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frameworks/keyed/ember/app/components/my-table.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<td class="col-md-1"><a onclick={{fn this.remove item}}><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td>
<td class="col-md-6"></td>
</tr>
{{/each}}
Expand Down