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

use textContent and innerHTML where appropriate #860

Merged
merged 3 commits into from
Sep 19, 2017
Merged

use textContent and innerHTML where appropriate #860

merged 3 commits into from
Sep 19, 2017

Conversation

Rich-Harris
Copy link
Member

Ref #23. Any time you have an element that contains no if/each blocks, tags, components, or elements with bindings/refs/transitions/dynamic attributes, we can just use innerHTML (or textContent, if there's only a single text node child) instead of constructing the DOM programmatically.

There's some evidence that this is slightly slower on microbenchmarks, but I think we're talking about very modest differences. In return, we get leaner, more readable generated code.

We could generate all DOM that doesn't contain if/each blocks this way, like this...

div.innerHTML = "<button>click me</button>";
button = div.children[0];

...but this PR doesn't go that far.

Thoughts?

@Rich-Harris Rich-Harris merged commit 9f4db8d into master Sep 19, 2017
@Rich-Harris Rich-Harris deleted the gh-23 branch September 19, 2017 15:23
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