Skip to content

Commit

Permalink
🤯 Use generics in Svelte (i guess...)
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-c committed Sep 29, 2023
1 parent d31694e commit b6b21c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script lang="ts">
<script lang="ts" generics="T extends WidgetExample">
import type { WidgetExample } from "../WidgetExample";
import { slide } from "svelte/transition";
Expand All @@ -8,8 +8,8 @@
export let classNames = "";
export let isLoading = false;
export let inputSamples: WidgetExample[];
export let applyInputSample: (sample: WidgetExample) => void;
export let previewInputSample: (sample: WidgetExample) => void;
export let applyInputSample: (sample: T) => void;
export let previewInputSample: (sample: T) => void;
let containerEl: HTMLElement;
let isOptionsVisible = false;
Expand All @@ -25,12 +25,12 @@
hideOptions();
const sample = inputSamples[idx];
title = sample.example_title as string;
applyInputSample(sample);
applyInputSample(sample as T);
}
function _previewInputSample(idx: number) {
const sample = inputSamples[idx];
previewInputSample(sample);
previewInputSample(sample as T);
}
function toggleOptionsVisibility() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script lang="ts">
<script lang="ts" generics="T extends WidgetExample">
import type { WidgetProps, ModelLoadInfo } from "../types";
import type { WidgetExample } from "../WidgetExample";
Expand Down Expand Up @@ -26,8 +26,8 @@
};
export let noTitle = false;
export let outputJson: string;
export let applyInputSample: (sample: WidgetExample) => void = () => {};
export let previewInputSample: (sample: WidgetExample) => void = () => {};
export let applyInputSample: (sample: T) => void = () => {};
export let previewInputSample: (sample: T) => void = () => {};
let isMaximized = false;
let modelLoadInfo: ModelLoadInfo | undefined = undefined;
Expand Down

0 comments on commit b6b21c8

Please sign in to comment.