mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-29 02:00:31 +08:00
Make all Svelte events type-safe
Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<script lang="ts">
|
||||
<script lang="ts" strictEvents>
|
||||
import { createEventDispatcher } from "svelte";
|
||||
import type { ProjectInfo, Branches } from "@app/project";
|
||||
import { getOid } from "@app/project";
|
||||
@@ -10,7 +10,7 @@
|
||||
export let project: ProjectInfo;
|
||||
export let revision: string;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const dispatch = createEventDispatcher<{ branchChanged: string }>();
|
||||
const switchBranch = (name: string) => {
|
||||
dispatch("branchChanged", name);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts">
|
||||
<script lang="ts" strictEvents>
|
||||
import type { CommitMetadata } from "@app/commit";
|
||||
import { formatCommit } from "@app/utils";
|
||||
import { createEventDispatcher } from "svelte";
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
export let commit: CommitMetadata;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const dispatch = createEventDispatcher<{ browseCommit: string }>();
|
||||
|
||||
function browseCommit(commit: string) {
|
||||
dispatch("browseCommit", commit);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts">
|
||||
<script lang="ts" strictEvents>
|
||||
import type { ToggleButtonOption } from "@app/ToggleButton.svelte";
|
||||
|
||||
import Dropdown from "@app/Dropdown.svelte";
|
||||
@@ -14,7 +14,10 @@
|
||||
export let revisionNumber: number;
|
||||
export let activeTab: PatchTab;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const dispatch = createEventDispatcher<{
|
||||
switchTab: PatchTab;
|
||||
revisionChanged: string;
|
||||
}>();
|
||||
|
||||
const formatRevisionName = (revision: Revision, index: number) => {
|
||||
return `R${index} ${formatCommit(revision.oid)} ${formatTimestamp(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts">
|
||||
<script lang="ts" strictEvents>
|
||||
import { createEventDispatcher, onMount } from "svelte";
|
||||
import Icon from "@app/Icon.svelte";
|
||||
import Dropdown from "@app/Dropdown.svelte";
|
||||
@@ -45,7 +45,7 @@
|
||||
});
|
||||
});
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const dispatch = createEventDispatcher<{ peerChanged: string }>();
|
||||
const switchPeer = (peer: string) => {
|
||||
dispatch("peerChanged", peer);
|
||||
};
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<script lang="ts">
|
||||
<script lang="ts" strictEvents>
|
||||
import { createEventDispatcher } from "svelte";
|
||||
import Icon from "@app/Icon.svelte";
|
||||
import { lineNumberL, lineNumberR, lineSign } from "@app/diff";
|
||||
import type { FileDiff } from "@app/diff";
|
||||
import Badge from "@app/Badge.svelte";
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const dispatch = createEventDispatcher<{ browse: string }>();
|
||||
|
||||
export let file: FileDiff;
|
||||
export let mode: string | null = null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts">
|
||||
<script lang="ts" strictEvents>
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
||||
import type { Tree } from "@app/project";
|
||||
@@ -12,7 +12,7 @@
|
||||
export let tree: Tree;
|
||||
export let loadingPath: string | null = null;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const dispatch = createEventDispatcher<{ select: string }>();
|
||||
const onSelect = ({ detail: path }: { detail: string }): void => {
|
||||
dispatch("select", path);
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts">
|
||||
<script lang="ts" strictEvents>
|
||||
import { createEventDispatcher } from "svelte";
|
||||
|
||||
import Loading from "@app/Loading.svelte";
|
||||
@@ -16,7 +16,7 @@
|
||||
let expanded = currentPath.indexOf(prefix) === 0;
|
||||
let tree: Promise<Tree> | null = expanded ? fetchTree(prefix) : null;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const dispatch = createEventDispatcher<{ select: string }>();
|
||||
const onSelectFile = ({ detail: path }: { detail: string }) =>
|
||||
dispatch("select", path);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts">
|
||||
<script lang="ts" strictEvents>
|
||||
import { onMount, createEventDispatcher } from "svelte";
|
||||
import { setRecords } from "./resolver";
|
||||
import type { EnsRecord } from "./resolver";
|
||||
@@ -15,7 +15,7 @@
|
||||
export let records: EnsRecord[];
|
||||
export let registration: Registration;
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
const dispatch = createEventDispatcher<{ close: never }>();
|
||||
|
||||
let state: State = {
|
||||
status: Status.Failed,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import type { EnsRecord } from "./resolver";
|
||||
import type { Field } from "@app/Form.svelte";
|
||||
import type { Field, RegistrationRecord } from "@app/Form.svelte";
|
||||
import type { Registration } from "./registrar";
|
||||
import type { Wallet } from "@app/wallet";
|
||||
import type { ethers } from "ethers";
|
||||
@@ -169,16 +169,12 @@
|
||||
});
|
||||
});
|
||||
|
||||
const onSave = async (event: {
|
||||
detail: { name: string; value: string | null }[];
|
||||
}) => {
|
||||
const onSave = async (event: { detail: RegistrationRecord[] }) => {
|
||||
assert(state.status === Status.Found, "registration must be found");
|
||||
|
||||
updateRecords = event.detail
|
||||
.filter(f => f.value !== null)
|
||||
.map(f => {
|
||||
return { name: f.name, value: f.value as string };
|
||||
});
|
||||
updateRecords = event.detail.map(f => {
|
||||
return { name: f.name, value: f.value };
|
||||
});
|
||||
};
|
||||
|
||||
$: if (retry && state.status === Status.NotFound && retries > 0) {
|
||||
|
||||
Reference in New Issue
Block a user