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

Avoid binding event handler callbacks, version 2 #456

Merged
merged 39 commits into from
Apr 10, 2017
Merged

Conversation

Rich-Harris
Copy link
Member

#449, but on top of #453. Got a bit sidetracked into refactoring the Element visitor code, so haven't actually started on the event handler stuff per se, but that'll come soon. Element stuff is starting to feel a bit more logical and easier to follow.

@Rich-Harris Rich-Harris changed the title [WIP] Avoid binding event handler callbacks, version 2 Avoid binding event handler callbacks, version 2 Apr 10, 2017
@Rich-Harris
Copy link
Member Author

Taking the WIP label off this now. Event handlers are hoisted to the top level if a) they're not custom events (which can't be hoisted), and b) they're inside an each block. This means that in a situation like this...

{{#each veryLongList as item}}
  <button on:click='set({ selected: item })'>{{item}}</button>
{{/each}}

...the click handler only needs to be declared once, leading to lower memory use and better performance.

Custom event handlers are no longer bound — because they're declared inside a block where they have access to the node in question, references to this can simply be rewritten.

@Rich-Harris Rich-Harris mentioned this pull request Apr 10, 2017
@Rich-Harris Rich-Harris merged commit 20298b1 into master Apr 10, 2017
@Rich-Harris Rich-Harris deleted the gh-433-b branch April 10, 2017 16:07
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.

1 participant