Skip to main content

detach

Removes a handler or interceptor that was registered through on or intercept. Used for cleanup, typically on component teardown.

Usage

detach(tag: number | string | symbol): void;
ArgumentTypeDescription
tagnumber | string | symbolTag returned (or supplied) when the handler was registered.

Example

<script lang="ts">
import { onDestroy } from "svelte";
import { Calendar } from "@wx/svelte-calendar";
import type { CalendarInstanceApi } from "@wx/svelte-calendar";

let api = $state<CalendarInstanceApi>();
const tag = Symbol("delete-guard");

function init(a: CalendarInstanceApi) {
api = a;
api.intercept(
"delete-event",
p => confirm(`Delete event ${p.id}?`),
{ tag }
);
}

onDestroy(() => api?.detach(tag));
</script>

<Calendar {events} {init} />
  • on — register a handler under a tag.
  • intercept — register an interceptor under a tag.
  • init — capture the api so you can call detach later.