by spankalee · 7y ago · 0 comments
They are not a direct analog to modern frameworks, and it's completely expected that developers will use helper libraries to get better DX like declarative and reactive components.
I work on two such libraries: lit-html and LitELement. Combined they give you just as much declarative and reactive power as frameworks, much better DOM and style isolation, better performance, and smaller size than just about anything else out there.
Compare a styled Hello World example to React or any other framework:
import {LitElement, html, css, property, customElement} from 'lit-element';
@customElement('hello-world')
class HelloElement extends LitElement {
static styles = css`
:host {
display: block;
}
p {
background: pink;
}
`;
@property() name;
render() {
return html`<p>Hello ${this.name}!</p>`;
}
}
(this example uses decorators because I think it's clearer, but we support plain JS as well)Compared with svelte from the article:
<script>
export let name;
</script>
<style>
p {
background: pink;
}
</style>
<p>Hello {name}!</p>
# Size comparison## lit-element
lit-element.js?module: 8421 bytes
lit-hello.js: 340 bytes
## svelte
bundle.js: 2628 bytes
bundle.css: 72 bytes
2) Svelte bundles the runtime operations that each component uses directly into every component. HelloWorld doesn't use much, so it'll be small, but most component are not HelloWorld and most applications will not have only a single component. The cost of the common dependency on LitElement is amortized over all the elements that use it.
Why gzipped? Bytes of source is a fairer comparison. Parsed source code should be the comparison, not transfer time.
> HelloWorld doesn't use much, so it'll be small, but most component are not HelloWorld and most applications will not have only a single component.
Then why dare other to compare sizes of a Hello world example? :-)
CSS Modules will make it possible to directly import a Stylesheet: https://github.com/w3c/webcomponents/issues/759