Svelte
Svelte is a feature-rich yet easy-to-use UI framework to create reactive web UI’s. While most frameworks are implemented as runtime libraries, Svelte is implemented as a compiler. It looks at your code at build-time and produces runtime code, which makes it more powerful and less heavy.
Reactivity
<script>
let name = "world";
setTimeout(() => name = "Waldo", 5000);
$: len = name.length;
$: console.log("name", name);
</script>
<p>Hello {name}</p>
<p>Len: {len}</p>
Not only will the paragraph say Hello world initially, 5 seconds later it will automatically update to Hello Waldo. The reactive declaration marked with $: will also be executed every time the value of name changes.
Main Features of Svelte
- Templates - ability to use JS variables in HTML wrapped in
{} - Reactive templates - when a value changes, it re-renders parts of the page that use that variable
- Reactive declarations (
$:) - Single file components - HTML, CSS, and JavaScript all in one file
- Components can receive props
- CSS styles are “scoped” by default
- Attach event listeners
- Provides reactive stores
- Provides actions (
use:action)
Learn Svelte
- svelte.dev - the flagship site for Svelte
- Svelte Tutorial - Do all modules, except “Motion”, “Animation”, and “Transitions”
- Video: Why learn Svelte
- Video: How to learn Svelte