Svelte
Introduction
Svelte provides a different approach to building web apps than some of the other frameworks covered in this module. While frameworks like React and Vue do the bulk of their work in the user's browser while the app is running and rely on their own library, Svelte shifts that work into a compile step that happens only when you build your app, producing highly optimized vanilla JavaScript.
The outcome of this approach is not only smaller application bundles and better performance, but also a developer experience that is more approachable for people that have limited experience of the modern tooling ecosystem.
Svelte sticks closely to the classic web development model of HTML, CSS, and JS, just adding a few extensions to HTML and JavaScript. It arguably has fewer concepts and tools to learn than some of the other framework options.
Rendering
Svelte achieves this through a mechanism called reactive declarations.
When you define a variable or a reactive statement using the let keyword in a Svelte component, Svelte internally keeps track of its dependencies. It does this by analyzing the code in the component's script block during the compilation phase.
When a dependency changes, Svelte knows that the component needs to be re-rendered. It updates the component's internal state and generates an optimized JavaScript code specific to that component, including the necessary updates to the DOM.
It generate pure js to listen to specific state to update the real dom directly
Life Cycle
onMount -> (update the view) beforeUpdate -> afterUpdate -> onDestroy
Reactive Declaration
Props
Store
Last updated
Was this helpful?