This is an (incomplete) list of Svelte best practices that we try to follow at Der SPIEGEL.
Avoid using JavaScript to make changes to the DOM.
If that is not possible, then use JavaScript.
Encapsulate what can be encapsulated. The code of a component should fit your screen.
$
blocks.Avoid large reactive blocks and keep side-effects on a low level.
Avoid :global
and do not use it when an app is embedded.
Everything should be dynamic.
Create new objects, if you change property values and use <svelte:options immutable>
whenever possible.
It's often less boilerplate. However, there are cases where event handling is safer.
class:
and style:
instead of manual interpolation.It's just less error prone.
In English language.
Avoid complicated or even circular store dependencies.
bind:this
and onMount
.If you need access to a DOM element, this is a more reusable way.
onDestroy
or store unmount functions.Avoid memory leaks.