- Nesting
- Props
- Component Slots
- Event Dispatching
- Event Forwarding
- Events vs. Callbacks
- Framework
- Local State
- Directives
- Control Structures
- CSS Support
- SVG Support
- Reactivity
- Svelte Stores
- Custom Stores
- Svelte Context
- Stores in Context
- Working with Promises
- Transitions
- Svelte Actions
- DOM References
Coffee Break
10:00 - 10:30
Lunch Break
12:00 - 13:00
Coffee Break
14:30 - 15:00
- 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
Kaffepause
10:30 - 11:00
Mittagspause
12:30 - 13:30
Kaffepause
15:00 - 15:30
- Framework
- Local State
- Directives
- Control Structures
- CSS Support
- SVG Support
- Reactivity
Svelte is a tool for building web applications. Like other user interface frameworks, it allows you to build your app declaratively out of components that combine markup, styles and behaviours.
Logo
Register
Home
E-Mail
Submit
etc. pp...
Component
Component
Component
These components are compiled into small, efficient JavaScript modules that eliminate overhead traditionally associated with UI frameworks.
<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:
and bind:
.if
, else
, each
, and others.{#each}
block{#each}
block{#each}
block in Svelte is changed, elements are removed or added only at the end of the block.=
operator and its variants are used in Svelte to establish data binding between variables and UI elements.
Notes
Tasks
git checkout tags/part_1_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Preparation
Repository
- Nesting
- Props
- Component Slots
- Event Dispatching
- Event Forwarding
- Events vs. 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>
How?
<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>
<slot>
element.Dialog
Text that is shown in the dialog. Potentially expanded by further content.
Okay
<strong>Dialog</strong>
<p>Text that is shown in the dialog. Potentially expanded by further content.</p>
<button>Okay</button>
Notes
Tasks
Repository
git checkout tags/part_2_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Preparation
- Svelte Stores
- Custom Stores
- Svelte Context
- Stores in Context
.subscribe
method.readable
, writable
, and derived
..subscribe
method that accepts a subscription function as an argument to create a subscription..subscribe
is called..subscribe
must return an unsubscribe function. Calling it must end the subscription and the corresponding subscription function must not be called again by the Store..set
method, which accepts a new value as an argument and updates the store with it. Such a store is referred to as a writable store.setContext()
is used to create and provide the context in the parent component.getContext()
is used to retrieve the context in the child components.
Notes
Tasks
Repository
git checkout tags/part_3_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Preparation
- Working with Promises
- Transitions
- Svelte Actions
- DOM References
Render Component
Fetch Data
Update View
Render Component
Fetch Data
Update View
transition
directive and allow for the use of built-in or custom transitions.fade
, slide
, or scale
.bind:this={variable}
directive and can be used and shared like other variables.use:actionName={params}
directive.
Notes
Tasks
Repository
git checkout tags/part_4_exercise -b <BRANCH_NAME>
npm ci
npm run dev
Preparation
LinkedIn:
Xing:
X: