- Verschachtelung
- Props
- Event Dispatching
- Event Forwarding
- Events oder Callbacks
- Framework
- Lokaler State
- Direktiven
- Kontrollstrukturen
- CSS Support
- Reaktivität
- Svelte Stores
- Custom Stores
- Svelte Kontext
- Stores im Kontext
- Komponenten-Slots
- Arbeit mit Promises
- DOM-Referenzen
- Svelte Actions
- SVG-Support
- Transitionen
Kaffepause
10:30 - 11:00
Mittagspause
12:30 - 13:30
Kaffepause
15:00 - 15:30
Vorstellung der Konzepte des Kapitels mit Beispielen
Live Coding der Workshop-App durch Trainer
Übung der Inhalte durch Teilnehmer:innen
Lösungsvorschlag des Trainers
Logo
Register
Home
E-Mail
Submit
Logo
Register
Home
E-Mail
Submit
Komponente
Logo
Register
Home
E-Mail
Submit
Komponente
Komponente
Logo
Register
Home
E-Mail
Submit
Komponente
Komponente
Komponente
Logo
Register
Home
E-Mail
Submit
Komponente
Komponente
Komponente
etc. pp...
<h1>Simple Component</h1>
Component.svelte
<h1>Simple Component</h1>
<h1>Simple Component</h1>
<h1>Simple Component</h1>
import { SvelteComponent, detach, element, init,
insert, noop, safe_not_equal } from "svelte/internal";
function create_fragment(ctx) {
let h1;
return {
c() {
h1 = element("h1");
h1.textContent = "Simple Component";
},
m(target, anchor) {
insert(target, h1, anchor);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(h1);
},
};
}
class SimpleComponent extends SvelteComponent {
constructor(options) {
super();
init(this, options, null, create_fragment, safe_not_equal, {});
}
}
export default SimpleComponent;
<h1>Simple Component</h1>
/* Component.svelte generated by Svelte v3.57.0 */
import { SvelteComponent, detach, element, init, insert, noop,
safe_not_equal } from "svelte/internal";
function create_fragment(ctx) {
let h1;
return {
c() {
h1 = element("h1");
h1.textContent = "Simple Component";
},
m(target, anchor) {
insert(target, h1, anchor);
},
p: noop,
i: noop,
o: noop,
d(detaching) {
if (detaching) detach(h1);
},
};
}
class Component extends SvelteComponent {
constructor(options) {
super();
init(this, options, null, create_fragment, safe_not_equal, {});
}
}
export default Component;
Component.js
<h1>Simple Component</h1>
import Component from "./Component.js";
const app = new App({
target: document.body,
});
export default app;
main.js
<script>
// STATE & BEHAVIOR
</script>
<!-- DECLARATIVE MARKUP -->
<h1>Hello JSDays!</h1>
<p>{"Put your JS expressions in curly braces."}</p>
<style>
/* PRESENTATION */
</style>
Component.svelte
on:
und bind:
.if
, else
, each
, und andere unterstützt.{#each}
-Blocks{#each}
-Blocks in Svelte geändert wird, werden nur am Ende des Blocks Elemente entfernt oder hinzugefügt.=
-Operator und seine Varianten werden in Svelte verwendet, um Datenbindung zwischen Variablen und UI-Elementen herzustellen.Aufgaben
Hinweise
git checkout tags/chapter_1_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Vorbereitung
nilsroehrig/svelte-workshop-revisited
Repository
- Verschachtelung
- Props
- Event Dispatching
- Event Forwarding
- Events oder Callbacks
E-Mail
Submit
Register
Home
Logo
E-Mail
Submit
Register
Home
Logo
Logo
Register
Home
E-Mail
Submit
Logo
Register
Home
E-Mail
Submit
Logo
Register
Home
E-Mail
Submit
E-Mail
Submit
Register
Home
Logo
Logo
Register
Home
E-Mail
Submit
Logo
Register
Home
E-Mail
Submit
E-Mail
Submit
Register
Home
Logo
<Logo>
<Header>
<App>
<NavItem>
<NavItem>
<NavBar>
<Label>
<Input>
<Form>
<Button>
Register
Home
<NavItem>
<NavItem>
Register
Home
<NavItem >
<NavItem >
label="Home"
label="Register"
Register
Home
<script>
const str = "a string";
const num = 12345;
const bool = true;
const obj = {key: "value"};
const arr = [1, 2, 3, 4, 5];
function callback() {
console.log("callback");
}
</script>
<AnyComponent
stringProp={str}
numberProp={num}
booleanProp={bool}
objectProp={obj}
arrayProp={arr}
{callback}
/>
<script>
const str = "a string";
const num = 12345;
const bool = true;
const obj = {key: "value"};
const arr = [1, 2, 3, 4, 5];
function callback() {
console.log("callback");
}
</script>
<AnyComponent
stringProp={str}
numberProp={num}
booleanProp={bool}
objectProp={obj}
arrayProp={arr}
{callback}
/>
<script>
export let stringProp = "";
export let numberProp = 0;
export let booleanProp = true;
export let objectProp = {key: "value"};
export let arrayProp = [1, 2, 3];
export let callback = () => undefined;
</script>
<p>{stringProp}</p>
<p>{numberProp}</p>
<p>{booleanProp}</p>
{#each Object.entries(objectProp) as [key, value]}
<p>{key}: {value}</p>
{/each}
{#each arrayProp as value}
<p>{value}</p>
{/each}
<button on:click={callback}>Call back</button>
$$props
& $$restProps
E-Mail
Submit
Register
Home
Logo
E-Mail
Submit
Logo
Register
Home
E-Mail
Submit
<App>
<Form>
E-Mail
Submit
Logo
Register
Home
E-Mail
Submit
<App>
<Form>
Wie?
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
async function submitForm() {
await postForm();
dispatch("submit", { /* any information to share */ });
}
</script>
<form on:submit={submitForm}>
<!-- form content -->
</form>
Form.svelte
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
async function submitForm() {
await postForm();
dispatch("submit", { /* any information to share */ }
}
</script>
<form on:submit={submitForm}>
<!-- form content -->
</form>
Form.svelte
<script>
import Form from './Form.svelte';
function handleSubmit(event) {
/* here the shared information can be found,
* as Svelte events are just instances of
* CustomEvent */
const { detail } = event;
console.log({detail});
}
</script>
<Form on:submit={handleSubmit} />
App.svelte
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
async function submitForm() {
await postForm();
dispatch("submit", { /* any information to share */ }
}
</script>
<form on:submit={submitForm}>
<!-- form content -->
</form>
Form.svelte
<script>
import Form from './Form.svelte';
function handleSubmit(event) {
/* here the shared information can be found,
* as Svelte events are just instances of
* CustomEvent */
const { detail } = event;
console.log({detail});
}
</script>
<Form on:submit={handleSubmit} />
App.svelte
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
async function submitForm() {
await postForm();
dispatch("submit", { /* any information to share */ }
}
</script>
<form on:submit={submitForm}>
<!-- form content -->
</form>
Form.svelte
<script>
import Form from './Form.svelte';
function handleSubmit(event) {
/* here the shared information can be found,
* as Svelte events are just instances of
* CustomEvent */
const { detail } = event;
console.log({detail});
}
</script>
<Form on:submit={handleSubmit} />
App.svelte
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
async function submitForm() {
await postForm();
dispatch("submit", { /* any information to share */ }
}
</script>
<form on:submit={submitForm}>
<!-- form content -->
</form>
Form.svelte
<script>
import Form from './Form.svelte';
function handleSubmit(event) {
/* here the shared information can be found,
* as Svelte events are just instances of
* CustomEvent */
const { detail } = event;
console.log({detail});
}
</script>
<Form on:submit={handleSubmit} />
App.svelte
<script>
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
async function submitForm() {
await postForm();
dispatch("submit", { /* any information to share */ }
}
</script>
<form on:submit={submitForm}>
<!-- form content -->
</form>
Form.svelte
<script>
import Form from './Form.svelte';
function handleSubmit(event) {
/* here the shared information can be found,
* as Svelte events are just instances of
* CustomEvent */
const { detail } = event;
console.log({detail});
}
</script>
<Form on:submit={handleSubmit} />
App.svelte
<form on:submit>
<!-- form content -->
</form>
Form.svelte
<script>
import Form from './Form.svelte';
async function handleSubmit(event) {
const data = FormData(event.target);
await postData(data);
}
</script>
<Form on:submit={handleSubmit} />
App.svelte
<script>
import AnotherComponent from './AnotherComponent.svelte';
function callback() {
console.log("I am a callback. Arguments: ", ...arguments);
}
</script>
<AnotherComponent {callback} />
<script>
export let callback;
</script>
<button on:click={callback}>
Click me!
</button>
Component.svelte
AnotherComponent.svelte
<script>
import Button from './Button.svelte';
function handleButtonElementClick() {
console.log("Button element clicked.");
}
function handleButtonComponentClick() {
console.log("Button component clicked.");
}
</script>
<button on:click={handleButtonElementClick}>Button element</button>
<Button onClick={handleButtonComponentClick}>Button Component</Button>
git checkout tags/chapter_2_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Vorbereitung
nilsroehrig/svelte-workshop-revisited
Repository
Aufgaben
Hinweise
- Svelte Stores
- Custom Stores
- Svelte Context
- Stores im Kontext
.subscribe
-Methode abonniert werden können.readable
, writable
und derived
..subscribe
-Methode enthalten, die als Argument eine Subscription-Funktion akzeptiert, um ein Abo zu erstellen..subscribe
aufgerufen wird..subscribe
muss eine Unsubscribe-Funktion zurückgeben. Deren Aufruf muss das Abo beenden und die entsprechende Subscription-Funktion darf nicht erneut vom Store aufgerufen werden..set
-Methode enthalten, welche als Argument einen neuen Wert akzeptiert und den Store damit aktualisiert. Ein solcher Store wird als Writable Store bezeichnet.git checkout tags/chapter_3_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Vorbereitung
nilsroehrig/svelte-workshop-revisited
Repository
1. Finde einen Weg, die Werte aus der Estimation-Liste in einem Custom Store zu spreichern und über diesen Store zu aktualisieren.
Aufgaben
Hinweise
git checkout 9129682
- Komponenten-Slots
- Arbeit mit Promises
- DOM-Referenzen
- Svelte Actions
- SVG-Support
- Transitionen
Dialog
Text der im Dialog angezeigt wird. Potenziell ergänzt um weiteren Content.
Okay
<strong>Dialog</strong>
<p>Text der im Dialog angezeigt wird. Potenziell ergänzt um weiteren Content.</p>
<button>Okay</button>
Komponente Rendern
Daten Abrufen
Anzeige Aktualisieren
Komponente Rendern
Daten Abrufen
Anzeige Aktualisieren
git checkout tags/chapter_4_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Vorbereitung
nilsroehrig/svelte-workshop-revisited
Repository
1. Vervollständige die Bearbeitung von Schätzungen, sodass Stories bearbeitet und geschätzt werden können.
Aufgaben
Hinweise