Skip to content

Commit

Permalink
Remove event dispatcher and make required props explicit
Browse files Browse the repository at this point in the history
Svelte has deprecated the event dispatcher functionality and instead
works with callback functions that are called when an event should in
the past have been called.

Also `export let var: string` is in svelte something that can't be
optional, so we should type it out as `export let var = string |
undefined = undefined` or make sure we always pass that prop.
  • Loading branch information
sebastinez committed Sep 3, 2024
1 parent ffcbbeb commit d3f9974
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/Header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import Popover from "./Popover.svelte";
import ThemeSwitch from "./ThemeSwitch.svelte";
export let currentPage: string;
export let currentPage: string | undefined = undefined;
</script>

<style>
Expand Down
12 changes: 5 additions & 7 deletions src/components/Link.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
<script lang="ts" strictEvents>
<script lang="ts">
import type { Route } from "@app/lib/router/definitions";
import { createEventDispatcher } from "svelte";
import { push, routeToPath } from "@app/lib/router";
export let route: Route;
export let disabled: boolean = false;
const dispatch = createEventDispatcher<{
afterNavigate: null;
}>();
export let afterNavigate: (() => void) | undefined = undefined;
function navigateToRoute(event: MouseEvent): void {
event.preventDefault();
Expand All @@ -18,7 +14,9 @@
}
void push(route);
dispatch("afterNavigate");
if (afterNavigate) {
afterNavigate();
}
}
</script>

Expand Down

0 comments on commit d3f9974

Please sign in to comment.