DevSnack 04.04.2022
Version 1 erschien schon 2016
Rich Harris
The Guardian → New York Times → Vercel
3.46.6
„Was für den Guardian richtig war, kann für ZEIT ONLINE nicht falsch sein.“
— Helmut Schmidt, 2022
Say {name}!
Returns a promise that resolves once any pending state changes have been applied, or in the next microtask if there are none..
When you update component state in Svelte, it doesn't update the DOM immediately. Instead, it waits until the next microtask to see if there are any other changes that need to be applied, including in other components. Doing so avoids unnecessary work and allows the browser to batch things more effectively.
Any top-level statement (i.e. not inside a block or a function) can be made reactive by prefixing it with the $: JS label syntax. Reactive statements run immediately before the component updates, whenever the values that they depend on have changed.
Text expressions, <div>{(/^[A-Za-z ]+$/).test(value) ? x : y}</div>
, {@html}
, bind:property (Daten vom Kind ans Elternelement reichen), bind:group (Gruppen von input
verknüpfen), Actions (Funktionen die ablaufen, wenn ein Element erschaffen wird), in:fn/out:fn, --style-props (zur Übergabe von CSS custom properties), <svelte:self>
(Rekursion, baby), createEventDispatcher (Events durch Komponenten bubblen lassen)…
Ein Store ist ein Objekt mit einer subscribe()
Methode, die interessierte Parteien benachrichtigt, wann immer der Inhalt des Stores geändert wird. Optional gibt es eine set()
Methode, die neue Werte im Store setzen kann. Dieses minimale Interface nennt sich store contract.
Svelte: readable, writable and derived store.
„SvelteKit is a framework for building extremely high-performance web apps.“
*.svelte
src/routes/blog/[slug].svelte
*.js|ts
fetch
oder Funktionsaufruf(SSR)).<slot></slot>
in den dann der Inhalt gerendert wird.__layout.svelte
im Routing-Verzeichnis als Hauptlayout, es können über degleichen Dateien in Unterverzeichnissen auch Layouts gegenseitig eingebettet werden.__layout.reset.svelte
handle
, handleError
,getSession
und externalFetch
.adapter-auto
, baut passend zu Cloudflare Pages, Netlify oder Vercel.adapter-node
wird eine Node-App gebaut, die man in beliebgen Umgebungen laufen lassen kann.adapter-static
baut man statische Seiten, dann fungiert Svelte also als SSG.Das ist natürlich längst nicht alles, nur alles, was ich bis jetzt ausprobieren konnte.
In der Doku findet sich natürlich noch einiges mehr an Funktionalitäten…