- Verschachtelung
- Props
- Komponenten- Slots
- Event Dispatching
- Event Forwarding
- Events oder Callbacks
- Framework
- Lokaler State
- Direktiven
- Kontrollstrukturen
- CSS Support
- SVG Support
- Reaktivität
- Svelte Stores
- Custom Stores
- Svelte Kontext
- Stores im Kontext
- Arbeit mit Promises
- Transitionen
- Svelte Actions
- DOM-Referenzen
Mittagspause
12:30 - 13:30
Kaffeepausen
15:00 - 15:15 & 16:15 - 16:30
- Framework
- Lokaler State
- Direktiven
- Kontrollstrukturen
- CSS Support
- SVG Support
- Reaktivität
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>
import { [...] } 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 Component({
target: document.body,
});
export default app;
main.js
<script>
// STATE & BEHAVIOR
</script>
<!-- DECLARATIVE MARKUP -->
<h1>Hello enterJS!</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.
Hinweise
Aufgaben
git checkout tags/part_1_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Vorbereitung
Repository
- Verschachtelung
- Props
- Komponenten- Slots
- 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>
<slot>
-Elements in Komponenten definiert.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>
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("form:posted", { /* 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("form:posted", { /* 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:form:posted={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 = new 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>
Hinweise
Aufgaben
git checkout tags/part_2_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Vorbereitung
Repository
- 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.setContext()
wird verwendet, um den Kontext in der übergeordneten Komponente zu erstellen und bereitzustellen.getContext()
wird verwendet, um den Kontext in den untergeordneten Komponenten abzurufen.
Hinweise
https://slides.com/nilsroehrig/svelte-workshop-enterjs-2023
Aufgaben
git checkout tags/part_3_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Vorbereitung
Repository
- Arbeit mit Promises
- Transitionen
- Refs & Actions
Komponente Rendern
Daten Abrufen
Anzeige Aktualisieren
Komponente Rendern
Daten Abrufen
Anzeige Aktualisieren
transition
-Direktive verwendet und ermöglichen die Nutzung eingebauter oder benutzerdefinierter Transitionen.fade
, slide
oder scale
.bind:this={variable}
-Direktive erstellt und können wie andere Variablen verwendet und geteilt werden.use:actionName={params}
-Direktive verwendet.
Hinweise
Aufgaben
git checkout tags/part_4_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Vorbereitung
Repository