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

Optimize locally-scoped event listeners #4495

Open
nolanlawson opened this issue Aug 27, 2024 · 1 comment
Open

Optimize locally-scoped event listeners #4495

nolanlawson opened this issue Aug 27, 2024 · 1 comment

Comments

@nolanlawson
Copy link
Collaborator

nolanlawson commented Aug 27, 2024

Currently we don't optimize event listeners that reference a local variable, for example in a for-loop:

<template for:each={list} for:item="task">
    <button key={task.id} onclick={task.delete}></button>
</template>

This produces:

on: {
    click: api_bind(task.delete),
},

Note that there is no caching on the $ctx object. Whereas there is if the referenced function is scoped to the top level (i.e. the component):

<button onclick={topScopedListener}></button>
on: {
  click: _m0 || ($ctx._m0 = api_bind($cmp.topScopedListener)),
},

Note that using this same system for locally-scoped variables is not possible, because it would lead to incorrect behavior – we don't want every task.delete in an array to be cached onto $ctx._m0, because this would mean that every event listener would just be the first task's delete.

It's possible, though, that we could do a similar caching optimization even for locally-scoped event listeners. This may be possible by using the task object itself as a WeakMap key, or by using the key as a key, or something.

@caineblood

This comment was marked as outdated.

@salesforce salesforce deleted a comment Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants